Java BufferedInputStream Read Line readline(final BufferedInputStream in)

Here you can find the source of readline(final BufferedInputStream in)

Description

readline

License

Open Source License

Declaration

public static String readline(final BufferedInputStream in) 

Method Source Code

//package com.java2s;
//    it under the terms of the GNU General Public License as published by

import java.io.BufferedInputStream;

public class Main {
    public static String readline(final BufferedInputStream in) {
        final StringBuilder data = new StringBuilder("");
        int c;/*from   w ww .j a v  a 2 s . c o  m*/
        try {
            in.mark(1);
            if (in.read() == -1)
                return null;
            else
                in.reset();
            while ((c = in.read()) >= 0) {
                if ((c == 0) || (c == 10) || (c == 13))
                    break;
                else
                    data.append((char) c);
            }
            if (c == 13) {
                in.mark(1);
                if (in.read() != 10) {
                    in.reset();
                }
            }
        } catch (Exception e) {
        }
        return data.toString();
    }
}