Top Description Fields Methods
com.amazon.ion.impl

pack-priv Interface ByteReader

Known Direct Implementers
com.amazon.ion.impl.SimpleByteBuffer.SimpleByteReader
Imports
com.amazon.ion.Decimal, .Timestamp, java.io.IOException

Interface to read bytes over a variety of sources. Avoiding the Java standard overhead in so far as possible. This requires the ability to access any part of the underlying data source randomly. However forward access is expected to be the standard direction.

Field Summary

Modifier and TypeField and Description
public static final int
EOF

yet another definition of eof of file as -1

Method Summary

Modifier and TypeMethod and Description
public int

Returns:

offset of the next byte to read
position
()

returns the current position of the reader in the underlying byte buffer

public void
position(int
offset to position the reader to
newPosition
)

sets the position of the reader so that it will read the byte at the passed in offset (newPosition) on the next call to read()

public int

Returns:

next byte of data
read
()

reads a single byte and returns it as an unsigned value, that is from 0 to 255.

public int

Returns:

number of bytes actually copied
read
(byte[]
callers destination byte array
dst
,
int
offset of the first destination array element to write into
start
,
int
maximum number of bytes to copy
len
)

reads a number of bytes into the callers supplied buffer (dst).

public Decimal

Returns:

Decimal object initialized to the represented value; not null.
readDecimal
(int
number of bytes over which the value extends
len
)

reads the next len bytes and converts them to a Decimal value.

public double

Returns:

0.0 or the double represented by the next 8 bytes
readFloat
(int
0 or 8
len
)

reads len bytes and treats them as an IEEE 64 binary floating point value.

public String

Returns:

resultant Java string
readString
(int
number of bytes to read
len
)

reads the next len bytes and converts them from UTF-8 into Java characters and returns those characters as a String.

public Timestamp

Returns:

a new Timestamp instance, or null if the encoded value is null.timestamp.
readTimestamp
(int len)

Reads the next len bytes and returns them as a Timestamp object.

public int

Returns:

typedesc byte
readTypeDesc
()

reads the next byte as a typedesc bytes

public long

Returns:

long value read
readULong
(int
number of bytes to read into the long
len
)

reads the next len bytes as a signed long.

public int

Returns:

int value read
readVarInt
()

reads the upcoming bytes as a signed int.

public long

Returns:

long value read
readVarLong
()

reads the upcoming bytes as a signed long.

public int

Returns:

int value read
readVarUInt
()

reads the upcoming bytes as a unsigned int.

public long

Returns:

long value read
readVarULong
()

reads the upcoming bytes as a unsigned long.

public void
skip(int
number of bytes to skip
length
)

moves the reader forward length bytes.

Field Detail

EOFback to summary
public static final int EOF

yet another definition of eof of file as -1

Method Detail

positionback to summary
public int position()

returns the current position of the reader in the underlying byte buffer

Returns:int

offset of the next byte to read

positionback to summary
public void position(int newPosition)

sets the position of the reader so that it will read the byte at the passed in offset (newPosition) on the next call to read()

Parameters
newPosition:int

offset to position the reader to

readback to summary
public int read() throws IOException

reads a single byte and returns it as an unsigned value, that is from 0 to 255. This returns a ByteReader.EOF (-1) if there is not data to read.

Returns:int

next byte of data

readback to summary
public int read(byte[] dst, int start, int len) throws IOException

reads a number of bytes into the callers supplied buffer (dst). This will return the number of bytes read, if any.

Parameters
dst:byte[]

callers destination byte array

start:int

offset of the first destination array element to write into

len:int

maximum number of bytes to copy

Returns:int

number of bytes actually copied

readDecimalback to summary
public Decimal readDecimal(int len) throws IOException

reads the next len bytes and converts them to a Decimal value.

Parameters
len:int

number of bytes over which the value extends

Returns:Decimal

Decimal object initialized to the represented value; not null.

readFloatback to summary
public double readFloat(int len) throws IOException

reads len bytes and treats them as an IEEE 64 binary floating point value. Currently the only valid values for len are 0 (which returns 0.0e1) or 8 which is treated as a 64 bit binary float and returned.

Parameters
len:int

0 or 8

Returns:double

0.0 or the double represented by the next 8 bytes

readStringback to summary
public String readString(int len) throws IOException

reads the next len bytes and converts them from UTF-8 into Java characters and returns those characters as a String. This may throw an exception in the event it encounters byte sequences that are not value UTF-8. This converts some Unicode values into character pairs when the value requires the use of surrogate pairs in Unicode 16.

Parameters
len:int

number of bytes to read

Returns:String

resultant Java string

readTimestampback to summary
public Timestamp readTimestamp(int len) throws IOException

Reads the next len bytes and returns them as a Timestamp object. This contains an UTC date and time value and a timezone offset of the original value.

Returns:Timestamp

a new Timestamp instance, or null if the encoded value is null.timestamp.

readTypeDescback to summary
public int readTypeDesc() throws IOException

reads the next byte as a typedesc bytes

Returns:int

typedesc byte

readULongback to summary
public long readULong(int len) throws IOException

reads the next len bytes as a signed long. This uses 8 bits per byte and expects the bytes in bigendian order. It returns the aggregated bytes as a Java long (signed 64 bit value).

Parameters
len:int

number of bytes to read into the long

Returns:long

long value read

readVarIntback to summary
public int readVarInt() throws IOException

reads the upcoming bytes as a signed int. This uses 7 bits per byte, expects the bytes in bigendian order, and looks for the high order bit (0x80) to be set to mark the end of the value. It expects the 2nd bit (0x40 of the first byte) to be the sign of the value. The remaining bits are the absolute value of the orginal value. It returns the aggregated bytes as a Java long (signed 32 bit value) correctly signed.

Returns:int

int value read

readVarLongback to summary
public long readVarLong() throws IOException

reads the upcoming bytes as a signed long. This uses 7 bits per byte, expects the bytes in bigendian order, and looks for the high order bit (0x80) to be set to mark the end of the value. It expects the 2nd bit (0x40 of the first byte) to be the sign of the value. The remaining bits are the absolute value of the orginal value. It returns the aggregated bytes as a Java long (signed 64 bit value) correctly signed.

Returns:long

long value read

readVarUIntback to summary
public int readVarUInt() throws IOException

reads the upcoming bytes as a unsigned int. This uses 7 bits per byte, expects the bytes in bigendian order, and looks for the high order bit (0x80) to be set to mark the end of the value. It does not include a sign bit so all 7 bits in the first byte are treated as positive. It returns the aggregated bytes as a Java long (signed 32 bit value).

Returns:int

int value read

readVarULongback to summary
public long readVarULong() throws IOException

reads the upcoming bytes as a unsigned long. This uses 7 bits per byte, expects the bytes in bigendian order, and looks for the high order bit (0x80) to be set to mark the end of the value. It does not include a sign bit so all 7 bits in the first byte are treated as positive. It returns the aggregated bytes as a Java long (signed 64 bit value).

Returns:long

long value read

skipback to summary
public void skip(int length)

moves the reader forward length bytes. This is typically faster than read as it has no need to actually move any bytes of data. It may error if the skip would take the current position off the end of the buffer.

Parameters
length:int

number of bytes to skip