Java ByteArrayOutputStream Read Line readLine(final InputStream in)

Here you can find the source of readLine(final InputStream in)

Description

read Line

License

LGPL

Declaration

public static String readLine(final InputStream in) throws IOException 

Method Source Code


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

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;

public class Main {
    private static final int CR = 13;
    private static final int LF = 10;
    private static final int EOF = -1;

    public static String readLine(final InputStream in) throws IOException {
        final ByteArrayOutputStream out = new ByteArrayOutputStream();
        while (true) {
            final int b = in.read();
            switch (b) {
            case EOF:
                if (out.size() != 0) {
                    return out.toString();
                }/*w w  w . j  a v  a2  s.  c  om*/
                return null;
            case CR:
                break;
            case LF:
                return out.toString();
            default:
                out.write(b);
                break;
            }
        }
    }
}

Related

  1. readLine()
  2. readLine(InputStream in)
  3. readLine(InputStream in)
  4. readLine(InputStream in)
  5. readLine(InputStream in)