org.apache.derby.impl.io.vfmem
Class BlockedByteArray
- java.lang.Object
-
- org.apache.derby.impl.io.vfmem.BlockedByteArray
-
public class BlockedByteArray extends java.lang.ObjectStores data in blocks, and supports reading/writing data from/into these blocks.The blocked array is expanded and shrunk as required.
-
-
Constructor Summary
Constructors Constructor and Description BlockedByteArray()Creates a new blocked byte array with the default number of slots to hold byte arrays (blocks).
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description longlength()Returns the number of bytes allocated.intread(long pos)Returns the byte at the given position.intread(long pos, byte[] buf, int offset, int len)Reads up tolenbytes.voidsetLength(long newLength)Changes the allocated length of the data.intwriteByte(long pos, byte b)Writes the given byte into the blocked byte array.intwriteBytes(long pos, byte[] buf, int offset, int len)Writes the given bytes into the blocked byte array.
-
-
-
Constructor Detail
-
BlockedByteArray
public BlockedByteArray()
Creates a new blocked byte array with the default number of slots to hold byte arrays (blocks).No blocks are pre-allocated.
- See Also:
INITIAL_BLOCK_HOLDER_SIZE
-
-
Method Detail
-
read
public int read(long pos)
Returns the byte at the given position.- Parameters:
pos- position to read from- Returns:
- A single byte.
-
read
public int read(long pos, byte[] buf, int offset, int len)Reads up tolenbytes.- Parameters:
pos- the position to start reading atbuf- the destination bufferoffset- offset into the destination bufferlen- the number of bytes to read- Returns:
- The number of bytes read.
-
length
public long length()
Returns the number of bytes allocated.- Returns:
- Bytes allocated.
-
setLength
public void setLength(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.
- Parameters:
newLength- the new length of the allocated data in bytes
-
writeBytes
public int writeBytes(long pos, byte[] buf, int offset, int len)Writes the given bytes into the blocked byte array.- Parameters:
pos- the position to start writing atbuf- the source bufferoffset- the offset into the source bufferlen- the number of bytes to write- Returns:
- The number of bytes written.
-
writeByte
public int writeByte(long pos, byte b)Writes the given byte into the blocked byte array.- Parameters:
pos- the position to write the byte atb- the byte to write- Returns:
1, which is the number of bytes written.
-
-
DataMelt 3.0 © DataMelt by jWork.ORG