The blocked array is expanded and shrunk as required.
| Modifier and Type | Field and Description |
|---|---|
| private static final int | _16K
Constant for 16 KB. |
| private static final int | _32K
Constant for 32 KB. |
| private static final int | _4K
Constant for 4 KB. |
| private static final int | _8K
Constant for 8 KB. |
| private int | allocatedBlocks
The number of allocated blocks. |
| private byte[][] | blocks
References to blocks of data. |
| private int | blockSize
The size of a block of data (the allocation unit). |
| private static final int | DEFAULT_BLOCKSIZE
The default block size. |
| private static final int | INITIAL_BLOCK_HOLDER_SIZE
The default number of slots for holding a block of data. |
| private long | length
The number of bytes stored in the blocked byte array. |
| private static final int | MIN_HOLDER_GROWTH
Minimum number of holder slots to grow with when the block holder array has to grow to be able to reference all the data arrays. |
| Access | Constructor and Description |
|---|---|
| public | BlockedByteArray()
Creates a new blocked byte array with the default number of slots to hold byte arrays (blocks). |
| Modifier and Type | Method and Description |
|---|---|
| private void | checkBlockSize(int
the requested number of bytes to be written len)Tries to optimize the block size by setting it equal to the the page size used by the database. |
| pack-priv synchronized BlockedByteArrayInputStream | Returns: AnInputStream-object.Returns an input stream serving the data in the blocked byte array. |
| pack-priv synchronized BlockedByteArrayOutputStream | Returns: AnOutputStream-object.initial position of the output stream pos)Returns an output stream writing data into the blocked byte array. |
| private void | increaseCapacity(long
the index that must fit into the array lastIndex)Increases the capacity of this blocked byte array by allocating more blocks. |
| public synchronized long | |
| public synchronized int | |
| public synchronized int | Returns: The number of bytes read.the position to start reading at pos, byte[] the destination buffer buf, int offset into the destination buffer offset, int the number of bytes to read len)Reads up to |
| pack-priv synchronized void | |
| public synchronized void | setLength(final long
the new length of the allocated data in bytes newLength)Changes the allocated length of the data. |
| public synchronized int | Returns: 1, which is the number of bytes written.the position to write the byte at pos, byte the byte to write b)Writes the given byte into the blocked byte array. |
| public synchronized int | Returns: The number of bytes written.the position to start writing at pos, final byte[] the source buffer buf, int the offset into the source buffer offset, final int the number of bytes to write len)Writes the given bytes into the blocked byte array. |
| _16K | back to summary |
|---|---|
| private static final int _16K Constant for 16 KB. | |
| _32K | back to summary |
|---|---|
| private static final int _32K Constant for 32 KB. | |
| _4K | back to summary |
|---|---|
| private static final int _4K Constant for 4 KB. | |
| _8K | back to summary |
|---|---|
| private static final int _8K Constant for 8 KB. | |
| allocatedBlocks | back to summary |
|---|---|
| private int allocatedBlocks The number of allocated blocks. | |
| blocks | back to summary |
|---|---|
| private byte[][] blocks References to blocks of data. | |
| blockSize | back to summary |
|---|---|
| private int blockSize The size of a block of data (the allocation unit). | |
| DEFAULT_BLOCKSIZE | back to summary |
|---|---|
| private static final int DEFAULT_BLOCKSIZE The default block size. | |
| INITIAL_BLOCK_HOLDER_SIZE | back to summary |
|---|---|
| private static final int INITIAL_BLOCK_HOLDER_SIZE The default number of slots for holding a block of data. | |
| length | back to summary |
|---|---|
| private long length The number of bytes stored in the blocked byte array. | |
| MIN_HOLDER_GROWTH | back to summary |
|---|---|
| private static final int MIN_HOLDER_GROWTH Minimum number of holder slots to grow with when the block holder array has to grow to be able to reference all the data arrays. | |
| BlockedByteArray | back to summary |
|---|---|
| public BlockedByteArray() Creates a new blocked byte array with the default number of slots to hold byte arrays (blocks). No blocks are pre-allocated.
| |
| checkBlockSize | back to summary |
|---|---|
| private void checkBlockSize(int len) Tries to optimize the block size by setting it equal to the the page size used by the database. Since we don't have a way of knowing which page size will be used, wait to set the block size until the first write request and see how many bytes are written then.
| |
| getInputStream | back to summary |
|---|---|
| pack-priv synchronized BlockedByteArrayInputStream getInputStream() Returns an input stream serving the data in the blocked byte array.
| |
| getOutputStream | back to summary |
|---|---|
| pack-priv synchronized BlockedByteArrayOutputStream getOutputStream(long pos) Returns an output stream writing data into the blocked byte array.
| |
| increaseCapacity | back to summary |
|---|---|
| private void increaseCapacity(long lastIndex) Increases the capacity of this blocked byte array by allocating more blocks.
| |
| length | back to summary |
|---|---|
| public synchronized long length() Returns the number of bytes allocated.
| |
| read | back to summary |
|---|---|
| public synchronized int read(long pos) Returns the byte at the given position.
| |
| read | back to summary |
|---|---|
| public synchronized int read(long pos, byte[] buf, int offset, int len) Reads up to
| |
| release | back to summary |
|---|---|
| pack-priv synchronized void release() Releases this array. | |
| setLength | back to summary |
|---|---|
| public synchronized void setLength(final long newLength) Changes the allocated length of the data. If the new length is larger than the current length, the blocked byte array will be extended with new blocks. If the new length is smaller, existing (allocated) blocks will be removed if possible.
| |
| writeByte | back to summary |
|---|---|
| public synchronized int writeByte(long pos, byte b) Writes the given byte into the blocked byte array.
| |
| writeBytes | back to summary |
|---|---|
| public synchronized int writeBytes(final long pos, final byte[] buf, int offset, final int len) Writes the given bytes into the blocked byte array.
| |