Search in sources :

Example 81 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 82 with Scanner

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());
        }
    }
}
Also used : Scanner(java.util.Scanner) StringWriter(java.io.StringWriter) IOException(java.io.IOException) File(java.io.File) PrintWriter(java.io.PrintWriter)

Example 83 with Scanner

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");
}
Also used : Scanner(java.util.Scanner) Matchers.containsString(org.hamcrest.Matchers.containsString)

Example 84 with Scanner

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);
    }
}
Also used : Scanner(java.util.Scanner) InputStream(java.io.InputStream) IOException(java.io.IOException)

Example 85 with Scanner

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);
}
Also used : Scanner(java.util.Scanner) ArrayList(java.util.ArrayList)

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