Top Description Fields Constructors Methods
com.amazon.ion.impl

pack-priv final Class IonCharacterReader

extends PushbackReader
Class Inheritance
Imports
java.io.IOException, .PushbackReader, .Reader, java.util.LinkedList

Extension of the java.io.PushbackReader to abstract line/offset counting and push back support. Note that this class does not leverage java.io.LineNumberReader as we need to un-roll the line number on push back and we need to have the logic to deal with newline combinations anyhow.

Field Summary

Modifier and TypeField and Description
public static final int
BUFFER_PADDING

The additional buffer padding--this is to add to the fact that the pushback buffer may have to be larger than user specified characters a CR/LF combo is 2 characters, but logically one newline.

public static final int
DEFAULT_BUFFER_SIZE

The default buffer size

private int
private LinkedList<Integer>
m_columns

This offset stack is for pushing back characters that unroll lines and keeps our offset/line number counts correct.

private long
private int
private int

Constructor Summary

AccessConstructor and Description
public
IonCharacterReader(final Reader
The underlying reader to wrap.
in
,
final int
The size of the push back buffer.
size
)

Constructs a character reader with an explicit buffer size.

public
IonCharacterReader(final Reader
The underlying reader to wrap.
in
)

Constructs a character reader with the default buffer size.

Method Summary

Modifier and TypeMethod and Description
public final int

Returns:

The offset, 1-based.
getColumn
()

Returns the offset within the line based on the last call to read().

public final long

Returns:

The logical number of consumed characters.
getConsumedAmount
()

Returns the logical number of consumed characters.

public final int

Returns:

The line number, 1-based.
getLineNumber
()

Returns the current line number in the stream based on the last call to read().

private final int
private final void
pushColumn(final int offset)

public int
read()

Overrides java.io.PushbackReader.read.

Uses the push back implementation but normalizes newlines to "\n".

public int
read(char[]
Destination buffer
cbuf
,
int
Offset at which to start storing characters
off
,
int
Maximum number of characters to read
len
)

Overrides java.io.PushbackReader.read.

Readers a buffer's worth of data.

public long
skip(final long
The number of characters to skip
n
)

Overrides java.io.PushbackReader.skip.

Skips over some number of characters.

public void
unread(char[]
Character array
cbuf
,
int
Offset of first character to push back
off
,
int
Number of characters to push back
len
)

Overrides java.io.PushbackReader.unread.

Delegates to unread(int).

public void
unread(char[]
Character array to push back
cbuf
)

Overrides java.io.PushbackReader.unread.

Delegates to unread(char[], int, int).

public void
unread(int
The int value representing a character to be pushed back
c
)

Overrides java.io.PushbackReader.unread.

Will unread a character and update the line number if necessary.

private void
unreadImpl(int
the character to unread.
c
,
boolean
Whether or not we actually update the line number.
updateCounts
)

Performs ths actual unread operation.

Inherited from java.io.PushbackReader:
closemarkmarkSupportedreadyreset

Field Detail

BUFFER_PADDINGback to summary
public static final int BUFFER_PADDING

The additional buffer padding--this is to add to the fact that the pushback buffer may have to be larger than user specified characters a CR/LF combo is 2 characters, but logically one newline. FIXME does this properly account for surrogates?

See Also
_Private_Utils#MAX_LOOKAHEAD_UTF16
DEFAULT_BUFFER_SIZEback to summary
public static final int DEFAULT_BUFFER_SIZE

The default buffer size

See Also
_Private_Utils#MAX_LOOKAHEAD_UTF16
m_columnback to summary
private int m_column
m_columnsback to summary
private LinkedList<Integer> m_columns

This offset stack is for pushing back characters that unroll lines and keeps our offset/line number counts correct. This is essentially a pushback stack for character offsets.

m_consumedback to summary
private long m_consumed
m_lineback to summary
private int m_line
m_sizeback to summary
private int m_size

Constructor Detail

IonCharacterReaderback to summary
public IonCharacterReader(final Reader in, final int size)

Constructs a character reader with an explicit buffer size. Note that this is a minimum and the implementation is allowed to make it larger for internal operations.

Parameters
in:Reader

The underlying reader to wrap.

size:int

The size of the push back buffer.

IonCharacterReaderback to summary
public IonCharacterReader(final Reader in)

Constructs a character reader with the default buffer size.

Parameters
in:Reader

The underlying reader to wrap.

Method Detail

getColumnback to summary
public final int getColumn()

Returns the offset within the line based on the last call to read().

Returns:int

The offset, 1-based.

getConsumedAmountback to summary
public final long getConsumedAmount()

Returns the logical number of consumed characters. This does not necessarily equal to the number of actual characters read as newline combinations are treated as one.

Returns:long

The logical number of consumed characters.

getLineNumberback to summary
public final int getLineNumber()

Returns the current line number in the stream based on the last call to read().

Returns:int

The line number, 1-based.

popColumnback to summary
private final int popColumn() throws IOException
pushColumnback to summary
private final void pushColumn(final int offset)
readback to summary
public int read() throws IOException

Overrides java.io.PushbackReader.read.

Uses the push back implementation but normalizes newlines to "\n".

Returns:int

Doc from java.io.PushbackReader.read.

The character read, or -1 if the end of the stream has been reached

Annotations
@Override
Exceptions
IOException:

Doc from java.io.PushbackReader.read.

If an I/O error occurs

readback to summary
public int read(char[] cbuf, int off, int len) throws IOException

Overrides java.io.PushbackReader.read.

Readers a buffer's worth of data. This implementation simply leverages read() over the buffer.

Parameters
cbuf:char[]

Doc from java.io.Reader.read.

Destination buffer

off:int

Doc from java.io.Reader.read.

Offset at which to start storing characters

len:int

Doc from java.io.Reader.read.

Maximum number of characters to read

Returns:int

Doc from java.io.Reader.read.

The number of characters read, or -1 if the end of the stream has been reached

Annotations
@Override
Exceptions
IOException:

Doc from java.io.Reader.read.

If an I/O error occurs

skipback to summary
public long skip(final long n) throws IOException

Overrides java.io.PushbackReader.skip.

Skips over some number of characters. This is implemented as a series of read() calls.

Parameters
n:long

Doc from java.io.Reader.skip.

The number of characters to skip

Returns:long

Doc from java.io.Reader.skip.

The number of characters actually skipped

Annotations
@Override
Exceptions
IOException:

Doc from java.io.Reader.skip.

If an I/O error occurs

unreadback to summary
public void unread(char[] cbuf, int off, int len) throws IOException

Overrides java.io.PushbackReader.unread.

Delegates to unread(int).

Parameters
cbuf:char[]

Doc from java.io.PushbackReader.unread.

Character array

off:int

Doc from java.io.PushbackReader.unread.

Offset of first character to push back

len:int

Doc from java.io.PushbackReader.unread.

Number of characters to push back

Annotations
@Override
Exceptions
IOException:

Doc from java.io.PushbackReader.unread.

If there is insufficient room in the pushback buffer, or if some other I/O error occurs

unreadback to summary
public void unread(char[] cbuf) throws IOException

Overrides java.io.PushbackReader.unread.

Delegates to unread(char[], int, int).

Parameters
cbuf:char[]

Doc from java.io.PushbackReader.unread.

Character array to push back

Annotations
@Override
Exceptions
IOException:

Doc from java.io.PushbackReader.unread.

If there is insufficient room in the pushback buffer, or if some other I/O error occurs

unreadback to summary
public void unread(int c) throws IOException

Overrides java.io.PushbackReader.unread.

Will unread a character and update the line number if necessary. This will throw an exception if a carriage return is given as this character is never yielded from this stream.

Parameters
c:int

Doc from java.io.PushbackReader.unread.

The int value representing a character to be pushed back

Annotations
@Override
Exceptions
IOException:

Doc from java.io.PushbackReader.unread.

If the pushback buffer is full, or if some other I/O error occurs

unreadImplback to summary
private void unreadImpl(int c, boolean updateCounts) throws IOException

Performs ths actual unread operation.

Parameters
c:int

the character to unread.

updateCounts:boolean

Whether or not we actually update the line number.