Java ByteArrayOutputStream Read Line readLine(Reader ir)

Here you can find the source of readLine(Reader ir)

Description

read Line

License

BSD License

Declaration

public static String readLine(Reader ir) throws IOException 

Method Source Code

//package com.java2s;
//The contents of this file are subject to the "Simplified BSD License" (the "License");

import java.io.ByteArrayOutputStream;

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

import java.io.Reader;

public class Main {
    public static String readLine(InputStream is, String encoding) throws IOException {

        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        int c;//from w ww.j  ava2  s .  com

        boolean bAny = false;
        while ((c = is.read()) > 0 && c != '\n') {
            bAny = true;
            if (c != '\r')
                bos.write(c);
        }
        if (c == -1 && !bAny)
            return null;
        bos.close();
        return bos.toString(encoding);
    }

    public static String readLine(Reader ir) throws IOException {
        StringBuffer sb = new StringBuffer();
        int c;
        boolean bAny = false;
        while ((c = ir.read()) > 0 && c != '\n') {
            bAny = true;
            if (c != '\r')
                sb.append((char) c);
        }
        if (c == -1 && !bAny)
            return null;

        return sb.toString();
    }
}

Related

  1. readLine(InputStream inputStream)
  2. readLine(InputStream inputStream)
  3. readLine(InputStream inputstream)
  4. readLine(InputStream inputStream)
  5. readLine(InputStream is)