javolution.io
Class CharSequenceReader

Object
  extended by Reader
      extended by CharSequenceReader
All Implemented Interfaces:
Closeable, Readable, Reusable

public final class CharSequenceReader
extends Reader
implements Reusable

This class allows any CharSequence to be used as a reader.

Version:
3.8, May 8, 2004
Author:
Jean-Marie Dautelle

Field Summary
 
Fields inherited from class Reader
lock
 
Constructor Summary
CharSequenceReader()
          Creates a new character sequence reader for which the character sequence input is not set.
 
Method Summary
 void close()
          Closes and resets this reader for reuse.
 int read()
          Reads a single character.
 void read(Appendable dest)
          Reads characters into the specified appendable.
 int read(char[] cbuf, int off, int len)
          Reads characters into a portion of an array.
 boolean ready()
          Indicates if this stream is ready to be read.
 void reset()
          Resets the internal state of this object to its default values.
 CharSequenceReader setInput(CharSequence charSequence)
          Sets the character sequence to use for reading.
 
Methods inherited from class Reader
mark, markSupported, read, read, skip
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CharSequenceReader

public CharSequenceReader()
Creates a new character sequence reader for which the character sequence input is not set.

See Also:
setInput(java.lang.CharSequence)
Method Detail

setInput

public CharSequenceReader setInput(CharSequence charSequence)
Sets the character sequence to use for reading.

Parameters:
charSequence - the character sequence to be read.
Returns:
this reader.
Throws:
IllegalStateException - if this reader is being reused and it has not been closed or reset.

ready

public boolean ready()
              throws IOException
Indicates if this stream is ready to be read.

Overrides:
ready in class Reader
Returns:
true if this reader has remaining characters to read; false otherwise.
Throws:
IOException - if an I/O error occurs.

close

public void close()
Closes and resets this reader for reuse.

Specified by:
close in interface Closeable
Specified by:
close in class Reader

read

public int read()
         throws IOException
Reads a single character. This method does not block, -1 is returned if the end of the character sequence input has been reached.

Overrides:
read in class Reader
Returns:
the 31-bits Unicode of the character read, or -1 if there is no more remaining bytes to be read.
Throws:
IOException - if an I/O error occurs (e.g. incomplete character sequence being read).

read

public int read(char[] cbuf,
                int off,
                int len)
         throws IOException
Reads characters into a portion of an array. This method does not block.

Specified by:
read in class Reader
Parameters:
cbuf - the destination buffer.
off - the offset at which to start storing characters.
len - the maximum number of characters to read
Returns:
the number of characters read, or -1 if there is no more character to be read.
Throws:
IOException - if an I/O error occurs.

read

public void read(Appendable dest)
          throws IOException
Reads characters into the specified appendable. This method does not block.

Parameters:
dest - the destination buffer.
Throws:
IOException - if an I/O error occurs.

reset

public void reset()
Description copied from interface: Reusable
Resets the internal state of this object to its default values.

Specified by:
reset in interface Reusable
Overrides:
reset in class Reader


Copyright © 2005-2012 Javolution. All Rights Reserved.