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 sonarqube by SonarSource.
the class ScannerReportViewerApp method updateSource.
private void updateSource(Component component) {
File sourceFile = reader.getFileStructure().fileFor(Domain.SOURCE, component.getRef());
sourceEditor.setText("");
if (sourceFile.exists()) {
try (Scanner s = new Scanner(sourceFile, StandardCharsets.UTF_8.name()).useDelimiter("\\Z")) {
if (s.hasNext()) {
sourceEditor.setText(s.next());
}
} catch (IOException ex) {
StringWriter errors = new StringWriter();
ex.printStackTrace(new PrintWriter(errors));
sourceEditor.setText(errors.toString());
}
}
}
use of java.util.Scanner in project neo4j by neo4j.
the class SecurityLogTest method readLogFile.
private String[] readLogFile(FileSystemAbstraction fs, File activeLogFile) throws IOException {
Scanner scan = new Scanner(fs.openAsInputStream(activeLogFile));
scan.useDelimiter("\\Z");
String allLines = scan.next();
scan.close();
return allLines.split("\\n");
}
use of java.util.Scanner in project AndEngine by nicolasgramlich.
the class SystemUtils method matchSystemFile.
private static MatchResult matchSystemFile(final String pSystemFile, final String pPattern, final int pHorizon) throws SystemUtilsException {
InputStream in = null;
try {
final Process process = new ProcessBuilder(new String[] { "/system/bin/cat", pSystemFile }).start();
in = process.getInputStream();
final Scanner scanner = new Scanner(in);
final boolean matchFound = scanner.findWithinHorizon(pPattern, pHorizon) != null;
if (matchFound) {
return scanner.match();
} else {
throw new SystemUtilsException();
}
} catch (final IOException e) {
throw new SystemUtilsException(e);
} finally {
StreamUtils.close(in);
}
}
use of java.util.Scanner in project AnimeTaste by daimajia.
the class PlaylistParser method parse.
/**
* See {@link Channels#newReader(java.nio.channels.ReadableByteChannel, String)}
* See {@link java.io.StringReader}
*
* @param source the source.
* @return a playlist.
* @throws ParseException parsing fails.
*/
public Playlist parse(Readable source) throws ParseException {
final Scanner scanner = new Scanner(source);
boolean firstLine = true;
int lineNumber = 0;
final List<Element> elements = new ArrayList<Element>(10);
final ElementBuilder builder = new ElementBuilder();
boolean endListSet = false;
int targetDuration = -1;
int mediaSequenceNumber = -1;
EncryptionInfo currentEncryption = null;
while (scanner.hasNextLine()) {
String line = scanner.nextLine().trim();
if (line.length() > 0) {
if (line.startsWith(EX_PREFIX)) {
if (firstLine) {
checkFirstLine(lineNumber, line);
firstLine = false;
} else if (line.startsWith(EXTINF)) {
parseExtInf(line, lineNumber, builder);
} else if (line.startsWith(EXT_X_ENDLIST)) {
endListSet = true;
} else if (line.startsWith(EXT_X_TARGET_DURATION)) {
if (targetDuration != -1) {
throw new ParseException(line, lineNumber, EXT_X_TARGET_DURATION + " duplicated");
}
targetDuration = parseTargetDuration(line, lineNumber);
} else if (line.startsWith(EXT_X_MEDIA_SEQUENCE)) {
if (mediaSequenceNumber != -1) {
throw new ParseException(line, lineNumber, EXT_X_MEDIA_SEQUENCE + " duplicated");
}
mediaSequenceNumber = parseMediaSequence(line, lineNumber);
} else if (line.startsWith(EXT_X_DISCONTINUITY)) {
builder.discontinuity(true);
} else if (line.startsWith(EXT_X_PROGRAM_DATE_TIME)) {
long programDateTime = parseProgramDateTime(line, lineNumber);
builder.programDate(programDateTime);
} else if (line.startsWith(EXT_X_KEY)) {
currentEncryption = parseEncryption(line, lineNumber);
} else {
log.log(Level.FINE, new StringBuilder().append("Unknown: '").append(line).append("'").toString());
}
} else if (line.startsWith(COMMENT_PREFIX)) {
// comment do nothing
if (log.isLoggable(Level.FINEST)) {
log.log(Level.FINEST, "----- Comment: " + line);
}
} else {
if (firstLine) {
checkFirstLine(lineNumber, line);
}
// No prefix: must be the media uri.
builder.encrypted(currentEncryption);
builder.uri(toURI(line));
elements.add(builder.create());
// a new element begins.
builder.reset();
}
}
lineNumber++;
}
return new Playlist(Collections.unmodifiableList(elements), endListSet, targetDuration, mediaSequenceNumber);
}
Aggregations