public class BlockedByteArray
extends java.lang.Object
The blocked array is expanded and shrunk as required.
Modifier and Type | Field | Description |
---|---|---|
private static int |
_16K |
Constant for 16 KB.
|
private static int |
_32K |
Constant for 32 KB.
|
private static int |
_4K |
Constant for 4 KB.
|
private static 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 int |
DEFAULT_BLOCKSIZE |
The default block size.
|
private static 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 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.
|
Constructor | Description |
---|---|
BlockedByteArray() |
Creates a new blocked byte array with the default number of slots to
hold byte arrays (blocks).
|
Modifier and Type | Method | Description |
---|---|---|
private void |
checkBlockSize(int len) |
Tries to optimize the block size by setting it equal to the the page
size used by the database.
|
(package private) BlockedByteArrayInputStream |
getInputStream() |
Returns an input stream serving the data in the blocked byte array.
|
(package private) BlockedByteArrayOutputStream |
getOutputStream(long pos) |
Returns an output stream writing data into the blocked byte array.
|
private void |
increaseCapacity(long lastIndex) |
Increases the capacity of this blocked byte array by allocating more
blocks.
|
long |
length() |
Returns the number of bytes allocated.
|
int |
read(long pos) |
Returns the byte at the given position.
|
int |
read(long pos,
byte[] buf,
int offset,
int len) |
Reads up to
len bytes. |
(package private) void |
release() |
Releases this array.
|
void |
setLength(long newLength) |
Changes the allocated length of the data.
|
int |
writeByte(long pos,
byte b) |
Writes the given byte into the blocked byte array.
|
int |
writeBytes(long pos,
byte[] buf,
int offset,
int len) |
Writes the given bytes into the blocked byte array.
|
private static final int _4K
private static final int _8K
private static final int _16K
private static final int _32K
private static final int DEFAULT_BLOCKSIZE
private static final int INITIAL_BLOCK_HOLDER_SIZE
private static final int MIN_HOLDER_GROWTH
private byte[][] blocks
private int blockSize
private int allocatedBlocks
private long length
public BlockedByteArray()
No blocks are pre-allocated.
INITIAL_BLOCK_HOLDER_SIZE
public int read(long pos)
pos
- position to read frompublic int read(long pos, byte[] buf, int offset, int len)
len
bytes.pos
- the position to start reading atbuf
- the destination bufferoffset
- offset into the destination bufferlen
- the number of bytes to readpublic long length()
public void setLength(long newLength)
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.
newLength
- the new length of the allocated data in bytespublic int writeBytes(long pos, byte[] buf, int offset, int len)
pos
- the position to start writing atbuf
- the source bufferoffset
- the offset into the source bufferlen
- the number of bytes to writepublic int writeByte(long pos, byte b)
pos
- the position to write the byte atb
- the byte to write1
, which is the number of bytes written.BlockedByteArrayInputStream getInputStream()
InputStream
-object.BlockedByteArrayOutputStream getOutputStream(long pos)
pos
- initial position of the output streamOutputStream
-object.void release()
private void checkBlockSize(int len)
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.
len
- the requested number of bytes to be writtenprivate void increaseCapacity(long lastIndex)
lastIndex
- the index that must fit into the arrayApache Derby V10.14 Internals - Copyright © 2004,2018 The Apache Software Foundation. All Rights Reserved.