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

pack-priv final Class WriteBuffer

extends Object
implements Closeable
Class Inheritance
All Implemented Interfaces
java.io.Closeable, java.lang.AutoCloseable
Imports
java.io.Closeable, .IOException, .OutputStream, java.util.ArrayList, .List

A facade over Block management and low-level Ion encoding concerns for the IonRawBinaryWriter.

Field Summary

Modifier and TypeField and Description
private final BlockAllocator
private static final int
private final List<Block>
private Block
private Runnable
private static final char
private static final char
private int
private static final long
private static final long
private static final long
private static final long
private static final long
private static final long
private static final long
private static final long
private static final char
private static final char
private static final int
private static final int
private static final int
private static final int
private static final int
private static final int
private static final int
private static final int
private static final int
private static final int
private static final int
private static final int
private static final int
private static final int
private static final int
private static final int
private static final int
private static final int
private static final int
private static final long
private static final long
private static final long
private static final long
private static final long
private static final long
private static final long
private static final long
private static final long
private static final long
private static final long
private static final long
private static final long
private static final long
private static final long
private static final long
private static final long
private static final long
private static final long
private static final long
private static final long
private static final long
private static final long
private static final long
private static final long
private static final long
private static final long
private static final long
private static final long
private static final long
private static final long
private static final long
private static final long
private static final long
private static final long
private static final long
private static final long

Constructor Summary

AccessConstructor and Description
public
WriteBuffer(final BlockAllocator allocator, Runnable endOfBlockCallBack)

Method Summary

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

Implements java.io.Closeable.close.

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

public static int
fixedIntLength(final long value)

Get the length of FixedInt for the provided value.

public static int
fixedUIntLength(final long value)

Get the length of FixedUInt for the provided value.

public static int
flexIntLength(final long value)

Get the length of FlexInt for the provided value.

public static int
flexUIntLength(final long value)

Get the length of FlexUInt for the provided value.

private int
index(final long position)

Returns the block index for the given position.

private int
offset(final long position)

Returns the offset within the block for a given position.

public long
position()

Returns the logical position in the current block.

public int
remaining()

Returns the amount of capacity left in the current block.

public void
reset()

Resets the write buffer to empty.

public void
shiftBytesLeft(int
The number of bytes at the end of the buffer that we'll be shifting to the left.
length
,
int
The number of bytes to the left that we'll be shifting.
shiftBy
)

Shifts the last `length` bytes in the buffer to the left.

private void
shiftBytesLeftAcrossBlocks(int
The number of bytes at the end of the buffer that we'll be shifting to the left.
length
,
int
The number of bytes to the left that we'll be shifting.
shiftBy
)

Shifts the last `length` bytes in the buffer to the left.

private void
shiftBytesLeftWithinASingleBlock(int
The number of bytes at the end of the buffer that we'll be shifting to the left.
length
,
int
The number of bytes to the left that we'll be shifting.
shiftBy
)

Shifts the last `length` bytes in the buffer to the left.

public void
truncate(final long position)

Resets the write buffer to a particular point.

public static int
varUIntLength(final long value)

Get the length of varUint for the provided value.

public void
writeByte(final byte octet)

Writes a single octet to the buffer, expanding if necessary.

public void
writeBytes(final byte[] bytes, final int off, final int len)

Writes an array of bytes to the buffer expanding if necessary.

public void
writeBytes(byte[] bytes)

Writes an array of bytes to the buffer expanding if necessary, defaulting to the entire array.

private void
writeBytesSlow(final byte[] bytes, int off, int len)

public int
writeFixedInt(final long value)

Writes a FixedInt to this WriteBuffer, using the minimum number of bytes needed to represent the number.

private int
writeFixedIntOrUInt(final long value, final int numBytes)

Because the fixed int and fixed uint encodings are so similar, we can use this method to write either one as long as we provide the correct number of bytes needed to encode the value.

public int
writeFixedUInt(final long value)

Writes a FixedUInt to this WriteBuffer, using the minimum number of bytes needed to represent the number.

public int
writeFlexInt(final long value)

Writes a FlexInt to this WriteBuffer, returning the number of bytes that were needed to encode the value

private int
writeFlexIntOrUInt(final long value, final int numBytes)

Because the flex int and flex uint encodings are so similar, we can use this method to write either one as long as we provide the correct number of bytes needed to encode the value.

public int
writeFlexUInt(final long value)

Writes a FlexUInt to this WriteBuffer, returning the number of bytes that were needed to encode the value

public void
writeInt16(long value)

public void
writeInt24(long value)

public void
writeInt32(long value)

public void
writeInt40(long value)

public void
writeInt48(long value)

public void
writeInt56(long value)

public void
writeInt64(long value)

public void
writeInt8(long value)

public void
writeLowerNibbleAt(final long
represents the position of the byte that will be overwritten.
position
,
final long
represents the length value of the container.
value
)

Overwrite the lower nibble of the specified type descriptor byte with the length information.

public void
writeTo(final OutputStream out)

Write the entire buffer to output stream.

public void
writeTo(final OutputStream out, long position, long length)

Write a specific segment of data from the buffer to a stream.

public void
writeUInt16(long value)

private void
writeUInt16Slow(long value)

public void
writeUInt24(long value)

private void
writeUInt24Slow(long value)

public void
writeUInt32(long value)

private void
writeUInt32Slow(long value)

public void
writeUInt40(long value)

private void
writeUInt40Slow(long value)

public void
writeUInt48(long value)

private void
writeUInt48Slow(long value)

public void
writeUInt56(long value)

private void
writeUInt56Slow(long value)

public void
writeUInt64(long value)

private void
writeUInt64Slow(long value)

public void
writeUInt8(long value)

public void
writeUInt8At(final long position, final long value)

public int
writeUTF8(final CharSequence chars, int off, int len)

Returns the number of octets written.

public int
writeUTF8(final CharSequence chars)

Returns the number of octets written.

private int
writeUTF8Slow(final CharSequence chars, int off, int len)

private int
writeUTF8UpTo2Byte(final CharSequence chars, int off, int len)

private int
writeUTF8UpTo3Byte(final CharSequence chars, int off, int len)

public int
writeVarInt(long value)

private int
writeVarIntSlow(final long magnitude, final long signMask)

public int
writeVarUInt(final long value)

public void
writeVarUIntDirect1At(final long position, final long value)

private int
writeVarUIntDirect2(final long value)

public void
writeVarUIntDirect2At(long position, long value)

private void
writeVarUIntDirect2StraddlingAt(final int index, final int offset, final long value)

private int
writeVarUIntDirect3(final long value)

private int
writeVarUIntDirect4(final long value)

private int
writeVarUIntDirect5(final long value)

private int
writeVarUIntSlow(final long value)

public static void
writeVarUIntTo(final OutputStream out, final long value)

Write the varUint value to the outputStream.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

allocatorback to summary
private final BlockAllocator allocator
BITS_PER_SURROGATEback to summary
private static final int BITS_PER_SURROGATE
blocksback to summary
private final List<Block> blocks
currentback to summary
private Block current
endOfBlockCallBackback to summary
private Runnable endOfBlockCallBack
HIGH_SURROGATE_FIRSTback to summary
private static final char HIGH_SURROGATE_FIRST
HIGH_SURROGATE_LASTback to summary
private static final char HIGH_SURROGATE_LAST
indexback to summary
private int index
INT16_SIGN_MASKback to summary
private static final long INT16_SIGN_MASK
INT24_SIGN_MASKback to summary
private static final long INT24_SIGN_MASK
INT32_SIGN_MASKback to summary
private static final long INT32_SIGN_MASK
INT40_SIGN_MASKback to summary
private static final long INT40_SIGN_MASK
INT48_SIGN_MASKback to summary
private static final long INT48_SIGN_MASK
INT56_SIGN_MASKback to summary
private static final long INT56_SIGN_MASK
INT64_SIGN_MASKback to summary
private static final long INT64_SIGN_MASK
INT8_SIGN_MASKback to summary
private static final long INT8_SIGN_MASK
LOW_SURROGATE_FIRSTback to summary
private static final char LOW_SURROGATE_FIRST
LOW_SURROGATE_LASTback to summary
private static final char LOW_SURROGATE_LAST
SURROGATE_BASEback to summary
private static final int SURROGATE_BASE
UINT_2_OCTET_SHIFTback to summary
private static final int UINT_2_OCTET_SHIFT
UINT_3_OCTET_SHIFTback to summary
private static final int UINT_3_OCTET_SHIFT
UINT_4_OCTET_SHIFTback to summary
private static final int UINT_4_OCTET_SHIFT
UINT_5_OCTET_SHIFTback to summary
private static final int UINT_5_OCTET_SHIFT
UINT_6_OCTET_SHIFTback to summary
private static final int UINT_6_OCTET_SHIFT
UINT_7_OCTET_SHIFTback to summary
private static final int UINT_7_OCTET_SHIFT
UINT_8_OCTET_SHIFTback to summary
private static final int UINT_8_OCTET_SHIFT
UTF8_2_OCTET_MIN_VALUEback to summary
private static final int UTF8_2_OCTET_MIN_VALUE
UTF8_2_OCTET_PREFIX_MASKback to summary
private static final int UTF8_2_OCTET_PREFIX_MASK
UTF8_2_OCTET_SHIFTback to summary
private static final int UTF8_2_OCTET_SHIFT
UTF8_3_OCTET_MIN_VALUEback to summary
private static final int UTF8_3_OCTET_MIN_VALUE
UTF8_3_OCTET_PREFIX_MASKback to summary
private static final int UTF8_3_OCTET_PREFIX_MASK
UTF8_3_OCTET_SHIFTback to summary
private static final int UTF8_3_OCTET_SHIFT
UTF8_4_OCTET_PREFIX_MASKback to summary
private static final int UTF8_4_OCTET_PREFIX_MASK
UTF8_4_OCTET_SHIFTback to summary
private static final int UTF8_4_OCTET_SHIFT
UTF8_BITS_PER_FOLLOW_OCTETback to summary
private static final int UTF8_BITS_PER_FOLLOW_OCTET
UTF8_FOLLOW_MASKback to summary
private static final int UTF8_FOLLOW_MASK
UTF8_FOLLOW_PREFIX_MASKback to summary
private static final int UTF8_FOLLOW_PREFIX_MASK
VAR_INT_10_OCTET_MIN_VALUEback to summary
private static final long VAR_INT_10_OCTET_MIN_VALUE
VAR_INT_10_OCTET_SHIFTback to summary
private static final long VAR_INT_10_OCTET_SHIFT
VAR_INT_2_OCTET_MIN_VALUEback to summary
private static final long VAR_INT_2_OCTET_MIN_VALUE
VAR_INT_3_OCTET_MIN_VALUEback to summary
private static final long VAR_INT_3_OCTET_MIN_VALUE
VAR_INT_4_OCTET_MIN_VALUEback to summary
private static final long VAR_INT_4_OCTET_MIN_VALUE
VAR_INT_5_OCTET_MIN_VALUEback to summary
private static final long VAR_INT_5_OCTET_MIN_VALUE
VAR_INT_6_OCTET_MIN_VALUEback to summary
private static final long VAR_INT_6_OCTET_MIN_VALUE
VAR_INT_7_OCTET_MIN_VALUEback to summary
private static final long VAR_INT_7_OCTET_MIN_VALUE
VAR_INT_8_OCTET_MIN_VALUEback to summary
private static final long VAR_INT_8_OCTET_MIN_VALUE
VAR_INT_9_OCTET_MIN_VALUEback to summary
private static final long VAR_INT_9_OCTET_MIN_VALUE
VAR_INT_BITS_PER_OCTETback to summary
private static final long VAR_INT_BITS_PER_OCTET
VAR_INT_BITS_PER_SIGNED_OCTETback to summary
private static final long VAR_INT_BITS_PER_SIGNED_OCTET
VAR_INT_FINAL_OCTET_SIGNAL_MASKback to summary
private static final long VAR_INT_FINAL_OCTET_SIGNAL_MASK
VAR_INT_MASKback to summary
private static final long VAR_INT_MASK
VAR_INT_SIGNBIT_OFF_MASKback to summary
private static final long VAR_INT_SIGNBIT_OFF_MASK
VAR_INT_SIGNBIT_ON_MASKback to summary
private static final long VAR_INT_SIGNBIT_ON_MASK
VAR_INT_SIGNED_OCTET_MASKback to summary
private static final long VAR_INT_SIGNED_OCTET_MASK
VAR_SINT_2_OCTET_SHIFTback to summary
private static final long VAR_SINT_2_OCTET_SHIFT
VAR_SINT_3_OCTET_SHIFTback to summary
private static final long VAR_SINT_3_OCTET_SHIFT
VAR_SINT_4_OCTET_SHIFTback to summary
private static final long VAR_SINT_4_OCTET_SHIFT
VAR_SINT_5_OCTET_SHIFTback to summary
private static final long VAR_SINT_5_OCTET_SHIFT
VAR_UINT_2_OCTET_MIN_VALUEback to summary
private static final long VAR_UINT_2_OCTET_MIN_VALUE
VAR_UINT_2_OCTET_SHIFTback to summary
private static final long VAR_UINT_2_OCTET_SHIFT
VAR_UINT_3_OCTET_MIN_VALUEback to summary
private static final long VAR_UINT_3_OCTET_MIN_VALUE
VAR_UINT_3_OCTET_SHIFTback to summary
private static final long VAR_UINT_3_OCTET_SHIFT
VAR_UINT_4_OCTET_MIN_VALUEback to summary
private static final long VAR_UINT_4_OCTET_MIN_VALUE
VAR_UINT_4_OCTET_SHIFTback to summary
private static final long VAR_UINT_4_OCTET_SHIFT
VAR_UINT_5_OCTET_MIN_VALUEback to summary
private static final long VAR_UINT_5_OCTET_MIN_VALUE
VAR_UINT_5_OCTET_SHIFTback to summary
private static final long VAR_UINT_5_OCTET_SHIFT
VAR_UINT_6_OCTET_MIN_VALUEback to summary
private static final long VAR_UINT_6_OCTET_MIN_VALUE
VAR_UINT_6_OCTET_SHIFTback to summary
private static final long VAR_UINT_6_OCTET_SHIFT
VAR_UINT_7_OCTET_MIN_VALUEback to summary
private static final long VAR_UINT_7_OCTET_MIN_VALUE
VAR_UINT_7_OCTET_SHIFTback to summary
private static final long VAR_UINT_7_OCTET_SHIFT
VAR_UINT_8_OCTET_MIN_VALUEback to summary
private static final long VAR_UINT_8_OCTET_MIN_VALUE
VAR_UINT_8_OCTET_SHIFTback to summary
private static final long VAR_UINT_8_OCTET_SHIFT
VAR_UINT_9_OCTET_MIN_VALUEback to summary
private static final long VAR_UINT_9_OCTET_MIN_VALUE
VAR_UINT_9_OCTET_SHIFTback to summary
private static final long VAR_UINT_9_OCTET_SHIFT

Constructor Detail

WriteBufferback to summary
public WriteBuffer(final BlockAllocator allocator, Runnable endOfBlockCallBack)

Method Detail

allocateNewBlockback to summary
private void allocateNewBlock()
closeback to summary
public void 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.

fixedIntLengthback to summary
public static int fixedIntLength(final long value)

Get the length of FixedInt for the provided value.

fixedUIntLengthback to summary
public static int fixedUIntLength(final long value)

Get the length of FixedUInt for the provided value.

flexIntLengthback to summary
public static int flexIntLength(final long value)

Get the length of FlexInt for the provided value.

flexUIntLengthback to summary
public static int flexUIntLength(final long value)

Get the length of FlexUInt for the provided value.

indexback to summary
private int index(final long position)

Returns the block index for the given position.

offsetback to summary
private int offset(final long position)

Returns the offset within the block for a given position.

positionback to summary
public long position()

Returns the logical position in the current block.

remainingback to summary
public int remaining()

Returns the amount of capacity left in the current block.

resetback to summary
public void reset()

Resets the write buffer to empty.

shiftBytesLeftback to summary
public void shiftBytesLeft(int length, int shiftBy)

Shifts the last `length` bytes in the buffer to the left. This can be used when a value's header was preallocated but the value's encoded size proved to be much smaller than anticipated. The caller must guarantee that the buffer contains enough bytes to perform the requested shift.

Parameters
length:int

The number of bytes at the end of the buffer that we'll be shifting to the left.

shiftBy:int

The number of bytes to the left that we'll be shifting.

shiftBytesLeftAcrossBlocksback to summary
private void shiftBytesLeftAcrossBlocks(int length, int shiftBy)

Shifts the last `length` bytes in the buffer to the left. Unlike shiftBytesLeftWithinASingleBlock(int, int), this method supports shifting bytes across multiple blocks in the buffer.

Parameters
length:int

The number of bytes at the end of the buffer that we'll be shifting to the left.

shiftBy:int

The number of bytes to the left that we'll be shifting.

shiftBytesLeftWithinASingleBlockback to summary
private void shiftBytesLeftWithinASingleBlock(int length, int shiftBy)

Shifts the last `length` bytes in the buffer to the left. The caller must guarantee that the `current` Block contains at least `length + shiftBy` bytes. This ensures that we're shifting a contiguous slice of bytes within a single block.

Parameters
length:int

The number of bytes at the end of the buffer that we'll be shifting to the left.

shiftBy:int

The number of bytes to the left that we'll be shifting.

truncateback to summary
public void truncate(final long position)

Resets the write buffer to a particular point.

varUIntLengthback to summary
public static int varUIntLength(final long value)

Get the length of varUint for the provided value.

writeByteback to summary
public void writeByte(final byte octet)

Writes a single octet to the buffer, expanding if necessary.

writeBytesback to summary
public void writeBytes(final byte[] bytes, final int off, final int len)

Writes an array of bytes to the buffer expanding if necessary.

writeBytesback to summary
public void writeBytes(byte[] bytes)

Writes an array of bytes to the buffer expanding if necessary, defaulting to the entire array.

writeBytesSlowback to summary
private void writeBytesSlow(final byte[] bytes, int off, int len)
writeFixedIntback to summary
public int writeFixedInt(final long value)

Writes a FixedInt to this WriteBuffer, using the minimum number of bytes needed to represent the number. Returns the number of bytes that were needed to encode the value.

writeFixedIntOrUIntback to summary
private int writeFixedIntOrUInt(final long value, final int numBytes)

Because the fixed int and fixed uint encodings are so similar, we can use this method to write either one as long as we provide the correct number of bytes needed to encode the value.

writeFixedUIntback to summary
public int writeFixedUInt(final long value)

Writes a FixedUInt to this WriteBuffer, using the minimum number of bytes needed to represent the number. Returns the number of bytes that were needed to encode the value.

writeFlexIntback to summary
public int writeFlexInt(final long value)

Writes a FlexInt to this WriteBuffer, returning the number of bytes that were needed to encode the value

writeFlexIntOrUIntback to summary
private int writeFlexIntOrUInt(final long value, final int numBytes)

Because the flex int and flex uint encodings are so similar, we can use this method to write either one as long as we provide the correct number of bytes needed to encode the value.

writeFlexUIntback to summary
public int writeFlexUInt(final long value)

Writes a FlexUInt to this WriteBuffer, returning the number of bytes that were needed to encode the value

writeInt16back to summary
public void writeInt16(long value)
writeInt24back to summary
public void writeInt24(long value)
writeInt32back to summary
public void writeInt32(long value)
writeInt40back to summary
public void writeInt40(long value)
writeInt48back to summary
public void writeInt48(long value)
writeInt56back to summary
public void writeInt56(long value)
writeInt64back to summary
public void writeInt64(long value)
writeInt8back to summary
public void writeInt8(long value)
writeLowerNibbleAtback to summary
public void writeLowerNibbleAt(final long position, final long value)

Overwrite the lower nibble of the specified type descriptor byte with the length information.

Parameters
position:long

represents the position of the byte that will be overwritten.

value:long

represents the length value of the container.

writeToback to summary
public void writeTo(final OutputStream out) throws IOException

Write the entire buffer to output stream.

writeToback to summary
public void writeTo(final OutputStream out, long position, long length) throws IOException

Write a specific segment of data from the buffer to a stream.

writeUInt16back to summary
public void writeUInt16(long value)
writeUInt16Slowback to summary
private void writeUInt16Slow(long value)
writeUInt24back to summary
public void writeUInt24(long value)
writeUInt24Slowback to summary
private void writeUInt24Slow(long value)
writeUInt32back to summary
public void writeUInt32(long value)
writeUInt32Slowback to summary
private void writeUInt32Slow(long value)
writeUInt40back to summary
public void writeUInt40(long value)
writeUInt40Slowback to summary
private void writeUInt40Slow(long value)
writeUInt48back to summary
public void writeUInt48(long value)
writeUInt48Slowback to summary
private void writeUInt48Slow(long value)
writeUInt56back to summary
public void writeUInt56(long value)
writeUInt56Slowback to summary
private void writeUInt56Slow(long value)
writeUInt64back to summary
public void writeUInt64(long value)
writeUInt64Slowback to summary
private void writeUInt64Slow(long value)
writeUInt8back to summary
public void writeUInt8(long value)
writeUInt8Atback to summary
public void writeUInt8At(final long position, final long value)
writeUTF8back to summary
public int writeUTF8(final CharSequence chars, int off, int len)

Returns the number of octets written.

writeUTF8back to summary
public int writeUTF8(final CharSequence chars)

Returns the number of octets written.

writeUTF8Slowback to summary
private int writeUTF8Slow(final CharSequence chars, int off, int len)
writeUTF8UpTo2Byteback to summary
private int writeUTF8UpTo2Byte(final CharSequence chars, int off, int len)
writeUTF8UpTo3Byteback to summary
private int writeUTF8UpTo3Byte(final CharSequence chars, int off, int len)
writeVarIntback to summary
public int writeVarInt(long value)
writeVarIntSlowback to summary
private int writeVarIntSlow(final long magnitude, final long signMask)
writeVarUIntback to summary
public int writeVarUInt(final long value)
writeVarUIntDirect1Atback to summary
public void writeVarUIntDirect1At(final long position, final long value)
writeVarUIntDirect2back to summary
private int writeVarUIntDirect2(final long value)
writeVarUIntDirect2Atback to summary
public void writeVarUIntDirect2At(long position, long value)
writeVarUIntDirect2StraddlingAtback to summary
private void writeVarUIntDirect2StraddlingAt(final int index, final int offset, final long value)
writeVarUIntDirect3back to summary
private int writeVarUIntDirect3(final long value)
writeVarUIntDirect4back to summary
private int writeVarUIntDirect4(final long value)
writeVarUIntDirect5back to summary
private int writeVarUIntDirect5(final long value)
writeVarUIntSlowback to summary
private int writeVarUIntSlow(final long value)
writeVarUIntToback to summary
public static void writeVarUIntTo(final OutputStream out, final long value) throws IOException

Write the varUint value to the outputStream.