public class HeapBytes extends AbstractBytes
| Modifier and Type | Method and Description |
|---|---|
static HeapBytes |
allocate(long size)
Allocates a new heap byte array.
|
byte[] |
array()
Returns the underlying byte array.
|
void |
close() |
HeapBytes |
copy()
Copies the bytes to a new byte array.
|
Bytes |
flush()
Flushes the bytes to the underlying persistence layer.
|
Bytes |
read(long position,
byte[] bytes,
long offset,
long length)
Reads bytes into the given byte array starting at the given offset up to the given length.
|
Bytes |
read(long position,
Bytes bytes,
long offset,
long length)
Reads bytes into the given byte array starting at the given offset up to the given length.
|
boolean |
readBoolean(long offset)
Reads a 1 byte boolean from the buffer at the given offset.
|
int |
readByte(long offset)
Reads a byte from the buffer at the given offset.
|
char |
readChar(long offset)
Reads a 16-bit character from the buffer at the given offset.
|
double |
readDouble(long offset)
Reads a double-precision 64-bit floating point number from the buffer at the given offset.
|
float |
readFloat(long offset)
Reads a single-precision 32-bit floating point number from the buffer at the given offset.
|
int |
readInt(long offset)
Reads a 32-bit signed integer from the buffer at the given offset.
|
long |
readLong(long offset)
Reads a 64-bit signed integer from the buffer at the given offset.
|
int |
readMedium(long offset)
Reads a 24-bit signed integer from the buffer at the given offset.
|
short |
readShort(long offset)
Reads a 16-bit signed integer from the buffer at the given offset.
|
String |
readString(long offset)
Reads a string from the buffer at the given offset.
|
int |
readUnsignedByte(long offset)
Reads an unsigned byte from the buffer at the given offset.
|
long |
readUnsignedInt(long offset)
Reads a 32-bit unsigned integer from the buffer at the given offset.
|
int |
readUnsignedMedium(long offset)
Reads a 24-bin unsigned integer from the buffer at the given offset.
|
int |
readUnsignedShort(long offset)
Reads a 16-bit unsigned integer from the buffer at the given offset.
|
String |
readUTF8(long offset)
Reads a UTF-8 string from the buffer at the given offset.
|
HeapBytes |
reset(byte[] array)
Resets the heap byte array.
|
Bytes |
resize(long newSize)
Resizes the bytes.
|
long |
size()
Returns the count of the bytes.
|
static HeapBytes |
wrap(byte[] bytes)
Wraps the given bytes in a
HeapBytes object. |
Bytes |
write(long position,
byte[] bytes,
long offset,
long length)
Writes an array of bytes to the buffer.
|
Bytes |
write(long position,
Bytes bytes,
long offset,
long length)
Writes an array of bytes to the buffer.
|
Bytes |
writeBoolean(long offset,
boolean b)
Writes a 1 byte boolean to the buffer at the given offset.
|
Bytes |
writeByte(long offset,
int b)
Writes a byte to the buffer at the given offset.
|
Bytes |
writeChar(long offset,
char c)
Writes a 16-bit character to the buffer at the given offset.
|
Bytes |
writeDouble(long offset,
double d)
Writes a double-precision 64-bit floating point number to the buffer at the given offset.
|
Bytes |
writeFloat(long offset,
float f)
Writes a single-precision 32-bit floating point number to the buffer at the given offset.
|
Bytes |
writeInt(long offset,
int i)
Writes a 32-bit signed integer to the buffer at the given offset.
|
Bytes |
writeLong(long offset,
long l)
Writes a 64-bit signed integer to the buffer at the given offset.
|
Bytes |
writeMedium(long offset,
int m)
Writes a 24-bit signed integer to the buffer at the given offset.
|
Bytes |
writeShort(long offset,
short s)
Writes a 16-bit signed integer to the buffer at the given offset.
|
Bytes |
writeString(long offset,
String s)
Writes a string to the buffer at the given offset.
|
Bytes |
writeUnsignedByte(long offset,
int b)
Writes an unsigned byte to the buffer at the given position.
|
Bytes |
writeUnsignedInt(long offset,
long i)
Writes a 32-bit unsigned integer to the buffer at the given offset.
|
Bytes |
writeUnsignedMedium(long offset,
int m)
Writes a 24-bit unsigned integer to the buffer at the given offset.
|
Bytes |
writeUnsignedShort(long offset,
int s)
Writes a 16-bit unsigned integer to the buffer at the given offset.
|
Bytes |
writeUTF8(long offset,
String s)
Writes a UTF-8 string to the buffer at the given offset.
|
Bytes |
zero()
Zeros out all bytes in the array.
|
Bytes |
zero(long offset)
Zeros out all bytes starting at the given offset in the array.
|
Bytes |
zero(long offset,
long length)
Zeros out bytes starting at the given offset up to the given length.
|
isDirect, isFile, order, orderpublic static HeapBytes allocate(long size)
When the array is constructed, HeapMemoryAllocator will be used to allocate
count bytes on the Java heap.
size - The count of the buffer to allocate (in bytes).IllegalArgumentException - If count is greater than the maximum allowed count for
an array on the Java heap - Integer.MAX_VALUE - 5public static HeapBytes wrap(byte[] bytes)
HeapBytes object.
The returned Bytes object will be backed by a HeapMemory instance that
wraps the given byte array. The Bytes.size() will be equivalent to the provided
by array length.
bytes - The bytes to wrap.public HeapBytes copy()
HeapBytes instance backed by a copy of this instance's array.public byte[] array()
public HeapBytes reset(byte[] array)
array - The internal byte array.public long size()
Bytespublic Bytes resize(long newSize)
Bytes
When the bytes are resized, underlying memory addresses in copies of this instance may no longer be valid. Additionally,
if the newSize is smaller than the current count then some data may be lost during the resize. Use
with caution.
newSize - The count to which to resize this instance.public Bytes zero()
BytesOutputpublic Bytes zero(long offset)
BytesOutputoffset - The offset at which to start zeroing out bytes.public Bytes zero(long offset, long length)
BytesOutputoffset - The offset at which to start zeroing out bytes.length - THe total number of bytes to zero out.public Bytes read(long position, Bytes bytes, long offset, long length)
BytesInputposition - The offset from which to start reading bytes.bytes - The byte array into which to read bytes.offset - The offset at which to write bytes into the given buffer.length - The total number of bytes to read.public Bytes read(long position, byte[] bytes, long offset, long length)
BytesInputposition - The offset from which to start reading bytes.bytes - The byte array into which to read bytes.offset - The offset at which to write bytes into the given bufferlength - The total number of bytes to read.public int readByte(long offset)
BytesInputoffset - The offset at which to read the byte.public int readUnsignedByte(long offset)
BytesInputoffset - The offset at which to read the byte.public char readChar(long offset)
BytesInputoffset - The offset at which to read the character.public short readShort(long offset)
BytesInputoffset - The offset at which to read the short.public int readUnsignedShort(long offset)
BytesInputoffset - The offset at which to read the short.public int readMedium(long offset)
BytesInputoffset - The offset at which to read the integer.public int readUnsignedMedium(long offset)
BytesInputoffset - The offset at which to read the integer.public int readInt(long offset)
BytesInputoffset - The offset at which to read the integer.public long readUnsignedInt(long offset)
BytesInputoffset - The offset at which to read the integer.public long readLong(long offset)
BytesInputoffset - The offset at which to read the long.public float readFloat(long offset)
BytesInputoffset - The offset at which to read the float.public double readDouble(long offset)
BytesInputoffset - The offset at which to read the double.public boolean readBoolean(long offset)
BytesInputoffset - The offset at which to read the boolean.public String readString(long offset)
BytesInputoffset - The offset at which to read the string.public String readUTF8(long offset)
BytesInputoffset - The offset at which to read the string.public Bytes write(long position, Bytes bytes, long offset, long length)
BytesOutputposition - The offset at which to start writing the bytes.bytes - The array of bytes to write.offset - The offset at which to start reading bytes from the given source.length - The number of bytes from the provided byte array to write to the buffer.public Bytes write(long position, byte[] bytes, long offset, long length)
BytesOutputposition - The offset at which to start writing the bytes.bytes - The array of bytes to write.offset - The offset at which to start reading bytes from the given source.length - The number of bytes from the provided byte array to write to the buffer.public Bytes writeByte(long offset, int b)
BytesOutputoffset - The offset at which to write the byte.b - The byte to write.public Bytes writeUnsignedByte(long offset, int b)
BytesOutputoffset - The offset at which to write the byte.b - The byte to write.public Bytes writeChar(long offset, char c)
BytesOutputoffset - The offset at which to write the character.c - The character to write.public Bytes writeShort(long offset, short s)
BytesOutputoffset - The offset at which to write the short.s - The short to write.public Bytes writeUnsignedShort(long offset, int s)
BytesOutputoffset - The offset at which to write the short.s - The short to write.public Bytes writeMedium(long offset, int m)
BytesOutputoffset - The offset at which to write the short.m - The short to write.public Bytes writeUnsignedMedium(long offset, int m)
BytesOutputoffset - The offset at which to write the short.m - The short to write.public Bytes writeInt(long offset, int i)
BytesOutputoffset - The offset at which to write the integer.i - The integer to write.public Bytes writeUnsignedInt(long offset, long i)
BytesOutputoffset - The offset at which to write the integer.i - The integer to write.public Bytes writeLong(long offset, long l)
BytesOutputoffset - The offset at which to write the long.l - The long to write.public Bytes writeFloat(long offset, float f)
BytesOutputoffset - The offset at which to write the float.f - The float to write.public Bytes writeDouble(long offset, double d)
BytesOutputoffset - The offset at which to write the double.d - The double to write.public Bytes writeBoolean(long offset, boolean b)
BytesOutputoffset - The offset at which to write the boolean.b - The boolean to write.public Bytes writeString(long offset, String s)
BytesOutputoffset - The offset at which to write the string.s - The string to write.public Bytes writeUTF8(long offset, String s)
BytesOutputoffset - The offset at which to write the string.s - The string to write.public Bytes flush()
BytesOutputpublic void close()
close in interface AutoCloseableclose in interface Bytesclose in class AbstractBytesCopyright © 2013–2015. All rights reserved.