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

pack-priv final Class BlockedBuffer

extends Object
Class Inheritance
Imports
com.amazon.ion.IonException, java.io.ByteArrayOutputStream, .IOException, .InputStream, .OutputStream, java.util.ArrayList, .Comparator, .SortedSet, .TreeSet

This implements a blocked byte buffer and both an input and output stream that operates over it. It is designed to be able to be randomly accessed. The output steam supports both inserting data (with "stretching") in the middle of the stream and over-write. The output steam also supports remove which shrinks the overall data buffer. The underlying buffer is backed by one or more byte arrays to minimize data movement.

It is also meant to be reused, so that it does not have to pressure the GC, if that is desirable.

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static class
public static class
public static class
BlockedBuffer.BlockedByteInputStream

Reads data from a byte buffer, keeps a local position and a current block.

public static class
BlockedBuffer.BlockedByteOutputStream

Reads data from a byte buffer, keeps a local position and a current block.

public static class
private static class
public static interface
private static class

Field Summary

Modifier and TypeField and Description
pack-priv ArrayList<BlockedBuffer.bbBlock>
public int
public int
pack-priv int
pack-priv static int
pack-priv static int
pack-priv int
pack-priv int
pack-priv Object
pack-priv int
pack-priv TreeSet<BlockedBuffer.Monitor>
pack-priv static int
pack-priv int
pack-priv static boolean
pack-priv static final boolean

Constructor Summary

AccessConstructor and Description
public
BlockedBuffer()

Creates a new buffer without preallocating any space.

public
BlockedBuffer(int
the number of bytes to allocate.
initialSize
)

Creates a new buffer, preallocating some initial capacity.

public
BlockedBuffer(byte[]
the initial data to be buffered.
data
)

Creates a new buffer, assuming ownership of given data.

public
BlockedBuffer(InputStream
must not be null.
data
)

Creates a new buffer containing all data remaining on an InputStream.

Method Summary

Modifier and TypeMethod and Description
public boolean
private BlockedBuffer.bbBlock
addBlock(Object caller, int version, int idx, int offset, int needed)

private void
adjustOffsets(int lastidx, int addedBytes, int addedBlocks)

private void
clear(Object caller, int version)

empties the entire contents of the buffer

public BlockedBuffer
clone()

Overrides java.lang.Object.clone.

creates a logical copy of the buffer.

pack-priv int
pack-priv BlockedBuffer.bbBlock

Returns:

curr block ready to be read from
findBlockForRead
(Object caller, int version, BlockedBuffer.bbBlock curr, int
global position to be read from
pos
)

find the block where this offset (newPosition) has already been written.

pack-priv BlockedBuffer.bbBlock

Returns:

curr block ready to be written to
findBlockForWrite
(Object caller, int version, BlockedBuffer.bbBlock curr, int
global position to be written to
pos
)

find the block where this offset (newPosition) should be written.

pack-priv final BlockedBuffer.bbBlock
findBlockHelper(int pos, int lo, int hi)

pack-priv int
private BlockedBuffer.bbBlock

Returns:

bbBlock the initial current block
init
(int
or 0
initialSize
,
BlockedBuffer.bbBlock
or null
initialBlock
)

Initializes the various members such as the block arraylist the initial block and the various values like the block size upper limit.

pack-priv int

Returns:

int number of bytes inserted
insert
(Object caller, int version, BlockedBuffer.bbBlock curr, int pos, int
number of bytes to make space for
len
)

dispatcher for the various forms of insert we encounter calls one of the four helpers depending on the case that is needed to inser here

private int
insertAsManyBlocksAsNeeded(Object caller, int version, BlockedBuffer.bbBlock curr, int pos, int len, BlockedBuffer.bbBlock newLastBlock)

private void
private int
insertInCurrAndNext(Object caller, int version, BlockedBuffer.bbBlock curr, int pos, int len, BlockedBuffer.bbBlock next)

private int
insertInCurrOnly(Object caller, int version, BlockedBuffer.bbBlock curr, int pos, int len)

this handles insert when there's enough room in the current block

private BlockedBuffer.bbBlock
insertMakeNewTailBlock(Object caller, int version, BlockedBuffer.bbBlock curr, int minimumBlockSize)

pack-priv boolean
mutation_in_progress(Object caller, int version)

private int
nextBlockSize(Object caller, int version)

public void
notifyInsert(int pos, int len)

public void
public void
notifyRemove(int pos, int len)

public void
pack-priv BlockedBuffer.bbBlock
remove(Object caller, int version, BlockedBuffer.bbBlock curr, int pos, int len)

public static void
pack-priv static void
setBlockSizeParameters(int min, int max, boolean intenseValidation)

public static void
setBlockSizeParameters(int min, int max)

public final int
size()

Gets the number of bytes of content in this buffer.

pack-priv void
start_mutate(Object caller, int version)

pack-priv BlockedBuffer.bbBlock
truncate(Object caller, int version, int pos)

treat the limit as the end of file

Inherited from java.lang.Object:
equalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait