Javolution 6.0.0 java
javolution.io.CharSequenceReader Class Reference
Inheritance diagram for javolution.io.CharSequenceReader:
[legend]
Collaboration diagram for javolution.io.CharSequenceReader:
[legend]

Public Member Functions

 CharSequenceReader ()
 
CharSequenceReader setInput (CharSequence charSequence)
 
boolean ready () throws IOException
 
void close ()
 
int read () throws IOException
 
int read (char cbuf[], int off, int len) throws IOException
 
void read (Appendable dest) throws IOException
 
void reset ()
 

Private Attributes

CharSequence _input
 
int _index
 

Detailed Description

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

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

Definition at line 25 of file CharSequenceReader.java.

Constructor & Destructor Documentation

◆ CharSequenceReader()

javolution.io.CharSequenceReader.CharSequenceReader ( )

Creates a new character sequence reader for which the character sequence input is not set.

See also
setInput

Definition at line 43 of file CharSequenceReader.java.

43 {}

Member Function Documentation

◆ close()

void javolution.io.CharSequenceReader.close ( )

Closes and resets this reader for reuse.

Definition at line 76 of file CharSequenceReader.java.

76  {
77  if (_input != null) {
78  reset();
79  }
80  }

References javolution.io.CharSequenceReader._input, and javolution.io.CharSequenceReader.reset().

Here is the call graph for this function:

◆ read() [1/3]

int javolution.io.CharSequenceReader.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.

Returns
the 31-bits Unicode of the character read, or -1 if there is no more remaining bytes to be read.
Exceptions
IOExceptionif an I/O error occurs (e.g. incomplete character sequence being read).

Definition at line 91 of file CharSequenceReader.java.

91  {
92  if (_input == null)
93  throw new IOException("Reader closed");
94  return (_index < _input.length()) ? _input.charAt(_index++) : -1;
95  }

References javolution.io.CharSequenceReader._index, and javolution.io.CharSequenceReader._input.

◆ read() [2/3]

void javolution.io.CharSequenceReader.read ( Appendable  dest) throws IOException

Reads characters into the specified appendable. This method does not block.

Parameters
destthe destination buffer.
Exceptions
IOExceptionif an I/O error occurs.

Definition at line 144 of file CharSequenceReader.java.

144  {
145  if (_input == null)
146  throw new IOException("Reader closed");
147  dest.append(_input);
148  }

References javolution.io.CharSequenceReader._input.

◆ read() [3/3]

int javolution.io.CharSequenceReader.read ( char  cbuf[],
int  off,
int  len 
) throws IOException

Reads characters into a portion of an array. This method does not block.

Parameters
cbufthe destination buffer.
offthe offset at which to start storing characters.
lenthe maximum number of characters to read
Returns
the number of characters read, or -1 if there is no more character to be read.
Exceptions
IOExceptionif an I/O error occurs.

Definition at line 108 of file CharSequenceReader.java.

108  {
109  if (_input == null)
110  throw new IOException("Reader closed");
111  final int inputLength = _input.length();
112  if (_index >= inputLength)
113  return -1;
114  final int count = MathLib.min(inputLength - _index, len);
115  final Object csq = _input;
116  if (csq instanceof String) {
117  String str = (String) csq;
118  str.getChars(_index, _index + count, cbuf, off);
119  } else if (csq instanceof Text) {
120  Text txt = (Text) csq;
121  txt.getChars(_index, _index + count, cbuf, off);
122  } else if (csq instanceof TextBuilder) {
123  TextBuilder tb = (TextBuilder) csq;
124  tb.getChars(_index, _index + count, cbuf, off);
125  } else if (csq instanceof CharArray) {
126  CharArray ca = (CharArray) csq;
127  System.arraycopy(ca.array(), _index + ca.offset(), cbuf, off, count);
128  } else { // Generic CharSequence.
129  for (int i = off, n = off + count, j = _index; i < n;) {
130  cbuf[i++] = _input.charAt(j++);
131  }
132  }
133  _index += count;
134  return count;
135  }

References javolution.io.CharSequenceReader._index, javolution.io.CharSequenceReader._input, javolution.text.CharArray.array(), javolution.text.TextBuilder.getChars(), javolution.text.Text.getChars(), javolution.lang.MathLib.min(), and javolution.text.CharArray.offset().

Here is the call graph for this function:

◆ ready()

boolean javolution.io.CharSequenceReader.ready ( ) throws IOException

Indicates if this stream is ready to be read.

Returns
true if this reader has remaining characters to read; false otherwise.
Exceptions
IOExceptionif an I/O error occurs.

Definition at line 67 of file CharSequenceReader.java.

67  {
68  if (_input == null)
69  throw new IOException("Reader closed");
70  return true;
71  }

References javolution.io.CharSequenceReader._input.

◆ reset()

void javolution.io.CharSequenceReader.reset ( )

Definition at line 151 of file CharSequenceReader.java.

151  {
152  _index = 0;
153  _input = null;
154  }

References javolution.io.CharSequenceReader._index, and javolution.io.CharSequenceReader._input.

Referenced by javolution.io.CharSequenceReader.close().

Here is the caller graph for this function:

◆ setInput()

CharSequenceReader javolution.io.CharSequenceReader.setInput ( CharSequence  charSequence)

Sets the character sequence to use for reading.

Parameters
charSequencethe character sequence to be read.
Returns
this reader.
Exceptions
IllegalStateExceptionif this reader is being reused and it has not been closed or reset.

Definition at line 53 of file CharSequenceReader.java.

53  {
54  if (_input != null)
55  throw new IllegalStateException("Reader not closed or reset");
56  _input = charSequence;
57  return this;
58  }

References javolution.io.CharSequenceReader._input.

Member Data Documentation

◆ _index

int javolution.io.CharSequenceReader._index
private

Holds the current index into the character sequence.

Definition at line 35 of file CharSequenceReader.java.

Referenced by javolution.io.CharSequenceReader.read(), and javolution.io.CharSequenceReader.reset().

◆ _input

CharSequence javolution.io.CharSequenceReader._input
private

The documentation for this class was generated from the following file:
javolution.io.CharSequenceReader.reset
void reset()
Definition: CharSequenceReader.java:151
javolution.io.CharSequenceReader._index
int _index
Definition: CharSequenceReader.java:35
javolution.io.CharSequenceReader._input
CharSequence _input
Definition: CharSequenceReader.java:30