use of java.util.Scanner in project jmonkeyengine by jMonkeyEngine.
the class TextLoader method load.
public Object load(AssetInfo assetInfo) throws IOException {
Scanner scan = new Scanner(assetInfo.openStream());
StringBuilder sb = new StringBuilder();
try {
while (scan.hasNextLine()) {
sb.append(scan.nextLine()).append('\n');
}
} finally {
scan.close();
}
return sb.toString();
}
use of java.util.Scanner in project hudson-2.x by hudson.
the class FileBeheaderTest method contentIsRemovedFromBeginning.
@Test
public void contentIsRemovedFromBeginning() throws IOException {
File originalLog = cloneFile(templateLog);
long tail = originalLog.length() / 3;
File choppedLog = FileBeheader.chop(originalLog, tail);
String firstLine = new Scanner(choppedLog).nextLine();
assertThat(firstLine, not(containsString("begin")));
//TODO fix me
// assertThat( choppedLog.length(), lessThanOrEqualTo( tail ) );
assertThat(choppedLog.getName(), equalTo(originalLog.getName()));
assertThat(choppedLog, sameInstance(originalLog));
}
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;
}
use of java.util.Scanner in project OpenGrok by OpenGrok.
the class Node method newpatch.
void newpatch(List original, boolean annotate, Node root) throws InvalidFileFormatException {
DeltaText dt = new DeltaText(root, this.child, annotate);
for (int i = 0; i < text.length; i++) {
try {
char action = ((String) text[i]).charAt(0);
Scanner s = new Scanner(((String) text[i]).substring(1));
int atLine = s.nextInt();
int noLines = s.nextInt();
switch(action) {
case 'a':
dt.addDeltaText(new DeltaAddTextLine(atLine, noLines, text, i + 1));
i += noLines;
break;
case 'd':
dt.addDeltaText(new DeltaDelTextLine(atLine, noLines));
break;
default:
throw new InvalidFileFormatException("Expected 'a' or 'd', got: '" + action + "' while parsing deltatext for revision: " + version);
}
}// This is not very neat. But it will work.
catch (Exception e) {
throw new InvalidFileFormatException("While parsing delta text for revision: " + version + ", got: " + e.getMessage());
}
}
dt.patch(original);
}
use of java.util.Scanner in project languagetool by languagetool-org.
the class DictionaryExporter method outputSeparatorToTab.
protected void outputSeparatorToTab(File inputFile) throws RuntimeException, IOException {
File outputFile = new File(getOutputFilename());
String separator = getOption("fsa.dict.separator");
if (separator == null || separator.trim().isEmpty()) {
throw new IOException("A separator character (fsa.dict.separator) must be defined in the dictionary info file.");
}
boolean hasFrequency = isOptionTrue("fsa.dict.frequency-included");
String encoding = getOption("fsa.dict.encoding");
try (Scanner scanner = new Scanner(inputFile, encoding);
Writer out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(outputFile), encoding))) {
while (scanner.hasNextLine()) {
String line = scanner.nextLine();
String[] parts = line.split(Pattern.quote(separator));
if (parts.length == 3) {
if (hasFrequency) {
// remove frequency data in the last byte
parts[2] = parts[2].substring(0, parts[2].length() - 1);
}
out.write(parts[1] + "\t" + parts[0] + "\t" + parts[2] + "\n");
} else if (parts.length == 2) {
if (hasFrequency) {
out.write(parts[1] + "\n");
}
out.write(parts[1] + "\t" + parts[0] + "\n");
} else if (parts.length == 1) {
out.write(parts[0]);
} else {
System.err.println("Invalid input, expected one, two or three columns separated with " + separator + " in " + inputFile + ": " + line + " => ignoring");
}
}
}
}
Aggregations