public class MappedResizeableBuffer extends Object implements AutoCloseable
This buffer is resizable and based upon an underlying FileChannel. The channel is not closed when the buffer is closed.
Note: The resize method is not threadsafe. Concurrent access should only occur after a successful resize.
| Constructor and Description |
|---|
MappedResizeableBuffer(FileChannel fileChannel,
FileChannel.MapMode mapMode,
long offset,
long initialLength)
Attach a view to an off-heap memory region by address.
|
MappedResizeableBuffer(FileChannel fileChannel,
long offset,
long initialLength)
Attach a view to an off-heap memory region by address.
|
| Modifier and Type | Method and Description |
|---|---|
int |
addIntOrdered(long index,
int increment)
Add a value to a given index with ordered store semantics.
|
long |
addLongOrdered(long index,
long increment)
Add a value to a given index with ordered store semantics.
|
long |
addressOffset()
Address offset in memory at which the mapping begins.
|
void |
boundsCheck(long index,
int length)
Check that a given length of bytes is within the bounds from a given index.
|
long |
capacity()
Capacity of the buffer in bytes.
|
void |
checkLimit(long limit)
Check if limit exceeds the capacity.
|
void |
close() |
boolean |
compareAndSetInt(long index,
int expectedValue,
int updateValue)
Atomic compare and set of a long given an expected value.
|
boolean |
compareAndSetLong(long index,
long expectedValue,
long updateValue)
Atomic compare and set of a long given an expected value.
|
FileChannel |
fileChannel()
FileChannel that this buffer is mapping over. |
int |
getAndAddInt(long index,
int delta)
Atomically add a delta to a value at a location returning the previous contents.
|
long |
getAndAddLong(long index,
long delta)
Atomically add a delta to a value at a location returning the previous contents.
|
int |
getAndSetInt(long index,
int value)
Atomically exchange a value at a location returning the previous contents.
|
long |
getAndSetLong(long index,
long value)
Atomically exchange a value at a location returning the previous contents.
|
byte |
getByte(long index)
Get the value at a given index.
|
void |
getBytes(long index,
byte[] dst)
Get from the underlying buffer into a supplied byte array.
|
void |
getBytes(long index,
byte[] dst,
long offset,
int length)
Get bytes from the underlying buffer into a supplied byte array.
|
void |
getBytes(long index,
ByteBuffer dstBuffer,
int length)
Get from the underlying buffer into a supplied
ByteBuffer current Buffer.position(). |
byte |
getByteVolatile(long index)
Get the value at a given index with volatile semantics.
|
char |
getChar(long index)
Get the value at a given index.
|
char |
getChar(long index,
ByteOrder byteOrder)
Get the value at a given index.
|
char |
getCharVolatile(long index)
Get the value at a given index with volatile semantics.
|
double |
getDouble(long index)
Get the value at a given index.
|
double |
getDouble(long index,
ByteOrder byteOrder)
Get the value at a given index.
|
float |
getFloat(long index)
Get the value at a given index.
|
float |
getFloat(long index,
ByteOrder byteOrder)
Get the value at a given index.
|
int |
getInt(long index)
Get the value at a given index.
|
int |
getInt(long index,
ByteOrder byteOrder)
Get the value at a given index.
|
int |
getIntVolatile(long index)
Get the value at a given index with volatile semantics.
|
long |
getLong(long index)
Get the value at a given index.
|
long |
getLong(long index,
ByteOrder byteOrder)
Get the value at a given index.
|
long |
getLongVolatile(long index)
Get the value at a given index with volatile semantics.
|
short |
getShort(long index)
Get the value at a given index.
|
short |
getShort(long index,
ByteOrder byteOrder)
Get the value at a given index.
|
short |
getShortVolatile(long index)
Get the value at a given index with volatile semantics.
|
String |
getStringUtf8(long offset)
Get a String from bytes encoded in UTF-8 format that is length prefixed.
|
String |
getStringUtf8(long offset,
ByteOrder byteOrder)
Get a String from bytes encoded in UTF-8 format that is length prefixed.
|
String |
getStringUtf8(long offset,
int length)
Get part of String from bytes encoded in UTF-8 format that is length prefixed.
|
String |
getStringWithoutLengthUtf8(long offset,
int length)
Get an encoded UTF-8 String from the buffer that does not have a length prefix.
|
FileChannel.MapMode |
mapMode()
The
FileChannel.MapMode that will be used when mapping the file. |
void |
putByte(long index,
byte value)
Put a value to a given index.
|
void |
putBytes(long index,
byte[] src)
Put an array of src into the underlying buffer.
|
void |
putBytes(long index,
byte[] src,
long offset,
int length)
Put an array into the underlying buffer.
|
void |
putBytes(long index,
ByteBuffer srcBuffer,
int length)
Put bytes into the underlying buffer for the view.
|
void |
putBytes(long index,
ByteBuffer srcBuffer,
long srcIndex,
int length)
Put bytes into the underlying buffer for the view.
|
void |
putBytes(long index,
DirectBuffer srcBuffer,
int srcIndex,
int length)
Put bytes from a source
DirectBuffer into this MutableDirectBuffer at given indices. |
void |
putByteVolatile(long index,
byte value)
Put a value to a given index with volatile semantics.
|
void |
putChar(long index,
char value)
Put a value to a given index.
|
void |
putChar(long index,
char value,
ByteOrder byteOrder)
Put a value to a given index.
|
void |
putCharVolatile(long index,
char value)
Put a value to a given index with volatile semantics.
|
void |
putDouble(long index,
double value)
Put a value to a given index.
|
void |
putDouble(long index,
double value,
ByteOrder byteOrder)
Put a value to a given index.
|
void |
putFloat(long index,
float value)
Put a value to a given index.
|
void |
putFloat(long index,
float value,
ByteOrder byteOrder)
Put a value to a given index.
|
void |
putInt(long index,
int value)
Put a value to a given index.
|
void |
putInt(long index,
int value,
ByteOrder byteOrder)
Put a value to a given index.
|
void |
putIntOrdered(long index,
int value)
Put a value to a given index with ordered store semantics.
|
void |
putIntVolatile(long index,
int value)
Put a value to a given index with volatile semantics.
|
void |
putLong(long index,
long value)
Put a value to a given index.
|
void |
putLong(long index,
long value,
ByteOrder byteOrder)
Put a value to a given index.
|
void |
putLongOrdered(long index,
long value)
Put a value to a given index with ordered store semantics.
|
void |
putLongVolatile(long index,
long value)
Put a value to a given index with volatile semantics.
|
void |
putShort(long index,
short value)
Put a value to a given index.
|
void |
putShort(long index,
short value,
ByteOrder byteOrder)
Put a value to a given index.
|
void |
putShortVolatile(long index,
short value)
Put a value to a given index with volatile semantics.
|
int |
putStringUtf8(long offset,
String value)
Encode a String as UTF-8 bytes to the buffer with a length prefix.
|
int |
putStringUtf8(long offset,
String value,
ByteOrder byteOrder)
Encode a String as UTF-8 bytes to the buffer with a length prefix.
|
int |
putStringUtf8(long offset,
String value,
ByteOrder byteOrder,
int maxEncodedSize)
Encode a String as UTF-8 bytes the buffer with a length prefix with a maximum encoded size check.
|
int |
putStringUtf8(long offset,
String value,
int maxEncodedSize)
Encode a String as UTF-8 bytes the buffer with a length prefix with a maximum encoded size check.
|
int |
putStringWithoutLengthUtf8(long offset,
String value)
Encode a String as UTF-8 bytes in the buffer without a length prefix.
|
void |
resize(long newLength)
Resize the buffer.
|
void |
setMemory(long index,
int length,
byte value)
Set a region of memory to a given byte value.
|
String |
toString() |
void |
verifyAlignment()
Verify that the underlying buffer is correctly aligned to prevent word tearing and other ordering issues.
|
void |
wrap(FileChannel fileChannel,
FileChannel.MapMode mapMode,
long offset,
long length)
Remap the buffer based on a new file, mapping mode, offset, and a length
|
void |
wrap(FileChannel fileChannel,
long offset,
long length)
Remap the buffer based on a new file, offset, and a length
|
void |
wrap(long offset,
long length)
Remap the buffer using the existing file based on a new offset and length
|
public MappedResizeableBuffer(FileChannel fileChannel, long offset, long initialLength)
FileChannel.MapMode.READ_WRITE.fileChannel - the file to mapoffset - the offset of the file to start the mappinginitialLength - of the buffer from the given addresspublic MappedResizeableBuffer(FileChannel fileChannel, FileChannel.MapMode mapMode, long offset, long initialLength)
fileChannel - the file to mapmapMode - for the mappingoffset - the offset of the file to start the mappinginitialLength - of the buffer from the given addresspublic void close()
close in interface AutoCloseablepublic void resize(long newLength)
newLength - in bytes.public void wrap(long offset,
long length)
offset - the offset of the file to start the mappinglength - of the buffer from the given addresspublic void wrap(FileChannel fileChannel, long offset, long length)
fileChannel - the file to mapoffset - the offset of the file to start the mappinglength - of the buffer from the given addresspublic void wrap(FileChannel fileChannel, FileChannel.MapMode mapMode, long offset, long length)
fileChannel - the file to mapmapMode - for the file when mapping.offset - the offset of the file to start the mappinglength - of the buffer from the given addresspublic long addressOffset()
public FileChannel fileChannel()
FileChannel that this buffer is mapping over.FileChannel that this buffer is mapping over.public FileChannel.MapMode mapMode()
FileChannel.MapMode that will be used when mapping the file.FileChannel.MapMode that will be used when mapping the file.public void setMemory(long index,
int length,
byte value)
index - at which to start.length - of the run of bytes to set.value - the memory will be set to.public long capacity()
public void checkLimit(long limit)
limit - to check.public void verifyAlignment()
IllegalStateException - if the alignment is not correct.public long getLong(long index,
ByteOrder byteOrder)
index - in bytes from which to get.byteOrder - of the value to be read.public void putLong(long index,
long value,
ByteOrder byteOrder)
index - in bytes for where to put.value - for at a given index.byteOrder - of the value when written.public long getLong(long index)
index - in bytes from which to get.public void putLong(long index,
long value)
index - in bytes for where to put.value - for at a given index.public long getLongVolatile(long index)
index - in bytes from which to get.public void putLongVolatile(long index,
long value)
index - in bytes for where to put.value - for at a given index.public void putLongOrdered(long index,
long value)
index - in bytes for where to put.value - for at a given index.public long addLongOrdered(long index,
long increment)
index - in bytes for where to put.increment - by which the value at the index will be adjusted.public boolean compareAndSetLong(long index,
long expectedValue,
long updateValue)
index - in bytes for where to put.expectedValue - at to be compared.updateValue - to be exchanged.public long getAndSetLong(long index,
long value)
index - in bytes for where to put.value - for at a given index.public long getAndAddLong(long index,
long delta)
index - in bytes for where to put.delta - to be added to the value at the index.public int getInt(long index,
ByteOrder byteOrder)
index - in bytes from which to get.byteOrder - of the value to be read.public void putInt(long index,
int value,
ByteOrder byteOrder)
index - in bytes for where to put.value - for at a given index.byteOrder - of the value when written.public int getInt(long index)
index - in bytes from which to get.public void putInt(long index,
int value)
index - in bytes for where to put.value - for at a given index.public int getIntVolatile(long index)
index - in bytes from which to get.public void putIntVolatile(long index,
int value)
index - in bytes for where to put.value - for at a given index.public void putIntOrdered(long index,
int value)
index - in bytes for where to put.value - for at a given index.public int addIntOrdered(long index,
int increment)
index - in bytes for where to put.increment - by which the value at the index will be adjusted.public boolean compareAndSetInt(long index,
int expectedValue,
int updateValue)
index - in bytes for where to put.expectedValue - at to be compared.updateValue - to be exchanged.public int getAndSetInt(long index,
int value)
index - in bytes for where to put.value - for at a given index.public int getAndAddInt(long index,
int delta)
index - in bytes for where to put.delta - to be added to the value at the index.public double getDouble(long index,
ByteOrder byteOrder)
index - in bytes from which to get.byteOrder - of the value to be read.public void putDouble(long index,
double value,
ByteOrder byteOrder)
index - in bytes for where to put.value - for at a given index.byteOrder - of the value when written.public double getDouble(long index)
index - in bytes from which to get.public void putDouble(long index,
double value)
index - in bytes for where to put.value - for at a given index.public float getFloat(long index,
ByteOrder byteOrder)
index - in bytes from which to get.byteOrder - of the value to be read.public void putFloat(long index,
float value,
ByteOrder byteOrder)
index - in bytes for where to put.value - for at a given index.byteOrder - of the value when written.public float getFloat(long index)
index - in bytes from which to get.public void putFloat(long index,
float value)
index - in bytes for where to put.value - for at a given index.public short getShort(long index,
ByteOrder byteOrder)
index - in bytes from which to get.byteOrder - of the value to be read.public void putShort(long index,
short value,
ByteOrder byteOrder)
index - in bytes for where to put.value - for at a given index.byteOrder - of the value when written.public short getShort(long index)
index - in bytes from which to get.public void putShort(long index,
short value)
index - in bytes for where to put.value - for at a given index.public short getShortVolatile(long index)
index - in bytes from which to get.public void putShortVolatile(long index,
short value)
index - in bytes for where to put.value - for at a given index.public byte getByte(long index)
index - in bytes from which to get.public void putByte(long index,
byte value)
index - in bytes for where to put.value - for at a given index.public byte getByteVolatile(long index)
index - in bytes from which to get.public void putByteVolatile(long index,
byte value)
index - in bytes for where to put.value - for at a given index.public void getBytes(long index,
byte[] dst)
index - in the underlying buffer to start from.dst - into which the dst will be copied.public void getBytes(long index,
byte[] dst,
long offset,
int length)
index - in the underlying buffer to start from.dst - into which the bytes will be copied.offset - in the supplied buffer to start the copy.length - of the supplied buffer to use.public void getBytes(long index,
ByteBuffer dstBuffer,
int length)
ByteBuffer current Buffer.position().
The destination buffer will have its Buffer.position() advanced as a result.
index - in the underlying buffer to start from.dstBuffer - into which the bytes will be copied.length - of the supplied buffer to use.public void putBytes(long index,
byte[] src)
index - in the underlying buffer to start from.src - to be copied to the underlying buffer.public void putBytes(long index,
byte[] src,
long offset,
int length)
index - in the underlying buffer to start from.src - to be copied to the underlying buffer.offset - in the supplied buffer to begin the copy.length - of the supplied buffer to copy.public void putBytes(long index,
ByteBuffer srcBuffer,
int length)
Buffer.position() for a given length.
The source buffer will have its Buffer.position() advanced as a result.
index - in the underlying buffer to start from.srcBuffer - to copy the bytes from.length - of the supplied buffer to copy.public void putBytes(long index,
ByteBuffer srcBuffer,
long srcIndex,
int length)
The source buffer will not have its Buffer.position() advanced as a result.
index - in the underlying buffer to start from.srcBuffer - to copy the bytes from (does not change position).srcIndex - in the source buffer from which the copy will begin.length - of the bytes to be copied.public void putBytes(long index,
DirectBuffer srcBuffer,
int srcIndex,
int length)
DirectBuffer into this MutableDirectBuffer at given indices.index - in this buffer to begin putting the bytes.srcBuffer - from which the bytes will be copied.srcIndex - in the source buffer from which the byte copy will begin.length - of the bytes to be copied.public char getChar(long index,
ByteOrder byteOrder)
index - in bytes from which to get.byteOrder - of the value to be read.public void putChar(long index,
char value,
ByteOrder byteOrder)
index - in bytes for where to put.value - for at a given index.byteOrder - of the value when written.public char getChar(long index)
index - in bytes from which to get.public void putChar(long index,
char value)
index - in bytes for where to put.value - for at a given index.public char getCharVolatile(long index)
index - in bytes from which to get.public void putCharVolatile(long index,
char value)
index - in bytes for where to put.value - for at a given index.public String getStringUtf8(long offset)
offset - at which the String begins.public String getStringUtf8(long offset, ByteOrder byteOrder)
offset - at which the String begins.byteOrder - for the length at the beginning of the String.public String getStringUtf8(long offset, int length)
offset - at which the String begins.length - of the String in bytes to decode.public int putStringUtf8(long offset,
String value)
offset - at which the String should be encoded.value - of the String to be encoded.public int putStringUtf8(long offset,
String value,
ByteOrder byteOrder)
offset - at which the String should be encoded.value - of the String to be encoded.byteOrder - for the length prefix.public int putStringUtf8(long offset,
String value,
int maxEncodedSize)
offset - at which the String should be encoded.value - of the String to be encoded.maxEncodedSize - to be checked before writing to the buffer.IllegalArgumentException - if the encoded bytes are greater than maxEncodedLength.public int putStringUtf8(long offset,
String value,
ByteOrder byteOrder,
int maxEncodedSize)
offset - at which the String should be encoded.value - of the String to be encoded.byteOrder - for the length prefix.maxEncodedSize - to be checked before writing to the buffer.IllegalArgumentException - if the encoded bytes are greater than maxEncodedLength.public String getStringWithoutLengthUtf8(long offset, int length)
offset - at which the String begins.length - of the String in bytes to decode.public int putStringWithoutLengthUtf8(long offset,
String value)
offset - at which the String begins.value - of the String to be encoded.public void boundsCheck(long index,
int length)
index - from which to check.length - in bytes of the range to check.IndexOutOfBoundsException - if the length goes outside the capacity range.Copyright © 2014-2022 Real Logic Limited. All Rights Reserved.