Package org.apache.druid.segment.data
Class SafeWritableMemory
- java.lang.Object
-
- org.apache.druid.segment.data.SafeWritableBase
-
- org.apache.druid.segment.data.SafeWritableMemory
-
- All Implemented Interfaces:
org.apache.datasketches.memory.BaseState
,org.apache.datasketches.memory.Memory
,org.apache.datasketches.memory.WritableMemory
public class SafeWritableMemory extends SafeWritableBase implements org.apache.datasketches.memory.WritableMemory
Safety first! Don't trust something whose contents you locations to read and write stuff to, but need aMemory
orWritableMemory
? use this!Delegates everything to an underlying
ByteBuffer
so all read and write operations will have bounds checks built in rather than using 'unsafe'.
-
-
Constructor Summary
Constructors Constructor Description SafeWritableMemory(ByteBuffer buffer)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description org.apache.datasketches.memory.Buffer
asBuffer(ByteOrder byteOrder)
org.apache.datasketches.memory.WritableBuffer
asWritableBuffer(ByteOrder byteOrder)
void
clear()
void
clear(long offsetBytes, long lengthBytes)
void
clearBits(long offsetBytes, byte bitMask)
boolean
compareAndSwapLong(long offsetBytes, long expect, long update)
int
compareTo(long thisOffsetBytes, long thisLengthBytes, org.apache.datasketches.memory.Memory that, long thatOffsetBytes, long thatLengthBytes)
void
copyTo(long srcOffsetBytes, org.apache.datasketches.memory.WritableMemory destination, long dstOffsetBytes, long lengthBytes)
boolean
equalTo(long thisOffsetBytes, Object that, long thatOffsetBytes, long lengthBytes)
void
fill(byte value)
void
fill(long offsetBytes, long lengthBytes, byte value)
long
getAndAddLong(long offsetBytes, long delta)
long
getAndSetLong(long offsetBytes, long newValue)
Object
getArray()
void
getBooleanArray(long offsetBytes, boolean[] dstArray, int dstOffsetBooleans, int lengthBooleans)
void
getByteArray(long offsetBytes, byte[] dstArray, int dstOffsetBytes, int lengthBytes)
void
getCharArray(long offsetBytes, char[] dstArray, int dstOffsetChars, int lengthChars)
int
getCharsFromUtf8(long offsetBytes, int utf8LengthBytes, Appendable dst)
int
getCharsFromUtf8(long offsetBytes, int utf8LengthBytes, StringBuilder dst)
void
getDoubleArray(long offsetBytes, double[] dstArray, int dstOffsetDoubles, int lengthDoubles)
void
getFloatArray(long offsetBytes, float[] dstArray, int dstOffsetFloats, int lengthFloats)
void
getIntArray(long offsetBytes, int[] dstArray, int dstOffsetInts, int lengthInts)
void
getLongArray(long offsetBytes, long[] dstArray, int dstOffsetLongs, int lengthLongs)
void
getShortArray(long offsetBytes, short[] dstArray, int dstOffsetShorts, int lengthShorts)
void
putBooleanArray(long offsetBytes, boolean[] srcArray, int srcOffsetBooleans, int lengthBooleans)
void
putByteArray(long offsetBytes, byte[] srcArray, int srcOffsetBytes, int lengthBytes)
void
putCharArray(long offsetBytes, char[] srcArray, int srcOffsetChars, int lengthChars)
long
putCharsToUtf8(long offsetBytes, CharSequence src)
void
putDoubleArray(long offsetBytes, double[] srcArray, int srcOffsetDoubles, int lengthDoubles)
void
putFloatArray(long offsetBytes, float[] srcArray, int srcOffsetFloats, int lengthFloats)
void
putIntArray(long offsetBytes, int[] srcArray, int srcOffsetInts, int lengthInts)
void
putLongArray(long offsetBytes, long[] srcArray, int srcOffsetLongs, int lengthLongs)
void
putShortArray(long offsetBytes, short[] srcArray, int srcOffsetShorts, int lengthShorts)
org.apache.datasketches.memory.Memory
region(long offsetBytes, long capacityBytes, ByteOrder byteOrder)
void
setBits(long offsetBytes, byte bitMask)
static SafeWritableMemory
wrap(byte[] bytes)
static SafeWritableMemory
wrap(ByteBuffer buffer)
static SafeWritableMemory
wrap(ByteBuffer buffer, int offset, int size)
static SafeWritableMemory
wrap(ByteBuffer buffer, ByteOrder byteOrder)
org.apache.datasketches.memory.WritableMemory
writableRegion(long offsetBytes, long capacityBytes, ByteOrder byteOrder)
void
writeTo(long offsetBytes, long lengthBytes, WritableByteChannel out)
-
Methods inherited from class org.apache.druid.segment.data.SafeWritableBase
checkValidAndBounds, getBoolean, getByte, getByteBuffer, getCapacity, getChar, getCumulativeOffset, getCumulativeOffset, getDouble, getFloat, getInt, getLong, getMemoryRequestServer, getRegionOffset, getRegionOffset, getShort, getTypeByteOrder, hasArray, hasByteBuffer, isByteOrderCompatible, isDirect, isReadOnly, isSameResource, isValid, putBoolean, putByte, putChar, putDouble, putFloat, putInt, putLong, putShort, toHexString, xxHash64, xxHash64
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.apache.datasketches.memory.BaseState
checkValidAndBounds, equals, getByteBuffer, getCapacity, getCumulativeOffset, getCumulativeOffset, getRegionOffset, getRegionOffset, getTypeByteOrder, hasArray, hasByteBuffer, hashCode, isByteOrderCompatible, isDirect, isReadOnly, isSameResource, isValid, toHexString, xxHash64, xxHash64
-
-
-
-
Constructor Detail
-
SafeWritableMemory
public SafeWritableMemory(ByteBuffer buffer)
-
-
Method Detail
-
wrap
public static SafeWritableMemory wrap(byte[] bytes)
-
wrap
public static SafeWritableMemory wrap(ByteBuffer buffer)
-
wrap
public static SafeWritableMemory wrap(ByteBuffer buffer, ByteOrder byteOrder)
-
wrap
public static SafeWritableMemory wrap(ByteBuffer buffer, int offset, int size)
-
region
public org.apache.datasketches.memory.Memory region(long offsetBytes, long capacityBytes, ByteOrder byteOrder)
- Specified by:
region
in interfaceorg.apache.datasketches.memory.Memory
-
asBuffer
public org.apache.datasketches.memory.Buffer asBuffer(ByteOrder byteOrder)
- Specified by:
asBuffer
in interfaceorg.apache.datasketches.memory.Memory
-
getBooleanArray
public void getBooleanArray(long offsetBytes, boolean[] dstArray, int dstOffsetBooleans, int lengthBooleans)
- Specified by:
getBooleanArray
in interfaceorg.apache.datasketches.memory.Memory
-
getByteArray
public void getByteArray(long offsetBytes, byte[] dstArray, int dstOffsetBytes, int lengthBytes)
- Specified by:
getByteArray
in interfaceorg.apache.datasketches.memory.Memory
-
getCharArray
public void getCharArray(long offsetBytes, char[] dstArray, int dstOffsetChars, int lengthChars)
- Specified by:
getCharArray
in interfaceorg.apache.datasketches.memory.Memory
-
getCharsFromUtf8
public int getCharsFromUtf8(long offsetBytes, int utf8LengthBytes, Appendable dst) throws IOException, org.apache.datasketches.memory.Utf8CodingException
- Specified by:
getCharsFromUtf8
in interfaceorg.apache.datasketches.memory.Memory
- Throws:
IOException
org.apache.datasketches.memory.Utf8CodingException
-
getCharsFromUtf8
public int getCharsFromUtf8(long offsetBytes, int utf8LengthBytes, StringBuilder dst) throws org.apache.datasketches.memory.Utf8CodingException
- Specified by:
getCharsFromUtf8
in interfaceorg.apache.datasketches.memory.Memory
- Throws:
org.apache.datasketches.memory.Utf8CodingException
-
getDoubleArray
public void getDoubleArray(long offsetBytes, double[] dstArray, int dstOffsetDoubles, int lengthDoubles)
- Specified by:
getDoubleArray
in interfaceorg.apache.datasketches.memory.Memory
-
getFloatArray
public void getFloatArray(long offsetBytes, float[] dstArray, int dstOffsetFloats, int lengthFloats)
- Specified by:
getFloatArray
in interfaceorg.apache.datasketches.memory.Memory
-
getIntArray
public void getIntArray(long offsetBytes, int[] dstArray, int dstOffsetInts, int lengthInts)
- Specified by:
getIntArray
in interfaceorg.apache.datasketches.memory.Memory
-
getLongArray
public void getLongArray(long offsetBytes, long[] dstArray, int dstOffsetLongs, int lengthLongs)
- Specified by:
getLongArray
in interfaceorg.apache.datasketches.memory.Memory
-
getShortArray
public void getShortArray(long offsetBytes, short[] dstArray, int dstOffsetShorts, int lengthShorts)
- Specified by:
getShortArray
in interfaceorg.apache.datasketches.memory.Memory
-
compareTo
public int compareTo(long thisOffsetBytes, long thisLengthBytes, org.apache.datasketches.memory.Memory that, long thatOffsetBytes, long thatLengthBytes)
- Specified by:
compareTo
in interfaceorg.apache.datasketches.memory.Memory
-
copyTo
public void copyTo(long srcOffsetBytes, org.apache.datasketches.memory.WritableMemory destination, long dstOffsetBytes, long lengthBytes)
- Specified by:
copyTo
in interfaceorg.apache.datasketches.memory.Memory
-
writeTo
public void writeTo(long offsetBytes, long lengthBytes, WritableByteChannel out) throws IOException
- Specified by:
writeTo
in interfaceorg.apache.datasketches.memory.Memory
- Throws:
IOException
-
equalTo
public boolean equalTo(long thisOffsetBytes, Object that, long thatOffsetBytes, long lengthBytes)
- Specified by:
equalTo
in interfaceorg.apache.datasketches.memory.BaseState
-
writableRegion
public org.apache.datasketches.memory.WritableMemory writableRegion(long offsetBytes, long capacityBytes, ByteOrder byteOrder)
- Specified by:
writableRegion
in interfaceorg.apache.datasketches.memory.WritableMemory
-
asWritableBuffer
public org.apache.datasketches.memory.WritableBuffer asWritableBuffer(ByteOrder byteOrder)
- Specified by:
asWritableBuffer
in interfaceorg.apache.datasketches.memory.WritableMemory
-
putBooleanArray
public void putBooleanArray(long offsetBytes, boolean[] srcArray, int srcOffsetBooleans, int lengthBooleans)
- Specified by:
putBooleanArray
in interfaceorg.apache.datasketches.memory.WritableMemory
-
putByteArray
public void putByteArray(long offsetBytes, byte[] srcArray, int srcOffsetBytes, int lengthBytes)
- Specified by:
putByteArray
in interfaceorg.apache.datasketches.memory.WritableMemory
-
putCharArray
public void putCharArray(long offsetBytes, char[] srcArray, int srcOffsetChars, int lengthChars)
- Specified by:
putCharArray
in interfaceorg.apache.datasketches.memory.WritableMemory
-
putCharsToUtf8
public long putCharsToUtf8(long offsetBytes, CharSequence src)
- Specified by:
putCharsToUtf8
in interfaceorg.apache.datasketches.memory.WritableMemory
-
putDoubleArray
public void putDoubleArray(long offsetBytes, double[] srcArray, int srcOffsetDoubles, int lengthDoubles)
- Specified by:
putDoubleArray
in interfaceorg.apache.datasketches.memory.WritableMemory
-
putFloatArray
public void putFloatArray(long offsetBytes, float[] srcArray, int srcOffsetFloats, int lengthFloats)
- Specified by:
putFloatArray
in interfaceorg.apache.datasketches.memory.WritableMemory
-
putIntArray
public void putIntArray(long offsetBytes, int[] srcArray, int srcOffsetInts, int lengthInts)
- Specified by:
putIntArray
in interfaceorg.apache.datasketches.memory.WritableMemory
-
putLongArray
public void putLongArray(long offsetBytes, long[] srcArray, int srcOffsetLongs, int lengthLongs)
- Specified by:
putLongArray
in interfaceorg.apache.datasketches.memory.WritableMemory
-
putShortArray
public void putShortArray(long offsetBytes, short[] srcArray, int srcOffsetShorts, int lengthShorts)
- Specified by:
putShortArray
in interfaceorg.apache.datasketches.memory.WritableMemory
-
getAndAddLong
public long getAndAddLong(long offsetBytes, long delta)
- Specified by:
getAndAddLong
in interfaceorg.apache.datasketches.memory.WritableMemory
-
compareAndSwapLong
public boolean compareAndSwapLong(long offsetBytes, long expect, long update)
- Specified by:
compareAndSwapLong
in interfaceorg.apache.datasketches.memory.WritableMemory
-
getAndSetLong
public long getAndSetLong(long offsetBytes, long newValue)
- Specified by:
getAndSetLong
in interfaceorg.apache.datasketches.memory.WritableMemory
-
getArray
public Object getArray()
- Specified by:
getArray
in interfaceorg.apache.datasketches.memory.WritableMemory
-
clear
public void clear()
- Specified by:
clear
in interfaceorg.apache.datasketches.memory.WritableMemory
-
clear
public void clear(long offsetBytes, long lengthBytes)
- Specified by:
clear
in interfaceorg.apache.datasketches.memory.WritableMemory
-
clearBits
public void clearBits(long offsetBytes, byte bitMask)
- Specified by:
clearBits
in interfaceorg.apache.datasketches.memory.WritableMemory
-
fill
public void fill(byte value)
- Specified by:
fill
in interfaceorg.apache.datasketches.memory.WritableMemory
-
fill
public void fill(long offsetBytes, long lengthBytes, byte value)
- Specified by:
fill
in interfaceorg.apache.datasketches.memory.WritableMemory
-
setBits
public void setBits(long offsetBytes, byte bitMask)
- Specified by:
setBits
in interfaceorg.apache.datasketches.memory.WritableMemory
-
-