ewe.io
Class StringReader

java.lang.Object
  extended byewe.io.Reader
      extended byewe.io.StringReader

public class StringReader
extends Reader

This class permits a String to be read as a character input stream.

The mark/reset functionality in this class behaves differently than normal. If no mark has been set, then calling the reset() method rewinds the read pointer to the beginning of the String.


Field Summary
 
Fields inherited from class ewe.io.Reader
lock
 
Constructor Summary
StringReader(String buffer)
          Create a new StringReader that will read chars from the passed in String.
 
Method Summary
 void close()
          Close the stream.
 void mark(int readAheadLimit)
           
 boolean markSupported()
           
 int read()
          Read a single character.
 int read(char[] b, int off, int len)
          Read characters into a portion of an array.
 boolean ready()
          This method determines if the stream is ready to be read.
 void reset()
          Sets the read position in the stream to the previously marked position or to 0 (i.e., the beginning of the stream) if the mark has not already been set.
 long skip(long n)
          This method attempts to skip the requested number of chars in the input stream.
 
Methods inherited from class ewe.io.Reader
getLock, read
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, toString
 

Constructor Detail

StringReader

public StringReader(String buffer)
Create a new StringReader that will read chars from the passed in String. This stream will read from the beginning to the end of the String.

Method Detail

close

public void close()
Description copied from class: Reader
Close the stream.

Specified by:
close in class Reader

mark

public void mark(int readAheadLimit)
          throws IOException
Overrides:
mark in class Reader
Throws:
IOException

markSupported

public boolean markSupported()
Overrides:
markSupported in class Reader

read

public int read()
         throws IOException
Description copied from class: Reader
Read a single character. This method will block until a character is available, an I/O error occurs, or the end of the stream is reached.

Overrides:
read in class Reader
Returns:
The character read, as an integer in the range 0 to 0xffff, or -1 if the end of the stream has been reached
Throws:
IOException - If an I/O error occurs

read

public int read(char[] b,
                int off,
                int len)
         throws IOException
Description copied from class: Reader
Read characters into a portion of an array. This method will block until some input is available, an I/O error occurs, or the end of the stream is reached.

Specified by:
read in class Reader
Parameters:
b - Destination buffer
off - Offset at which to start storing characters
len - Maximum number of characters to read
Returns:
The number of characters read, or -1 if the end of the stream has been reached
Throws:
IOException - If an I/O error occurs

ready

public boolean ready()
              throws IOException
This method determines if the stream is ready to be read. This class is always ready to read and so always returns true, unless close() has previously been called in which case an IOException is thrown.

Overrides:
ready in class Reader
Returns:
true to indicate that this object is ready to be read.
Throws:
IOException - If the stream is closed.

reset

public void reset()
           throws IOException
Sets the read position in the stream to the previously marked position or to 0 (i.e., the beginning of the stream) if the mark has not already been set.

Overrides:
reset in class Reader
Throws:
IOException

skip

public long skip(long n)
          throws IOException
This method attempts to skip the requested number of chars in the input stream. It does this by advancing the pos value by the specified number of chars. It this would exceed the length of the buffer, then only enough chars are skipped to position the stream at the end of the buffer. The actual number of chars skipped is returned.

Overrides:
skip in class Reader
Parameters:
n - the number of characters to skip over.
Returns:
The actual number of chars skipped.
Throws:
IOException - if an I/O error occurs while skipping.