Search in sources :

Example 66 with Scanner

use of java.util.Scanner in project jmonkeyengine by jMonkeyEngine.

the class SceneWithAnimationLoader method load.

@Override
public Object load(AssetInfo assetInfo) throws IOException {
    AssetKey<?> key = assetInfo.getKey();
    if (!(key instanceof ModelKey))
        throw new AssetLoadException("Invalid asset key");
    InputStream stream = assetInfo.openStream();
    Scanner scanner = new Scanner(stream);
    AnimationList animList = new AnimationList();
    String modelName = null;
    try {
        while (scanner.hasNextLine()) {
            String line = scanner.nextLine();
            if (line.startsWith("#"))
                continue;
            if (modelName == null) {
                modelName = line;
                continue;
            }
            String[] split = split(line);
            if (split.length < 3)
                throw new IOException("Unparseable string \"" + line + "\"");
            int start;
            int end;
            try {
                start = Integer.parseInt(split[0]);
                end = Integer.parseInt(split[1]);
            } catch (NumberFormatException e) {
                throw new IOException("Unparseable string \"" + line + "\"", e);
            }
            animList.add(split[2], split.length > 3 ? split[3] : null, start, end);
        }
    } finally {
        scanner.close();
        stream.close();
    }
    return assetInfo.getManager().loadAsset(new SceneKey(key.getFolder() + modelName, animList));
}
Also used : Scanner(java.util.Scanner) ModelKey(com.jme3.asset.ModelKey) InputStream(java.io.InputStream) IOException(java.io.IOException) AssetLoadException(com.jme3.asset.AssetLoadException)

Example 67 with Scanner

use of java.util.Scanner in project Talon-for-Twitter by klinker24.

the class IOUtils method readChangelog.

public static String readChangelog(Context context) {
    String ret = "";
    try {
        AssetManager assetManager = context.getAssets();
        Scanner in = new Scanner(assetManager.open("changelog.txt"));
        while (in.hasNextLine()) {
            ret += in.nextLine() + "\n";
        }
    } catch (FileNotFoundException e) {
    } catch (IOException e) {
    }
    return ret;
}
Also used : Scanner(java.util.Scanner) AssetManager(android.content.res.AssetManager) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException)

Example 68 with Scanner

use of java.util.Scanner in project languagetool by languagetool-org.

the class AccentuationDataLoader method loadWords.

Map<String, AnalyzedTokenReadings> loadWords(String path) {
    final Map<String, AnalyzedTokenReadings> map = new HashMap<>();
    final InputStream inputStream = JLanguageTool.getDataBroker().getFromRulesDirAsStream(path);
    try (Scanner scanner = new Scanner(inputStream, FILE_ENCODING)) {
        while (scanner.hasNextLine()) {
            final String line = scanner.nextLine().trim();
            if (line.isEmpty() || line.charAt(0) == '#') {
                // ignore comments
                continue;
            }
            final String[] parts = line.split(";");
            if (parts.length != 3) {
                throw new RuntimeException("Format error in file " + path + ", line: " + line + ", " + "expected 3 semicolon-separated parts, got " + parts.length);
            }
            final AnalyzedToken analyzedToken = new AnalyzedToken(parts[1], parts[2], null);
            map.put(parts[0], new AnalyzedTokenReadings(analyzedToken, 0));
        }
    }
    return map;
}
Also used : Scanner(java.util.Scanner) AnalyzedToken(org.languagetool.AnalyzedToken) HashMap(java.util.HashMap) InputStream(java.io.InputStream) AnalyzedTokenReadings(org.languagetool.AnalyzedTokenReadings)

Example 69 with Scanner

use of java.util.Scanner in project languagetool by languagetool-org.

the class RareWordsFinder method run.

private void run(File input, int minimum) throws FileNotFoundException, CharacterCodingException {
    MorfologikSpeller speller = new MorfologikSpeller(dictInClassPath, 1);
    int lineCount = 0;
    int wordCount = 0;
    try (Scanner s = new Scanner(input)) {
        while (s.hasNextLine()) {
            String line = s.nextLine();
            String[] parts = line.split("\t");
            String word = parts[0];
            long count = Long.parseLong(parts[1]);
            if (count <= minimum) {
                if (word.matches("[a-zA-Z]+") && !word.matches("[A-Z]+") && !word.matches("[a-zA-Z]+[A-Z]+[a-zA-Z]*") && !word.matches("[A-Z].*")) {
                    boolean isMisspelled = speller.isMisspelled(word);
                    if (!isMisspelled) {
                        //List<String> suggestions = speller.getSuggestions(word);  // seems to work only for words that are actually misspellings
                        List<String> suggestions = hunspellDict.suggest(word);
                        suggestions.remove(word);
                        if (suggestionsMightBeUseful(word, suggestions)) {
                            System.out.println(word + "\t" + count + " -> " + String.join(", ", suggestions));
                            wordCount++;
                        }
                    }
                }
            }
            lineCount++;
            if (lineCount % 1_000_000 == 0) {
                System.out.println("lineCount: " + lineCount + ", words found: " + wordCount);
            }
        }
        System.out.println("Done. lineCount: " + lineCount + ", words found: " + wordCount);
    }
}
Also used : Scanner(java.util.Scanner) MorfologikSpeller(org.languagetool.rules.spelling.morfologik.MorfologikSpeller)

Example 70 with Scanner

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

the class WebRuntimeMonitorITCase method testNoCopyFromJar.

/**
	 * Files are copied from the flink-dist jar to a temporary directory and
	 * then served from there. Only allow to copy files from <code>flink-dist.jar:/web</code>
	 */
@Test
public void testNoCopyFromJar() throws Exception {
    final Deadline deadline = TestTimeout.fromNow();
    TestingCluster flink = null;
    WebRuntimeMonitor webMonitor = null;
    try {
        flink = new TestingCluster(new Configuration());
        flink.start(true);
        webMonitor = startWebRuntimeMonitor(flink);
        try (HttpTestClient client = new HttpTestClient("localhost", webMonitor.getServerPort())) {
            String expectedIndex = new Scanner(new File(MAIN_RESOURCES_PATH + "/index.html")).useDelimiter("\\A").next();
            // 1) Request index.html from 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(expectedIndex, response.getContent());
            // 2) Request file from class loader
            client.sendGetRequest("../log4j-test.properties", deadline.timeLeft());
            response = client.getNextResponse(deadline.timeLeft());
            assertEquals("Returned status code " + response.getStatus() + " for file outside of web root.", HttpResponseStatus.NOT_FOUND, response.getStatus());
            assertFalse("Did not respond with the file, but still copied it from the JAR.", new File(webMonitor.getBaseDir(new Configuration()), "log4j-test.properties").exists());
            // 3) Request non-existing file
            client.sendGetRequest("not-existing-resource", deadline.timeLeft());
            response = client.getNextResponse(deadline.timeLeft());
            assertEquals("Unexpected status code " + response.getStatus() + " for file outside of web root.", HttpResponseStatus.NOT_FOUND, response.getStatus());
        }
    } 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)

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