Search in sources :

Example 61 with Scanner

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

Example 62 with Scanner

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

Example 63 with Scanner

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

Example 64 with Scanner

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);
}
Also used : Scanner(java.util.Scanner) ToString(org.apache.commons.jrcs.util.ToString) PatchFailedException(org.apache.commons.jrcs.diff.PatchFailedException)

Example 65 with Scanner

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");
            }
        }
    }
}
Also used : Scanner(java.util.Scanner) FileOutputStream(java.io.FileOutputStream) OutputStreamWriter(java.io.OutputStreamWriter) IOException(java.io.IOException) File(java.io.File) BufferedWriter(java.io.BufferedWriter) Writer(java.io.Writer) OutputStreamWriter(java.io.OutputStreamWriter) BufferedWriter(java.io.BufferedWriter)

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