Search in sources :

Example 71 with Scanner

use of java.util.Scanner in project flink by apache.

the class WebRuntimeMonitorITCase method testStandaloneWebRuntimeMonitor.

/**
	 * Tests operation of the monitor in standalone operation.
	 */
@Test
public void testStandaloneWebRuntimeMonitor() throws Exception {
    final Deadline deadline = TestTimeout.fromNow();
    TestingCluster flink = null;
    WebRuntimeMonitor webMonitor = null;
    try {
        // Flink w/o a web monitor
        flink = new TestingCluster(new Configuration());
        flink.start(true);
        webMonitor = startWebRuntimeMonitor(flink);
        try (HttpTestClient client = new HttpTestClient("localhost", webMonitor.getServerPort())) {
            String expected = new Scanner(new File(MAIN_RESOURCES_PATH + "/index.html")).useDelimiter("\\A").next();
            // Request the file from the web server
            client.sendGetRequest("index.html", deadline.timeLeft());
            HttpTestClient.SimpleHttpResponse response = client.getNextResponse(deadline.timeLeft());
            assertEquals(HttpResponseStatus.OK, response.getStatus());
            assertEquals(response.getType(), MimeTypes.getMimeTypeForExtension("html"));
            assertEquals(expected, response.getContent());
            // Simple overview request
            client.sendGetRequest("/overview", deadline.timeLeft());
            response = client.getNextResponse(deadline.timeLeft());
            assertEquals(HttpResponseStatus.OK, response.getStatus());
            assertEquals(response.getType(), MimeTypes.getMimeTypeForExtension("json"));
            assertTrue(response.getContent().contains("\"taskmanagers\":1"));
        }
    } finally {
        if (flink != null) {
            flink.shutdown();
        }
        if (webMonitor != null) {
            webMonitor.stop();
        }
    }
}
Also used : Scanner(java.util.Scanner) HttpTestClient(org.apache.flink.runtime.webmonitor.testutils.HttpTestClient) TestingCluster(org.apache.flink.runtime.testingUtils.TestingCluster) Configuration(org.apache.flink.configuration.Configuration) Deadline(scala.concurrent.duration.Deadline) File(java.io.File) Test(org.junit.Test)

Example 72 with Scanner

use of java.util.Scanner in project hadoop by apache.

the class TestDFSShell method runCount.

private static void runCount(String path, long dirs, long files, FsShell shell) throws IOException {
    ByteArrayOutputStream bytes = new ByteArrayOutputStream();
    PrintStream out = new PrintStream(bytes);
    PrintStream oldOut = System.out;
    System.setOut(out);
    Scanner in = null;
    String results = null;
    try {
        runCmd(shell, "-count", path);
        results = bytes.toString();
        in = new Scanner(results);
        assertEquals(dirs, in.nextLong());
        assertEquals(files, in.nextLong());
    } finally {
        System.setOut(oldOut);
        if (in != null)
            in.close();
        IOUtils.closeStream(out);
        System.out.println("results:\n" + results);
    }
}
Also used : Scanner(java.util.Scanner) StringContains.containsString(org.hamcrest.core.StringContains.containsString)

Example 73 with Scanner

use of java.util.Scanner in project useful-java-links by Vedenin.

the class ConvertInputStreamToStringBigBenchmark method jdkScanner.

/*             3. Using Scanner (JDK) */
@Benchmark
public String jdkScanner() throws IOException {
    mark();
    Scanner s = new Scanner(inputStream).useDelimiter("\\A");
    String result = s.hasNext() ? s.next() : "";
    reset();
    return result;
}
Also used : Scanner(java.util.Scanner)

Example 74 with Scanner

use of java.util.Scanner in project Mycat-Server by MyCATApache.

the class SQLParserUtils method parse.

public Map<String, String> parse(String sql) {
    tables.clear();
    stateStack.clear();
    state = null;
    tableFlag = false;
    //单引号 
    boolean sFlag = false;
    //双引号计数器
    boolean dFlag = false;
    Scanner reader = new Scanner(sql);
    reader.useDelimiter(" ");
    String value;
    while (reader.hasNext()) {
        value = reader.next().toLowerCase();
        //前面已经出现单引号,在再次出现单引号之前不做任何处理
        if (sFlag) {
            if (value.endsWith("'") && getCount(value, "'") == 1) {
                sFlag = false;
                continue;
            } else if (value.indexOf("'") != -1) {
                value = value.substring(value.indexOf("'") + 1);
                sFlag = false;
            } else {
                continue;
            }
        }
        //前面已经出现双引号,在再次出现双引号之前不做任何处理
        if (dFlag) {
            if (value.endsWith("\"") && getCount(value, "\"") == 1) {
                dFlag = false;
                continue;
            } else if (value.indexOf("\"") != -1) {
                value = value.substring(value.indexOf("\"") + 1);
                dFlag = false;
            } else {
                continue;
            }
        }
        //单引号在select,where部分不做处理
        if (state != null && state.state != 1 && getCount(value, "'") % 2 == 1) {
            sFlag = true;
            continue;
        }
        if (state != null && state.state != 1 && getCount(value, "\"") % 2 == 1) {
            dFlag = true;
            continue;
        }
        //SELECT关键字
        if (value.equals("select") || value.equals("(select")) {
            //if (state != null) 
            state = new State();
            state.state = 0;
            //入栈
            stateStack.push(state);
            continue;
        }
        //FROM关键字
        if (value.equals("from") || value.equals("into") || value.equals("join")) {
            state.state = 1;
            tableFlag = true;
            continue;
        }
        //From部分出现逗号后面是表名
        if (state.state == 1 && value.equals(",")) {
            tableFlag = true;
            continue;
        }
        if (state.state == 1 && tableFlag == true) {
            getTableName(value);
            continue;
        }
        if (state.state == 1 && tableFlag == false) {
            if (!value.startsWith("),") && (value.equals(",") || value.endsWith(","))) {
                tableFlag = true;
                continue;
            } else if (!value.startsWith("),") && value.indexOf(",") != -1) {
                getTableName(value);
                continue;
            }
        }
        //WHERE关键字
        if (value.equals("where")) {
            state.state = 2;
            continue;
        }
        if (value.endsWith("(select")) {
            stateStack.push(state);
            state = new State();
            state.state = 0;
            continue;
        }
        if (value.equals(")") || value.startsWith("),")) {
            stateStack.pop();
            state = stateStack.peek();
            tableFlag = value.endsWith(",") ? true : false;
            if (state.state == 1) {
                getTableName(value);
            }
            continue;
        }
    }
    return tables;
}
Also used : Scanner(java.util.Scanner)

Example 75 with Scanner

use of java.util.Scanner in project jirm by agentgt.

the class JirmUrlEncodedUtils method parse.

/**
     * Returns a list of {@link NameValuePair NameValuePairs} as built from the
     * URI's query portion. For example, a URI of
     * http://example.org/path/to/file?a=1&b=2&c=3 would return a list of three
     * NameValuePairs, one for a=1, one for b=2, and one for c=3.
     * <p>
     * This is typically useful while parsing an HTTP PUT.
     *
     * @param uri
     *            uri to parse
     * @param encoding
     *            encoding to use while parsing the query
     */
public static List<NameValuePair> parse(final URI uri, final String encoding) {
    List<NameValuePair> result = Collections.emptyList();
    final String query = uri.getRawQuery();
    if (query != null && query.length() > 0) {
        result = new ArrayList<NameValuePair>();
        parse(result, new Scanner(query), encoding);
    }
    return result;
}
Also used : Scanner(java.util.Scanner)

Aggregations

Scanner (java.util.Scanner)862 File (java.io.File)135 ArrayList (java.util.ArrayList)77 IOException (java.io.IOException)72 Test (org.junit.Test)70 NoSuchElementException (java.util.NoSuchElementException)59 InputStream (java.io.InputStream)54 ServiceBuilder (com.github.scribejava.core.builder.ServiceBuilder)49 OAuthRequest (com.github.scribejava.core.model.OAuthRequest)49 Response (com.github.scribejava.core.model.Response)49 FileNotFoundException (java.io.FileNotFoundException)47 InputMismatchException (java.util.InputMismatchException)47 HashMap (java.util.HashMap)35 FileInputStream (java.io.FileInputStream)33 OAuth20Service (com.github.scribejava.core.oauth.OAuth20Service)31 OAuth2AccessToken (com.github.scribejava.core.model.OAuth2AccessToken)29 Locale (java.util.Locale)24 BigInteger (java.math.BigInteger)23 List (java.util.List)22 OAuth1AccessToken (com.github.scribejava.core.model.OAuth1AccessToken)18