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

pack-priv abstract Class UnifiedInputStreamX

extends Object
implements Closeable
Class Inheritance
All Implemented Interfaces
java.io.Closeable, java.lang.AutoCloseable
Known Direct Subclasses
com.amazon.ion.impl.UnifiedInputStreamX.FromCharArray, com.amazon.ion.impl.UnifiedInputStreamX.FromCharStream, com.amazon.ion.impl.UnifiedInputStreamX.FromByteArray, com.amazon.ion.impl.UnifiedInputStreamX.FromByteStream
Imports
com.amazon.ion.impl.UnifiedSavePointManagerX.SavePoint, java.io.Closeable, .IOException, .InputStream, .Reader

This is a local stream abstraction, and implementation, that allows the calling code to operate over final methods even when the original data source is an interface, such a Reader. When passed a users data buffer it simply operates of the entire buffer directly. When the input source is a stream is creates it's own local buffers, using UnifiedInputBufferX and UnifiedDataPageX. These allocate pages and loads them, a page at a time, from the stream using the highest bandwidth stream interface available. In this class the unread is only allowed to unread characters that it actually read. This is checked, when possible, when the local _debug is true. This is checked when the unread is bad into data that is present in the current buffer. When the unread crosses a buffer boundary the unread value is simply written into the space at the beginning of the block, which is reserved for that purpose. On all system allocated pages the user data starts at an offset in from the front of the buffer, The offset is set by UNREAD_LIMIT. This is not necessary at either the beginning of the input or for a user supplied buffer since the entire input is a single buffer.

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static class
private static class
private static class
private static class

Field Summary

Modifier and TypeField and Description
pack-priv UnifiedInputBufferX
pack-priv byte[]
pack-priv char[]
private static final boolean
pack-priv boolean
pack-priv boolean
pack-priv boolean
pack-priv int
pack-priv int
pack-priv int
pack-priv Reader
pack-priv UnifiedSavePointManagerX
pack-priv InputStream
pack-priv static int
public static final int
pack-priv static final int

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
private final boolean
public void
close()

Implements java.io.Closeable.close.

Closes this stream and releases any system resources associated with it.

public final byte[]
public final char[]
public final InputStream
public long

Returns:

current "file" position
getPosition
()

used to find the current position of this stream in the input source.

public final Reader
private final void
init()

private final boolean
public final boolean
protected final int
load(UnifiedDataPageX curr, int start_pos, long file_position)

protected final void
make_page_current(UnifiedDataPageX curr, int idx, int pos, int limit)

public static UnifiedInputStreamX
public static UnifiedInputStreamX
makeStream(CharSequence chars, int offset, int length)

public static UnifiedInputStreamX
makeStream(char[] chars)

public static UnifiedInputStreamX
makeStream(char[] chars, int offset, int length)

public static UnifiedInputStreamX
public static UnifiedInputStreamX
makeStream(byte[] buffer)

public static UnifiedInputStreamX
makeStream(byte[] buffer, int offset, int length)

public static UnifiedInputStreamX
public final int
read()

public final int
read(byte[] dst, int offset, int length)

protected final int
protected int

Returns:

first value from the refilled input source or EOF
refill
()

the refill method is the key override that is filled in by the various subclasses.

private final boolean
private int
protected final void
public final UnifiedSavePointManagerX.SavePoint
private void
set_current_page(int new_page_idx, UnifiedDataPageX new_page, int pos)

public final void
skip(int skipDistance)

public final void
unread(int c)

public final boolean
private final void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

_bufferback to summary
pack-priv UnifiedInputBufferX _buffer
_bytesback to summary
pack-priv byte[] _bytes
_charsback to summary
pack-priv char[] _chars
_debugback to summary
private static final boolean _debug
_eofback to summary
pack-priv boolean _eof
_is_byte_databack to summary
pack-priv boolean _is_byte_data
_is_streamback to summary
pack-priv boolean _is_stream
_limitback to summary
pack-priv int _limit
_max_char_valueback to summary
pack-priv int _max_char_value
_posback to summary
pack-priv int _pos
_readerback to summary
pack-priv Reader _reader
_save_pointsback to summary
pack-priv UnifiedSavePointManagerX _save_points
_streamback to summary
pack-priv InputStream _stream
DEFAULT_PAGE_SIZEback to summary
pack-priv static int DEFAULT_PAGE_SIZE
EOFback to summary
public static final int EOF
UNREAD_LIMITback to summary
pack-priv static final int UNREAD_LIMIT

Constructor Detail

UnifiedInputStreamXback to summary
pack-priv UnifiedInputStreamX()

Method Detail

can_fill_new_pageback to summary
private final boolean can_fill_new_page()
closeback to summary
public void close() throws IOException

Implements java.io.Closeable.close.

Doc from java.io.Closeable.close.

Closes this stream and releases any system resources associated with it. If the stream is already closed then invoking this method has no effect.

As noted in AutoCloseable#close(), cases where the close may fail require careful attention. It is strongly advised to relinquish the underlying resources and to internally mark the Closeable as closed, prior to throwing the IOException.

Exceptions
IOException:
if an I/O error occurs
getByteArrayback to summary
public final byte[] getByteArray()
getCharArrayback to summary
public final char[] getCharArray()
getInputStreamback to summary
public final InputStream getInputStream()
getPositionback to summary
public long getPosition()

used to find the current position of this stream in the input source.

Returns:long

current "file" position

getReaderback to summary
public final Reader getReader()
initback to summary
private final void init()
is_byte_databack to summary
private final boolean is_byte_data()
isEOFback to summary
public final boolean isEOF()
loadback to summary
protected final int load(UnifiedDataPageX curr, int start_pos, long file_position) throws IOException
make_page_currentback to summary
protected final void make_page_current(UnifiedDataPageX curr, int idx, int pos, int limit)
makeStreamback to summary
public static UnifiedInputStreamX makeStream(CharSequence chars)
makeStreamback to summary
public static UnifiedInputStreamX makeStream(CharSequence chars, int offset, int length)
makeStreamback to summary
public static UnifiedInputStreamX makeStream(char[] chars)
makeStreamback to summary
public static UnifiedInputStreamX makeStream(char[] chars, int offset, int length)
makeStreamback to summary
public static UnifiedInputStreamX makeStream(Reader reader) throws IOException
makeStreamback to summary
public static UnifiedInputStreamX makeStream(byte[] buffer)
makeStreamback to summary
public static UnifiedInputStreamX makeStream(byte[] buffer, int offset, int length)
makeStreamback to summary
public static UnifiedInputStreamX makeStream(InputStream stream) throws IOException
readback to summary
public final int read() throws IOException
readback to summary
public final int read(byte[] dst, int offset, int length) throws IOException
read_helperback to summary
protected final int read_helper() throws IOException
refillback to summary
protected int refill() throws IOException

the refill method is the key override that is filled in by the various subclasses. It fills either the byte or char array with a block of data from the input source. As this is a virtual function the right version will get called for each source type. Since it is only called once per block, and from then on the final method which pulls data from the block can return the value this should be a reasonable performance trade off.

Returns:int

first value from the refilled input source or EOF

refill_helperback to summary
private final boolean refill_helper() throws IOException
refill_is_eofback to summary
private int refill_is_eof()
save_point_reset_to_prevback to summary
protected final void save_point_reset_to_prev(UnifiedSavePointManagerX.SavePoint sp)
savePointAllocateback to summary
public final UnifiedSavePointManagerX.SavePoint savePointAllocate()
set_current_pageback to summary
private void set_current_page(int new_page_idx, UnifiedDataPageX new_page, int pos)
skipback to summary
public final void skip(int skipDistance) throws IOException
unreadback to summary
public final void unread(int c)
unread_optional_crback to summary
public final boolean unread_optional_cr()
verify_matched_unreadback to summary
private final void verify_matched_unread(int c)
com.amazon.ion.impl back to summary

pack-priv Class UnifiedInputStreamX.FromByteArray

extends UnifiedInputStreamX
Class Inheritance

Field Summary

Inherited from com.amazon.ion.impl.UnifiedInputStreamX:
_buffer_bytes_chars_eof_is_byte_data_is_stream_limit_max_char_value_pos_reader_save_points_streamDEFAULT_PAGE_SIZEEOFUNREAD_LIMIT

Constructor Summary

AccessConstructor and Description
pack-priv
FromByteArray(byte[] bytes, int offset, int length)

Method Summary

Inherited from com.amazon.ion.impl.UnifiedInputStreamX:
closegetByteArraygetCharArraygetInputStreamgetPositiongetReaderisEOFloadmake_page_currentmakeStreammakeStreammakeStreammakeStreammakeStreammakeStreammakeStreammakeStreamreadreadread_helperrefillsave_point_reset_to_prevsavePointAllocateskipunreadunread_optional_cr

Constructor Detail

FromByteArrayback to summary
pack-priv FromByteArray(byte[] bytes, int offset, int length)
com.amazon.ion.impl back to summary

private Class UnifiedInputStreamX.FromByteStream

extends UnifiedInputStreamX
Class Inheritance

Field Summary

Inherited from com.amazon.ion.impl.UnifiedInputStreamX:
_buffer_bytes_chars_eof_is_byte_data_is_stream_limit_max_char_value_pos_reader_save_points_streamDEFAULT_PAGE_SIZEEOFUNREAD_LIMIT

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public void
close()

Overrides com.amazon.ion.impl.UnifiedInputStreamX.close.

Implements java.io.Closeable.close.

Closes this stream and releases any system resources associated with it.

Inherited from com.amazon.ion.impl.UnifiedInputStreamX:
getByteArraygetCharArraygetInputStreamgetPositiongetReaderisEOFloadmake_page_currentmakeStreammakeStreammakeStreammakeStreammakeStreammakeStreammakeStreammakeStreamreadreadread_helperrefillsave_point_reset_to_prevsavePointAllocateskipunreadunread_optional_cr

Constructor Detail

FromByteStreamback to summary
pack-priv FromByteStream(InputStream stream) throws IOException

Method Detail

closeback to summary
public void close() throws IOException

Overrides com.amazon.ion.impl.UnifiedInputStreamX.close.

Implements java.io.Closeable.close.

Doc from java.io.Closeable.close.

Closes this stream and releases any system resources associated with it. If the stream is already closed then invoking this method has no effect.

As noted in AutoCloseable#close(), cases where the close may fail require careful attention. It is strongly advised to relinquish the underlying resources and to internally mark the Closeable as closed, prior to throwing the IOException.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs
com.amazon.ion.impl back to summary

private Class UnifiedInputStreamX.FromCharArray

extends UnifiedInputStreamX
Class Inheritance

Field Summary

Inherited from com.amazon.ion.impl.UnifiedInputStreamX:
_buffer_bytes_chars_eof_is_byte_data_is_stream_limit_max_char_value_pos_reader_save_points_streamDEFAULT_PAGE_SIZEEOFUNREAD_LIMIT

Constructor Summary

AccessConstructor and Description
pack-priv
FromCharArray(CharSequence chars, int offset, int length)

pack-priv
FromCharArray(char[] charArray, int offset, int length)

Method Summary

Inherited from com.amazon.ion.impl.UnifiedInputStreamX:
closegetByteArraygetCharArraygetInputStreamgetPositiongetReaderisEOFloadmake_page_currentmakeStreammakeStreammakeStreammakeStreammakeStreammakeStreammakeStreammakeStreamreadreadread_helperrefillsave_point_reset_to_prevsavePointAllocateskipunreadunread_optional_cr

Constructor Detail

FromCharArrayback to summary
pack-priv FromCharArray(CharSequence chars, int offset, int length)
FromCharArrayback to summary
pack-priv FromCharArray(char[] charArray, int offset, int length)
com.amazon.ion.impl back to summary

private Class UnifiedInputStreamX.FromCharStream

extends UnifiedInputStreamX
Class Inheritance

Field Summary

Inherited from com.amazon.ion.impl.UnifiedInputStreamX:
_buffer_bytes_chars_eof_is_byte_data_is_stream_limit_max_char_value_pos_reader_save_points_streamDEFAULT_PAGE_SIZEEOFUNREAD_LIMIT

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public void
close()

Overrides com.amazon.ion.impl.UnifiedInputStreamX.close.

Implements java.io.Closeable.close.

Closes this stream and releases any system resources associated with it.

Inherited from com.amazon.ion.impl.UnifiedInputStreamX:
getByteArraygetCharArraygetInputStreamgetPositiongetReaderisEOFloadmake_page_currentmakeStreammakeStreammakeStreammakeStreammakeStreammakeStreammakeStreammakeStreamreadreadread_helperrefillsave_point_reset_to_prevsavePointAllocateskipunreadunread_optional_cr

Constructor Detail

FromCharStreamback to summary
pack-priv FromCharStream(Reader reader) throws IOException

Method Detail

closeback to summary
public void close() throws IOException

Overrides com.amazon.ion.impl.UnifiedInputStreamX.close.

Implements java.io.Closeable.close.

Doc from java.io.Closeable.close.

Closes this stream and releases any system resources associated with it. If the stream is already closed then invoking this method has no effect.

As noted in AutoCloseable#close(), cases where the close may fail require careful attention. It is strongly advised to relinquish the underlying resources and to internally mark the Closeable as closed, prior to throwing the IOException.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs