Here you can find the source of readLinesStream(InputStream is, boolean trim)
Parameter | Description |
---|---|
is | a parameter |
Parameter | Description |
---|---|
IOException | an exception |
public static List<String> readLinesStream(InputStream is, boolean trim) throws IOException
//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; } }