Java OutputStream Write Text readLine(InputStream in, OutputStream out)

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

Description

Implementation only supports unix line-end format and is suitable for processing HTTP and other network protocol communications.

License

Open Source License

Declaration

public static int readLine(InputStream in, OutputStream out)
        throws IOException 

Method Source Code

//package com.java2s;
import java.io.*;

public class Main {
    /**/*from  ww  w .  j a v a 2 s . c om*/
     * Implementation only supports unix line-end format and is suitable for
     * processing HTTP and other network protocol communications. Reads and writes
     * a line of data. Returns the number of bytes read/written.
     */
    public static int readLine(InputStream in, OutputStream out)
            throws IOException {

        int count = 0;

        for (;;) {
            int b = in.read();

            if (b == -1) {
                break;
            }

            count++;

            out.write(b);

            if (b == '\n') {
                break;
            }
        }

        return count;
    }
}

Related

  1. readLine(InputStream in, OutputStream out)
  2. readLine(java.io.InputStream input)