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 aMemoryorWritableMemory? use this!Delegates everything to an underlying
ByteBufferso 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.BufferasBuffer(ByteOrder byteOrder)org.apache.datasketches.memory.WritableBufferasWritableBuffer(ByteOrder byteOrder)voidclear()voidclear(long offsetBytes, long lengthBytes)voidclearBits(long offsetBytes, byte bitMask)booleancompareAndSwapLong(long offsetBytes, long expect, long update)intcompareTo(long thisOffsetBytes, long thisLengthBytes, org.apache.datasketches.memory.Memory that, long thatOffsetBytes, long thatLengthBytes)voidcopyTo(long srcOffsetBytes, org.apache.datasketches.memory.WritableMemory destination, long dstOffsetBytes, long lengthBytes)booleanequalTo(long thisOffsetBytes, Object that, long thatOffsetBytes, long lengthBytes)voidfill(byte value)voidfill(long offsetBytes, long lengthBytes, byte value)longgetAndAddLong(long offsetBytes, long delta)longgetAndSetLong(long offsetBytes, long newValue)ObjectgetArray()voidgetBooleanArray(long offsetBytes, boolean[] dstArray, int dstOffsetBooleans, int lengthBooleans)voidgetByteArray(long offsetBytes, byte[] dstArray, int dstOffsetBytes, int lengthBytes)voidgetCharArray(long offsetBytes, char[] dstArray, int dstOffsetChars, int lengthChars)intgetCharsFromUtf8(long offsetBytes, int utf8LengthBytes, Appendable dst)intgetCharsFromUtf8(long offsetBytes, int utf8LengthBytes, StringBuilder dst)voidgetDoubleArray(long offsetBytes, double[] dstArray, int dstOffsetDoubles, int lengthDoubles)voidgetFloatArray(long offsetBytes, float[] dstArray, int dstOffsetFloats, int lengthFloats)voidgetIntArray(long offsetBytes, int[] dstArray, int dstOffsetInts, int lengthInts)voidgetLongArray(long offsetBytes, long[] dstArray, int dstOffsetLongs, int lengthLongs)voidgetShortArray(long offsetBytes, short[] dstArray, int dstOffsetShorts, int lengthShorts)voidputBooleanArray(long offsetBytes, boolean[] srcArray, int srcOffsetBooleans, int lengthBooleans)voidputByteArray(long offsetBytes, byte[] srcArray, int srcOffsetBytes, int lengthBytes)voidputCharArray(long offsetBytes, char[] srcArray, int srcOffsetChars, int lengthChars)longputCharsToUtf8(long offsetBytes, CharSequence src)voidputDoubleArray(long offsetBytes, double[] srcArray, int srcOffsetDoubles, int lengthDoubles)voidputFloatArray(long offsetBytes, float[] srcArray, int srcOffsetFloats, int lengthFloats)voidputIntArray(long offsetBytes, int[] srcArray, int srcOffsetInts, int lengthInts)voidputLongArray(long offsetBytes, long[] srcArray, int srcOffsetLongs, int lengthLongs)voidputShortArray(long offsetBytes, short[] srcArray, int srcOffsetShorts, int lengthShorts)org.apache.datasketches.memory.Memoryregion(long offsetBytes, long capacityBytes, ByteOrder byteOrder)voidsetBits(long offsetBytes, byte bitMask)static SafeWritableMemorywrap(byte[] bytes)static SafeWritableMemorywrap(ByteBuffer buffer)static SafeWritableMemorywrap(ByteBuffer buffer, int offset, int size)static SafeWritableMemorywrap(ByteBuffer buffer, ByteOrder byteOrder)org.apache.datasketches.memory.WritableMemorywritableRegion(long offsetBytes, long capacityBytes, ByteOrder byteOrder)voidwriteTo(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:
regionin interfaceorg.apache.datasketches.memory.Memory
-
asBuffer
public org.apache.datasketches.memory.Buffer asBuffer(ByteOrder byteOrder)
- Specified by:
asBufferin interfaceorg.apache.datasketches.memory.Memory
-
getBooleanArray
public void getBooleanArray(long offsetBytes, boolean[] dstArray, int dstOffsetBooleans, int lengthBooleans)- Specified by:
getBooleanArrayin interfaceorg.apache.datasketches.memory.Memory
-
getByteArray
public void getByteArray(long offsetBytes, byte[] dstArray, int dstOffsetBytes, int lengthBytes)- Specified by:
getByteArrayin interfaceorg.apache.datasketches.memory.Memory
-
getCharArray
public void getCharArray(long offsetBytes, char[] dstArray, int dstOffsetChars, int lengthChars)- Specified by:
getCharArrayin interfaceorg.apache.datasketches.memory.Memory
-
getCharsFromUtf8
public int getCharsFromUtf8(long offsetBytes, int utf8LengthBytes, Appendable dst) throws IOException, org.apache.datasketches.memory.Utf8CodingException- Specified by:
getCharsFromUtf8in interfaceorg.apache.datasketches.memory.Memory- Throws:
IOExceptionorg.apache.datasketches.memory.Utf8CodingException
-
getCharsFromUtf8
public int getCharsFromUtf8(long offsetBytes, int utf8LengthBytes, StringBuilder dst) throws org.apache.datasketches.memory.Utf8CodingException- Specified by:
getCharsFromUtf8in 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:
getDoubleArrayin interfaceorg.apache.datasketches.memory.Memory
-
getFloatArray
public void getFloatArray(long offsetBytes, float[] dstArray, int dstOffsetFloats, int lengthFloats)- Specified by:
getFloatArrayin interfaceorg.apache.datasketches.memory.Memory
-
getIntArray
public void getIntArray(long offsetBytes, int[] dstArray, int dstOffsetInts, int lengthInts)- Specified by:
getIntArrayin interfaceorg.apache.datasketches.memory.Memory
-
getLongArray
public void getLongArray(long offsetBytes, long[] dstArray, int dstOffsetLongs, int lengthLongs)- Specified by:
getLongArrayin interfaceorg.apache.datasketches.memory.Memory
-
getShortArray
public void getShortArray(long offsetBytes, short[] dstArray, int dstOffsetShorts, int lengthShorts)- Specified by:
getShortArrayin 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:
compareToin interfaceorg.apache.datasketches.memory.Memory
-
copyTo
public void copyTo(long srcOffsetBytes, org.apache.datasketches.memory.WritableMemory destination, long dstOffsetBytes, long lengthBytes)- Specified by:
copyToin interfaceorg.apache.datasketches.memory.Memory
-
writeTo
public void writeTo(long offsetBytes, long lengthBytes, WritableByteChannel out) throws IOException- Specified by:
writeToin interfaceorg.apache.datasketches.memory.Memory- Throws:
IOException
-
equalTo
public boolean equalTo(long thisOffsetBytes, Object that, long thatOffsetBytes, long lengthBytes)- Specified by:
equalToin interfaceorg.apache.datasketches.memory.BaseState
-
writableRegion
public org.apache.datasketches.memory.WritableMemory writableRegion(long offsetBytes, long capacityBytes, ByteOrder byteOrder)- Specified by:
writableRegionin interfaceorg.apache.datasketches.memory.WritableMemory
-
asWritableBuffer
public org.apache.datasketches.memory.WritableBuffer asWritableBuffer(ByteOrder byteOrder)
- Specified by:
asWritableBufferin interfaceorg.apache.datasketches.memory.WritableMemory
-
putBooleanArray
public void putBooleanArray(long offsetBytes, boolean[] srcArray, int srcOffsetBooleans, int lengthBooleans)- Specified by:
putBooleanArrayin interfaceorg.apache.datasketches.memory.WritableMemory
-
putByteArray
public void putByteArray(long offsetBytes, byte[] srcArray, int srcOffsetBytes, int lengthBytes)- Specified by:
putByteArrayin interfaceorg.apache.datasketches.memory.WritableMemory
-
putCharArray
public void putCharArray(long offsetBytes, char[] srcArray, int srcOffsetChars, int lengthChars)- Specified by:
putCharArrayin interfaceorg.apache.datasketches.memory.WritableMemory
-
putCharsToUtf8
public long putCharsToUtf8(long offsetBytes, CharSequence src)- Specified by:
putCharsToUtf8in interfaceorg.apache.datasketches.memory.WritableMemory
-
putDoubleArray
public void putDoubleArray(long offsetBytes, double[] srcArray, int srcOffsetDoubles, int lengthDoubles)- Specified by:
putDoubleArrayin interfaceorg.apache.datasketches.memory.WritableMemory
-
putFloatArray
public void putFloatArray(long offsetBytes, float[] srcArray, int srcOffsetFloats, int lengthFloats)- Specified by:
putFloatArrayin interfaceorg.apache.datasketches.memory.WritableMemory
-
putIntArray
public void putIntArray(long offsetBytes, int[] srcArray, int srcOffsetInts, int lengthInts)- Specified by:
putIntArrayin interfaceorg.apache.datasketches.memory.WritableMemory
-
putLongArray
public void putLongArray(long offsetBytes, long[] srcArray, int srcOffsetLongs, int lengthLongs)- Specified by:
putLongArrayin interfaceorg.apache.datasketches.memory.WritableMemory
-
putShortArray
public void putShortArray(long offsetBytes, short[] srcArray, int srcOffsetShorts, int lengthShorts)- Specified by:
putShortArrayin interfaceorg.apache.datasketches.memory.WritableMemory
-
getAndAddLong
public long getAndAddLong(long offsetBytes, long delta)- Specified by:
getAndAddLongin interfaceorg.apache.datasketches.memory.WritableMemory
-
compareAndSwapLong
public boolean compareAndSwapLong(long offsetBytes, long expect, long update)- Specified by:
compareAndSwapLongin interfaceorg.apache.datasketches.memory.WritableMemory
-
getAndSetLong
public long getAndSetLong(long offsetBytes, long newValue)- Specified by:
getAndSetLongin interfaceorg.apache.datasketches.memory.WritableMemory
-
getArray
public Object getArray()
- Specified by:
getArrayin interfaceorg.apache.datasketches.memory.WritableMemory
-
clear
public void clear()
- Specified by:
clearin interfaceorg.apache.datasketches.memory.WritableMemory
-
clear
public void clear(long offsetBytes, long lengthBytes)- Specified by:
clearin interfaceorg.apache.datasketches.memory.WritableMemory
-
clearBits
public void clearBits(long offsetBytes, byte bitMask)- Specified by:
clearBitsin interfaceorg.apache.datasketches.memory.WritableMemory
-
fill
public void fill(byte value)
- Specified by:
fillin interfaceorg.apache.datasketches.memory.WritableMemory
-
fill
public void fill(long offsetBytes, long lengthBytes, byte value)- Specified by:
fillin interfaceorg.apache.datasketches.memory.WritableMemory
-
setBits
public void setBits(long offsetBytes, byte bitMask)- Specified by:
setBitsin interfaceorg.apache.datasketches.memory.WritableMemory
-
-