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