Java InputStream Read Line readLines(InputStream stream)

Here you can find the source of readLines(InputStream stream)

Description

read Lines

License

Open Source License

Declaration

public static List<String> readLines(InputStream stream) 

Method Source Code

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

import java.io.InputStream;

import java.util.*;

public class Main {
    public static List<String> readLines(InputStream stream) {
        return splitMultiline(readString(stream), false);
    }//from   w w w . j a  v  a  2  s.c o m

    public static List<String> splitMultiline(String text, boolean trimLines) {
        final List<String> result = new ArrayList<>();
        final String[] lines = text.split("\\r\\n|\\n|\\r");
        for (String line : lines) {
            result.add(trimLines ? line.trim() : line);
        }
        return result;
    }

    public static String readString(InputStream stream) {
        final Scanner s = new Scanner(stream, "UTF-8").useDelimiter("\\A");
        return s.hasNext() ? s.next() : "";
    }

    public static String readString(InputStream stream, String lineEndings) {
        return normalizeLineEndings(readString(stream), lineEndings);
    }

    private static String normalizeLineEndings(String text, String lineEndings) {
        return text.replaceAll("\\r\\n|\\n|\\r", lineEndings);
    }
}

Related

  1. readLines(InputStream is)
  2. readLines(InputStream is)
  3. readLines(InputStream is)
  4. readLines(InputStream is2, String encoding)
  5. readLines(InputStream is2, String encoding)
  6. readLines(InputStream stream)
  7. readLines(InputStream stream)
  8. readLines(InputStream stream, String charset)
  9. readLinesCommon(InputStream in)