Class 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 a Memory or WritableMemory? 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 Detail

      • SafeWritableMemory

        public SafeWritableMemory​(ByteBuffer buffer)
    • Method Detail

      • region

        public org.apache.datasketches.memory.Memory region​(long offsetBytes,
                                                            long capacityBytes,
                                                            ByteOrder byteOrder)
        Specified by:
        region in interface org.apache.datasketches.memory.Memory
      • asBuffer

        public org.apache.datasketches.memory.Buffer asBuffer​(ByteOrder byteOrder)
        Specified by:
        asBuffer in interface org.apache.datasketches.memory.Memory
      • getBooleanArray

        public void getBooleanArray​(long offsetBytes,
                                    boolean[] dstArray,
                                    int dstOffsetBooleans,
                                    int lengthBooleans)
        Specified by:
        getBooleanArray in interface org.apache.datasketches.memory.Memory
      • getByteArray

        public void getByteArray​(long offsetBytes,
                                 byte[] dstArray,
                                 int dstOffsetBytes,
                                 int lengthBytes)
        Specified by:
        getByteArray in interface org.apache.datasketches.memory.Memory
      • getCharArray

        public void getCharArray​(long offsetBytes,
                                 char[] dstArray,
                                 int dstOffsetChars,
                                 int lengthChars)
        Specified by:
        getCharArray in interface org.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 interface org.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 interface org.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 interface org.apache.datasketches.memory.Memory
      • getFloatArray

        public void getFloatArray​(long offsetBytes,
                                  float[] dstArray,
                                  int dstOffsetFloats,
                                  int lengthFloats)
        Specified by:
        getFloatArray in interface org.apache.datasketches.memory.Memory
      • getIntArray

        public void getIntArray​(long offsetBytes,
                                int[] dstArray,
                                int dstOffsetInts,
                                int lengthInts)
        Specified by:
        getIntArray in interface org.apache.datasketches.memory.Memory
      • getLongArray

        public void getLongArray​(long offsetBytes,
                                 long[] dstArray,
                                 int dstOffsetLongs,
                                 int lengthLongs)
        Specified by:
        getLongArray in interface org.apache.datasketches.memory.Memory
      • getShortArray

        public void getShortArray​(long offsetBytes,
                                  short[] dstArray,
                                  int dstOffsetShorts,
                                  int lengthShorts)
        Specified by:
        getShortArray in interface org.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 interface org.apache.datasketches.memory.Memory
      • copyTo

        public void copyTo​(long srcOffsetBytes,
                           org.apache.datasketches.memory.WritableMemory destination,
                           long dstOffsetBytes,
                           long lengthBytes)
        Specified by:
        copyTo in interface org.apache.datasketches.memory.Memory
      • writeTo

        public void writeTo​(long offsetBytes,
                            long lengthBytes,
                            WritableByteChannel out)
                     throws IOException
        Specified by:
        writeTo in interface org.apache.datasketches.memory.Memory
        Throws:
        IOException
      • equalTo

        public boolean equalTo​(long thisOffsetBytes,
                               Object that,
                               long thatOffsetBytes,
                               long lengthBytes)
        Specified by:
        equalTo in interface org.apache.datasketches.memory.BaseState
      • writableRegion

        public org.apache.datasketches.memory.WritableMemory writableRegion​(long offsetBytes,
                                                                            long capacityBytes,
                                                                            ByteOrder byteOrder)
        Specified by:
        writableRegion in interface org.apache.datasketches.memory.WritableMemory
      • asWritableBuffer

        public org.apache.datasketches.memory.WritableBuffer asWritableBuffer​(ByteOrder byteOrder)
        Specified by:
        asWritableBuffer in interface org.apache.datasketches.memory.WritableMemory
      • putBooleanArray

        public void putBooleanArray​(long offsetBytes,
                                    boolean[] srcArray,
                                    int srcOffsetBooleans,
                                    int lengthBooleans)
        Specified by:
        putBooleanArray in interface org.apache.datasketches.memory.WritableMemory
      • putByteArray

        public void putByteArray​(long offsetBytes,
                                 byte[] srcArray,
                                 int srcOffsetBytes,
                                 int lengthBytes)
        Specified by:
        putByteArray in interface org.apache.datasketches.memory.WritableMemory
      • putCharArray

        public void putCharArray​(long offsetBytes,
                                 char[] srcArray,
                                 int srcOffsetChars,
                                 int lengthChars)
        Specified by:
        putCharArray in interface org.apache.datasketches.memory.WritableMemory
      • putCharsToUtf8

        public long putCharsToUtf8​(long offsetBytes,
                                   CharSequence src)
        Specified by:
        putCharsToUtf8 in interface org.apache.datasketches.memory.WritableMemory
      • putDoubleArray

        public void putDoubleArray​(long offsetBytes,
                                   double[] srcArray,
                                   int srcOffsetDoubles,
                                   int lengthDoubles)
        Specified by:
        putDoubleArray in interface org.apache.datasketches.memory.WritableMemory
      • putFloatArray

        public void putFloatArray​(long offsetBytes,
                                  float[] srcArray,
                                  int srcOffsetFloats,
                                  int lengthFloats)
        Specified by:
        putFloatArray in interface org.apache.datasketches.memory.WritableMemory
      • putIntArray

        public void putIntArray​(long offsetBytes,
                                int[] srcArray,
                                int srcOffsetInts,
                                int lengthInts)
        Specified by:
        putIntArray in interface org.apache.datasketches.memory.WritableMemory
      • putLongArray

        public void putLongArray​(long offsetBytes,
                                 long[] srcArray,
                                 int srcOffsetLongs,
                                 int lengthLongs)
        Specified by:
        putLongArray in interface org.apache.datasketches.memory.WritableMemory
      • putShortArray

        public void putShortArray​(long offsetBytes,
                                  short[] srcArray,
                                  int srcOffsetShorts,
                                  int lengthShorts)
        Specified by:
        putShortArray in interface org.apache.datasketches.memory.WritableMemory
      • getAndAddLong

        public long getAndAddLong​(long offsetBytes,
                                  long delta)
        Specified by:
        getAndAddLong in interface org.apache.datasketches.memory.WritableMemory
      • compareAndSwapLong

        public boolean compareAndSwapLong​(long offsetBytes,
                                          long expect,
                                          long update)
        Specified by:
        compareAndSwapLong in interface org.apache.datasketches.memory.WritableMemory
      • getAndSetLong

        public long getAndSetLong​(long offsetBytes,
                                  long newValue)
        Specified by:
        getAndSetLong in interface org.apache.datasketches.memory.WritableMemory
      • getArray

        public Object getArray()
        Specified by:
        getArray in interface org.apache.datasketches.memory.WritableMemory
      • clear

        public void clear()
        Specified by:
        clear in interface org.apache.datasketches.memory.WritableMemory
      • clear

        public void clear​(long offsetBytes,
                          long lengthBytes)
        Specified by:
        clear in interface org.apache.datasketches.memory.WritableMemory
      • clearBits

        public void clearBits​(long offsetBytes,
                              byte bitMask)
        Specified by:
        clearBits in interface org.apache.datasketches.memory.WritableMemory
      • fill

        public void fill​(byte value)
        Specified by:
        fill in interface org.apache.datasketches.memory.WritableMemory
      • fill

        public void fill​(long offsetBytes,
                         long lengthBytes,
                         byte value)
        Specified by:
        fill in interface org.apache.datasketches.memory.WritableMemory
      • setBits

        public void setBits​(long offsetBytes,
                            byte bitMask)
        Specified by:
        setBits in interface org.apache.datasketches.memory.WritableMemory