ewe.io
Class StreamReader

java.lang.Object
  extended byewe.util.Errorable
      extended byewe.io.StreamReader

public class StreamReader
extends Errorable

This is used for reading cr/lf delimited lines from a Stream or InputStream, and is far more effecient than a BufferedReader - but has less functionality.


Field Summary
 int bufferSize
          A buffer size to use - by default it is 1024 - however increasing this may not make a significant increase in performance.
protected  boolean closed
          Indicates if the stream is closed or not.
 String encoding
          Set this to be a text encoding form.
protected  InputStream input
          The underlying InputStream if one is used.
protected  Stream stream
          The underlying Stream if one is used.
static String UTF8
          This is the "UTF8" constant string.
 
Fields inherited from class ewe.util.Errorable
error
 
Constructor Summary
StreamReader(BasicStream s)
          Create a StreamReader from a Stream or BasicStream which has been opened for input.
StreamReader(File inputFile)
          Create a StreamReader from a File object.
StreamReader(InputStream in)
          Create a StreamReader from an InputStream.
StreamReader(String path)
          Create a StreamReader from a file name.
 
Method Summary
 boolean close()
          Close the StreamReader and underlying stream.
 boolean isOpen()
          Returns if the StreamReader is open.
 void pushback(String text)
          This will pushback some text into the stream.
 String readALine()
          This reads in a line of text which was terminated in the stream by a Line Feed (\n) or a Carriage Return (\r) or a CR followed by LF (\r\n) or by the end of the file.
 String readLine()
          Deprecated. use readALine() instead which throws an exception on error.
protected  boolean readMore()
          Read more into the internal buffer.
 
Methods inherited from class ewe.util.Errorable
returnError, returnError, returnError
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, toString
 

Field Detail

bufferSize

public int bufferSize
A buffer size to use - by default it is 1024 - however increasing this may not make a significant increase in performance.


stream

protected Stream stream
The underlying Stream if one is used.


input

protected InputStream input
The underlying InputStream if one is used.


closed

protected boolean closed
Indicates if the stream is closed or not.


UTF8

public static final String UTF8
This is the "UTF8" constant string.

See Also:
Constant Field Values

encoding

public String encoding
Set this to be a text encoding form. Either null for pure ASCII or "UTF8" for Java UTF8 encoding. By default it is UTF8.

Constructor Detail

StreamReader

public StreamReader(BasicStream s)
Create a StreamReader from a Stream or BasicStream which has been opened for input.


StreamReader

public StreamReader(String path)
             throws IOException
Create a StreamReader from a file name.


StreamReader

public StreamReader(InputStream in)
Create a StreamReader from an InputStream.


StreamReader

public StreamReader(File inputFile)
             throws IOException
Create a StreamReader from a File object. The toReadableStream() method is called on the file.

Method Detail

isOpen

public boolean isOpen()
Returns if the StreamReader is open.


readMore

protected boolean readMore()
Read more into the internal buffer.

Returns:
true if more data was read, false if not.

readALine

public String readALine()
                 throws IOException
This reads in a line of text which was terminated in the stream by a Line Feed (\n) or a Carriage Return (\r) or a CR followed by LF (\r\n) or by the end of the file. The terminating LF or CR is NOT returned with the string.

Returns:
a line of text without terminating LF or CR characters.
Throws:
IOException - on an input error.

readLine

public String readLine()
Deprecated. use readALine() instead which throws an exception on error.

This reads in a line of text which was terminated in the stream by a Line Feed (\n) or a Carriage Return (\r) or a CR followed by LF (\r\n) or by the end of the file. The terminating LF or CR is NOT returned with the string.


close

public boolean close()
Close the StreamReader and underlying stream.

Returns:
true if there was no error closing the streams. False if there was an error.

pushback

public void pushback(String text)
This will pushback some text into the stream. It will not pushback a line feed unless one is in the text.