Java ByteArrayOutputStream Read Line readLine(InputStream in)

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

Description

\r\n

License

GNU General Public License

Parameter

Parameter Description
in a parameter

Exception

Parameter Description
IOException an exception

Declaration

public static byte[] readLine(InputStream in) throws IOException 

Method Source Code

//package com.java2s;
/**//from w  ww  . ja  va 2 s  .co m
 * License
 * 
 * Licensed under the GNU GPL v3
 * http://www.gnu.org/licenses/gpl.html
 * 
 */

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

public class Main {
    /**
     * \r\n
     * 
     * @param in
     * @return
     * @throws IOException
     */
    public static byte[] readLine(InputStream in) throws IOException {
        ByteArrayOutputStream bts = new ByteArrayOutputStream();
        int last = 0;
        while (true) {
            int b = in.read();
            if (b == -1)
                break;
            bts.write(b);
            if (last == '\r' && b == '\n') {
                break;
            }
            last = b;
        }
        return bts.toByteArray();
    }
}

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)