Java Scanner Read getStreamLines(final InputStream is)

Here you can find the source of getStreamLines(final InputStream is)

Description

get Stream Lines

License

Open Source License

Declaration

public static List<String> getStreamLines(final InputStream is) throws IllegalArgumentException 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.io.InputStream;
import java.util.ArrayList;

import java.util.List;
import java.util.NoSuchElementException;

import java.util.Scanner;

public class Main {
    private static final String DEFAULT_ENCODING = "UTF-8";

    public static List<String> getStreamLines(final InputStream is) throws IllegalArgumentException {
        return getStreamLines(is, DEFAULT_ENCODING);
    }//from w  ww. j  ava 2s  .c o  m

    public static List<String> getStreamLines(final InputStream is, final String enc)
            throws IllegalArgumentException {
        List<String> lines = new ArrayList<>();
        Scanner scanner = new Scanner(is, enc).useDelimiter("\r?\n");
        while (scanner.hasNext()) {
            try {
                lines.add(scanner.next());
            } catch (NoSuchElementException e) {
                break;
            }
        }
        scanner.close();
        return lines;
    }
}

Related

  1. getThreadScanner()
  2. load(Class cls, String location)
  3. load(File in)
  4. load(final String fileName)