Android APIs
public class

CharArrayReader

extends Reader
java.lang.Object
   ↳ java.io.Reader
     ↳ java.io.CharArrayReader

Class Overview

A specialized Reader for reading the contents of a char array.

See Also

Summary

Fields
protected char[] buf The buffer for characters.
protected int count The ending index of the buffer.
protected int markedPos The current mark position.
protected int pos The current buffer position.
[Expand]
Inherited Fields
From class java.io.Reader
Public Constructors
CharArrayReader(char[] buf)
Constructs a CharArrayReader on the char array buf.
CharArrayReader(char[] buf, int offset, int length)
Constructs a CharArrayReader on the char array buf.
Public Methods
void close()
This method closes this CharArrayReader.
void mark(int readLimit)
Sets a mark position in this reader.
boolean markSupported()
Indicates whether this reader supports the mark() and reset() methods.
int read()
Reads a single character from this reader and returns it as an integer with the two higher-order bytes set to 0.
int read(char[] buffer, int offset, int count)
Reads up to count characters from this CharArrayReader and stores them at offset in the character array buffer.
boolean ready()
Indicates whether this reader is ready to be read without blocking.
void reset()
Resets this reader's position to the last mark() location.
long skip(long charCount)
Skips charCount characters in this reader.
[Expand]
Inherited Methods
From class java.io.Reader
From class java.lang.Object
From interface java.lang.Readable
From interface java.io.Closeable
From interface java.lang.AutoCloseable

Fields

protected char[] buf

Added in API level 1

The buffer for characters.

protected int count

Added in API level 1

The ending index of the buffer.

protected int markedPos

Added in API level 1

The current mark position.

protected int pos

Added in API level 1

The current buffer position.

Public Constructors

public CharArrayReader (char[] buf)

Added in API level 1

Constructs a CharArrayReader on the char array buf. The size of the reader is set to the length of the buffer and the object to to read from is set to buf.

Parameters
buf the char array from which to read.

public CharArrayReader (char[] buf, int offset, int length)

Added in API level 1

Constructs a CharArrayReader on the char array buf. The size of the reader is set to length and the start position from which to read the buffer is set to offset.

Parameters
buf the char array from which to read.
offset the index of the first character in buf to read.
length the number of characters that can be read from buf.
Throws
IllegalArgumentException if offset < 0 or length < 0, or if offset is greater than the size of buf .

Public Methods

public void close ()

Added in API level 1

This method closes this CharArrayReader. Once it is closed, you can no longer read from it. Only the first invocation of this method has any effect.

public void mark (int readLimit)

Added in API level 1

Sets a mark position in this reader. The parameter readLimit is ignored for CharArrayReaders. Calling reset() will reposition the reader back to the marked position provided the mark has not been invalidated.

Parameters
readLimit ignored for CharArrayReaders.
Throws
IOException if this reader is closed.

public boolean markSupported ()

Added in API level 1

Indicates whether this reader supports the mark() and reset() methods.

Returns
  • true for CharArrayReader.
See Also

public int read ()

Added in API level 1

Reads a single character from this reader and returns it as an integer with the two higher-order bytes set to 0. Returns -1 if no more characters are available from this reader.

Returns
  • the character read as an int or -1 if the end of the reader has been reached.
Throws
IOException if this reader is closed.

public int read (char[] buffer, int offset, int count)

Added in API level 1

Reads up to count characters from this CharArrayReader and stores them at offset in the character array buffer. Returns the number of characters actually read or -1 if the end of reader was encountered.

Throws
IndexOutOfBoundsException if offset < 0 || count < 0 || offset + count > buffer.length.
IOException if this reader is closed.

public boolean ready ()

Added in API level 1

Indicates whether this reader is ready to be read without blocking. Returns true if the next read will not block. Returns false if this reader may or may not block when read is called. The implementation in CharArrayReader always returns true even when it has been closed.

Returns
  • true if this reader will not block when read is called, false if unknown or blocking will occur.
Throws
IOException if this reader is closed.

public void reset ()

Added in API level 1

Resets this reader's position to the last mark() location. Invocations of read() and skip() will occur from this new location. If this reader has not been marked, it is reset to the beginning of the string.

Throws
IOException if this reader is closed.

public long skip (long charCount)

Added in API level 1

Skips charCount characters in this reader. Subsequent calls to read will not return these characters unless reset is used. This method does nothing and returns 0 if charCount <= 0.

Returns
  • the number of characters actually skipped.
Throws
IOException if this reader is closed.