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);
}
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;
}
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;
}
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;
}
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;
}
Aggregations