Java InputStream Read Line readLinesCommon(InputStream in)

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

Description

read Lines Common

License

BSD License

Declaration

private static List<String> readLinesCommon(InputStream in) throws IOException 

Method Source Code


//package com.java2s;
// New BSD License

import java.io.BufferedReader;

import java.io.Closeable;

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

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

public class Main {
    private static final String DEFAULT_ENCODING = "UTF8";

    private static List<String> readLinesCommon(InputStream in) throws IOException {

        if (in == null) {
            throw new IOException("Input stream is null.");
        }//from   ww w  .  j av a  2 s .  c om

        List<String> list = new ArrayList<String>();

        BufferedReader reader = null; //subclass of BufferedReader
        try {
            reader = new BufferedReader(new InputStreamReader(in, DEFAULT_ENCODING));

            String line;
            while ((line = reader.readLine()) != null) {
                list.add(line);
            }

            return list;
        } finally {
            close(reader);
        }
    }

    private static void close(Closeable c) {
        if (c != null) {
            try {
                c.close();
            } catch (IOException ex) {
            }
        }
    }
}

Related

  1. readLines(InputStream is2, String encoding)
  2. readLines(InputStream stream)
  3. readLines(InputStream stream)
  4. readLines(InputStream stream)
  5. readLines(InputStream stream, String charset)
  6. readLineSet(InputStream stream)
  7. readLinesStream(InputStream is, boolean trim)
  8. readLineString(InputStream is)
  9. readLineStringBuilder(InputStream is)