Java ByteArrayOutputStream Read Line readLine(InputStream in)

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

Description

read Line

License

Open Source License

Declaration

private static String readLine(InputStream in) throws IOException 

Method Source Code

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

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

public class Main {
    private static String readLine(InputStream in) throws IOException {
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        boolean eol = false;
        byte[] b = new byte[1];
        while (in.read(b, 0, 1) != -1) {
            if (b[0] == 13) {
                eol = true;//from ww w  .  j a  va  2s  .  c o  m
            } else {
                if ((eol) && (b[0] == 10)) {
                    break;
                }
                eol = false;
            }

            bos.write(b, 0, 1);
        }

        if (bos.size() == 0) {
            return null;
        }
        return bos.toString().trim();
    }
}

Related

  1. readLine()
  2. readLine(final InputStream in)
  3. readLine(InputStream in)
  4. readLine(InputStream in)
  5. readLine(InputStream in)
  6. readLine(InputStream in)
  7. readLine(InputStream in)
  8. readLine(InputStream in)
  9. readLine(InputStream in, char character)