Java InputStream Read Line readLinesStream(InputStream is, boolean trim)

Here you can find the source of readLinesStream(InputStream is, boolean trim)

Description

read a stream and return lines

License

Open Source License

Parameter

Parameter Description
is a parameter

Exception

Parameter Description
IOException an exception

Declaration

public static List<String> readLinesStream(InputStream is, boolean trim) throws IOException 

Method Source Code


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

import java.io.BufferedReader;

import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

import java.util.ArrayList;
import java.util.List;

public class Main {
    /**//  w  ww . j  a v a 2s .c  o m
     * read a stream and return lines
     * @param is
     * @return
     * @throws IOException 
     */
    public static List<String> readLinesStream(InputStream is, boolean trim) throws IOException {
        BufferedReader in = new BufferedReader(new InputStreamReader(is, "UTF-8"));

        List<String> lines = new ArrayList<String>();
        String line;
        while ((line = in.readLine()) != null) {
            if (trim) {
                line = line.replaceAll("^[\uFEFF-\uFFFF]+", ""); // trim and remove unicode
                line = line.replaceAll("\\[[a-z]\\]", ""); // remove comments from google docs
                line = line.trim();
            }
            if (!line.isEmpty())
                lines.add(line);
        }
        in.close();

        return lines;
    }
}

Related

  1. readLines(InputStream stream)
  2. readLines(InputStream stream)
  3. readLines(InputStream stream, String charset)
  4. readLinesCommon(InputStream in)
  5. readLineSet(InputStream stream)
  6. readLineString(InputStream is)
  7. readLineStringBuilder(InputStream is)
  8. readLineStringConcat(InputStream is)
  9. readLinesUntil(InputStream br, String ln)