Search in sources :

Example 26 with Scanner

use of java.util.Scanner in project visualee by Thomas-S-B.

the class ExaminerTest method testJumpOverJavaToken.

@Test
public void testJumpOverJavaToken() {
    JavaSource javaSource;
    String sourceCode;
    String actual;
    String expected;
    Scanner scanner;
    String currentToken;
    javaSource = JavaSourceFactory.getInstance().newJavaSource("TestClass");
    sourceCode = "@NotNull(groups = PersistenceConstraint.class)\n" + "private Album album;\n";
    javaSource.setSourceCode(sourceCode);
    scanner = Examiner.getSourceCodeScanner(javaSource.getSourceCode());
    // now @NotNull((groups
    currentToken = scanner.next();
    expected = "Album";
    actual = ExaminerImpl.jumpOverJavaToken(currentToken, scanner);
    assertEquals(expected, actual);
    javaSource = JavaSourceFactory.getInstance().newJavaSource("TestClass");
    sourceCode = "@NotNull((groups = PersistenceConstraint.class) saddas)\n" + "protected Album2 album;\n";
    javaSource.setSourceCode(sourceCode);
    scanner = Examiner.getSourceCodeScanner(javaSource.getSourceCode());
    // now @NotNull((groups
    currentToken = scanner.next();
    expected = "Album2";
    actual = ExaminerImpl.jumpOverJavaToken(currentToken, scanner);
    assertEquals(expected, actual);
}
Also used : Scanner(java.util.Scanner) JavaSource(de.strullerbaumann.visualee.source.entity.JavaSource) Test(org.junit.Test)

Example 27 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 28 with Scanner

use of java.util.Scanner in project malmo by Microsoft.

the class SchemaHelper method testSchemaVersionNumbers.

public static boolean testSchemaVersionNumbers(String modVersion) {
    // modVersion will be in three parts - eg 0.19.1
    // We only care about the major and minor release numbers.
    String[] parts = modVersion.split("\\.");
    if (parts.length != 3) {
        System.out.println("Malformed mod version number: " + modVersion + " - should be of form x.y.z. Has CMake been run?");
        return false;
    }
    String requiredVersion = parts[0] + "." + parts[1];
    System.out.println("Testing schemas against internal version number: " + requiredVersion);
    InputStream stream = MalmoMod.class.getClassLoader().getResourceAsStream("schemas.index");
    if (stream == null) {
        System.out.println("Cannot find index of schema files in resources - try rebuilding.");
        // Failed to find index in resources - check that gradle build has happened!
        return false;
    }
    Scanner scanner = new Scanner(stream);
    while (scanner.hasNextLine()) {
        String xsdFile = scanner.nextLine();
        String version = getVersionNumber(xsdFile);
        if (version == null || !version.equals(requiredVersion)) {
            scanner.close();
            System.out.println("Version error: schema file " + xsdFile + " has the wrong version number - should be " + requiredVersion + ", actually " + version);
            return false;
        }
    }
    scanner.close();
    return true;
}
Also used : Scanner(java.util.Scanner) InputStream(java.io.InputStream) MalmoMod(com.microsoft.Malmo.MalmoMod)

Example 29 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 30 with Scanner

use of java.util.Scanner in project OpenAttestation by OpenAttestation.

the class ByteArray method fromHex.

/**
     * @since 0.1.1
     * @param text hex string representing the byte array
     * @return 
     */
public static ByteArray fromHex(String text) {
    Scanner scanner = new Scanner(text);
    ByteArray data = new ByteArray(scanner.nextBigInteger(16));
    scanner.close();
    // preserve leading zeros; BigInteger preserves at most one byte of leading zeros that it uses to indicate the number is positive. we are only using biginteger as a shortcut to parsing so we need to ensure all leading zeros are preserved.
    if (data.length() * 2 < text.length() && text.startsWith("00")) {
        int size = (text.length() / 2) - data.length();
        byte[] zeros = new byte[size];
        data = new ByteArray(ByteArray.concat(zeros, data.getBytes()));
    } else // strip off leading zero that biginteger inserts to indicate sign
    if (data.length() * 2 > text.length() && data.getBytes()[0] == 0) {
        data = data.subarray(1);
    }
    return data;
}
Also used : Scanner(java.util.Scanner)

Aggregations

Scanner (java.util.Scanner)567 File (java.io.File)97 IOException (java.io.IOException)63 NoSuchElementException (java.util.NoSuchElementException)59 ArrayList (java.util.ArrayList)56 Test (org.junit.Test)53 InputStream (java.io.InputStream)51 ServiceBuilder (com.github.scribejava.core.builder.ServiceBuilder)49 OAuthRequest (com.github.scribejava.core.model.OAuthRequest)49 Response (com.github.scribejava.core.model.Response)49 InputMismatchException (java.util.InputMismatchException)47 FileNotFoundException (java.io.FileNotFoundException)42 OAuth20Service (com.github.scribejava.core.oauth.OAuth20Service)31 OAuth2AccessToken (com.github.scribejava.core.model.OAuth2AccessToken)29 FileInputStream (java.io.FileInputStream)27 HashMap (java.util.HashMap)26 Locale (java.util.Locale)23 OAuth1AccessToken (com.github.scribejava.core.model.OAuth1AccessToken)18 OAuth1RequestToken (com.github.scribejava.core.model.OAuth1RequestToken)18 OAuth10aService (com.github.scribejava.core.oauth.OAuth10aService)18