Java InputStream Read Line readLines(InputStream in)

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

Description

read Lines

License

Apache License

Declaration

public static List<String> readLines(InputStream in) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.io.BufferedReader;

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

import java.util.LinkedList;
import java.util.List;

public class Main {
    public static List<String> readLines(InputStream in) {
        final List<String> result = new LinkedList<String>();
        final BufferedReader reader = new BufferedReader(
                new InputStreamReader(in));
        String line;//  w w w  .j a  v  a  2  s.  c o  m
        try {
            while ((line = reader.readLine()) != null) {
                result.add(line);
            }
        } catch (final IOException e) {
            throw new RuntimeException(e);
        }
        return result;
    }

    public static String readLine(InputStream in) {
        final BufferedReader reader = new BufferedReader(
                new InputStreamReader(in));
        final StringBuilder out = new StringBuilder();
        final String newLine = System.getProperty("line.separator");
        String line;
        try {
            while ((line = reader.readLine()) != null) {
                out.append(line);
                out.append(newLine);
            }
        } catch (final IOException e) {
            throw new RuntimeException(e);
        }
        return out.toString();
    }
}

Related

  1. readLines(final InputStream inputStream)
  2. readLines(final InputStream inputStream)
  3. readLines(final InputStream is)
  4. readlines(final InputStream stream)
  5. readLines(InputStream in)
  6. readLines(InputStream in)
  7. readLines(InputStream in)
  8. readLines(InputStream in)
  9. readLines(InputStream in, int maxArraySize)