Example usage for java.util Scanner hasNextLine

List of usage examples for java.util Scanner hasNextLine

Introduction

In this page you can find the example usage for java.util Scanner hasNextLine.

Prototype

public boolean hasNextLine() 

Source Link

Document

Returns true if there is another line in the input of this scanner.

Usage

From source file:de.uni_freiburg.informatik.ultimate.licence_manager.util.ProcessUtils.java

public static void inheritIO(final InputStream src, final PrintStream dest) {
    new Thread(new Runnable() {
        public void run() {
            final Scanner sc = new Scanner(src);
            while (sc.hasNextLine()) {
                dest.println(sc.nextLine());
            }/*from w w w  .  j  ava 2 s .c o m*/
            sc.close();
        }
    }).start();
}

From source file:com.ExtendedAlpha.SWI.SeparatorLib.Separator.java

public static String getStringFromStream(InputStream stream) {
    Scanner x = new Scanner(stream);
    String str = "";
    while (x.hasNextLine()) {
        str += x.nextLine() + "\n";
    }/*from w  w  w  .  j  a  va2  s.  c  om*/
    x.close();
    return str.trim();
}

From source file:Main.java

private static StringReader fromStreamToStringReader(InputStream inputStream, String encoding) {
    StringBuilder content = new StringBuilder();

    Scanner scanner = null;
    try {//from  w  ww.  java  2 s.c  o m
        scanner = new Scanner(inputStream, encoding);

        while (scanner.hasNextLine()) {
            content.append(scanner.nextLine()).append("\n");
        }
    } finally {
        if (scanner != null) {
            scanner.close();
        }
    }

    return new StringReader(content.toString());
}

From source file:Main.java

public static String readTxtFile(String filePath) {
    File file = new File(filePath);
    if (file == null || !file.exists()) {
        return null;
    }/*from   w  ww  .ja va2 s. co  m*/
    try {
        Scanner scanner = new Scanner(file);
        StringBuilder sb = new StringBuilder();
        while (scanner.hasNextLine()) {
            sb.append(scanner.nextLine());
        }
        scanner.close();
        return sb.toString();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }
    return null;
}

From source file:edu.cmu.cs.lti.ark.fn.utils.LemmatizeStuff.java

private static void run() throws FileNotFoundException {
    Scanner sc = new Scanner(new FileInputStream(infilename));
    PrintStream ps = new PrintStream(new FileOutputStream(outfilename));
    while (sc.hasNextLine()) {
        String line = sc.nextLine();
        ps.print(line + "\t");
        String[] toks = line.trim().split("\\s");
        int sentLen = Integer.parseInt(toks[0]);
        for (int i = 0; i < sentLen; i++) {
            String lemma = lemmatizer.getLemma(toks[i + 1].toLowerCase(), toks[i + 1 + sentLen]);
            ps.print(lemma + "\t");
        }//from www.  ja v  a 2  s.  c  om
        ps.println();
    }
    sc.close();
    closeQuietly(ps);
}

From source file:com.thalesgroup.sonar.plugins.tusar.utils.Utils.java

private static void scanIniContent(Scanner scanner, List<String[]> metrics) {
    while (scanner.hasNextLine()) {
        String line = scanner.nextLine();
        if (!line.startsWith(Constants.COMMENTS)) {
            String[] tokens = line.split(Constants.CSV_SEPARATOR);
            if (tokens.length >= Constants.TOKENS_LENGTH) {
                metrics.add(tokens);//from   www.ja va 2  s .  co m
            } else {
                logger.warn(line + " contains less than three elements");
            }
        }
    }
}

From source file:SystemTrayTest.java

private static List<String> readFortunes() {
    List<String> fortunes = new ArrayList<String>();
    try {/*from   w  w  w . j a va  2s  . co m*/
        Scanner in = new Scanner(new File("fortunes"));
        StringBuilder fortune = new StringBuilder();
        while (in.hasNextLine()) {
            String line = in.nextLine();
            if (line.equals("%")) {
                fortunes.add(fortune.toString());
                fortune = new StringBuilder();
            } else {
                fortune.append(line);
                fortune.append(' ');
            }
        }
    } catch (IOException ex) {
        ex.printStackTrace();
    }
    return fortunes;
}

From source file:Main.java

public static Map<String, List<String>> createDictionary(Context context) {
    try {/*from  w  w w. j a v a2s .c  o m*/
        AssetManager am = context.getAssets();
        InputStream is = am.open(DICTIONARY_FILENAME);
        Scanner reader = new Scanner(is);
        Map<String, List<String>> map = new HashMap<String, List<String>>();

        while (reader.hasNextLine()) {
            String word = reader.nextLine();
            char[] keyArr = word.toCharArray();
            Arrays.sort(keyArr);
            String key = String.copyValueOf(keyArr);

            List<String> wordList = map.get(key);
            if (wordList == null) {
                wordList = new LinkedList<String>();
            }
            wordList.add(word);
            map.put(key, wordList);
        }
        reader.close();
        return map;
    } catch (Exception e) {
        System.out.println(e.getMessage());
        e.printStackTrace();
    }
    return null;
}

From source file:Main.java

/**
 * read one file and return its content as string
 * @param fileName//from  w w w.  ja  va  2s  .com
 * @return
 * @throws FileNotFoundException
 */
public static String readFileToString(String fileName) throws FileNotFoundException {
    File file = new File(fileName);
    if (file.exists()) {
        StringBuilder stringBuilder = new StringBuilder((int) file.length());
        Scanner scanner = new Scanner(file, "UTF-8");
        String lineSeparator = System.getProperty("line.separator");

        while (scanner.hasNextLine()) {
            stringBuilder.append(scanner.nextLine() + lineSeparator);
        }

        scanner.close();
        return stringBuilder.toString();
    }

    Log.e(TAG_CLASS, "no file called: " + fileName);
    return null;
}

From source file:org.gearvrf.utility.Log.java

/**
 * Log long string using verbose tag/*  w  ww  . j  av a2s .co  m*/
 * 
 * @param TAG The tag.
 * @param longString The long string.
 */
public static void logLong(String TAG, String longString) {
    InputStream is = new ByteArrayInputStream(longString.getBytes());
    @SuppressWarnings("resource")
    Scanner scan = new Scanner(is);
    while (scan.hasNextLine()) {
        Log.v(TAG, scan.nextLine());
    }
}