Java ByteArrayOutputStream Read Line readLine(InputStream in, char character)

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

Description

read Line

License

Open Source License

Declaration

public static String readLine(InputStream in, char character) throws IOException 

Method Source Code

//package com.java2s;
/**/* w w w. j  a  v a2  s  . c o m*/
 * File: $HeadURL: https://hdt-java.googlecode.com/svn/trunk/hdt-java/src/org/rdfhdt/hdt/util/io/IOUtil.java $
 * Revision: $Rev: 194 $
 * Last modified: $Date: 2013-03-04 21:30:01 +0000 (lun, 04 mar 2013) $
 * Last modified by: $Author: mario.arias $
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 *
 * Contacting the authors:
 *   Mario Arias:               mario.arias@deri.org
 *   Javier D. Fernandez:       jfergar@infor.uva.es
 *   Miguel A. Martinez-Prieto: migumar2@infor.uva.es
 *   Alejandro Andres:          fuzzy.alej@gmail.com
 */

import java.io.ByteArrayOutputStream;
import java.io.EOFException;

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

public class Main {
    public static String readLine(InputStream in, char character) throws IOException {
        ByteArrayOutputStream buf = new ByteArrayOutputStream();
        while (true) {
            int value = in.read();
            if (value == -1) {
                throw new EOFException();
            }
            if (value == character) {
                break;
            }
            buf.write(value);
        }
        return new String(buf.toByteArray()); // Uses default encoding
    }
}

Related

  1. readLine(InputStream in)
  2. readLine(InputStream in)
  3. readLine(InputStream in)
  4. readLine(InputStream in)
  5. readLine(InputStream in)
  6. readLine(InputStream input)
  7. readLine(InputStream inputStream)
  8. readLine(InputStream inputStream)
  9. readLine(InputStream inputstream)