Class ByteBufferAccessor

  • All Implemented Interfaces:
    ValueAccessor<java.nio.ByteBuffer>

    public class ByteBufferAccessor
    extends java.lang.Object
    implements ValueAccessor<java.nio.ByteBuffer>
    Accessor for ByteBuffer values. ByteBufferAccessor treates Buffer.position() as index 0, and Buffer.remaining() as the length.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static ValueAccessor<java.nio.ByteBuffer> instance  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.nio.ByteBuffer allocate​(int size)
      Allocate and return a {@param } instance of {@param size} bytes on the heap.
      <V2> int compare​(java.nio.ByteBuffer left, V2 right, ValueAccessor<V2> accessorR)
      lexicographically compare {@param left} to {@param right}
      int compareByteArrayTo​(byte[] left, java.nio.ByteBuffer right)
      compare a byte array on the left with a {@param } on the right}
      int compareByteBufferTo​(java.nio.ByteBuffer left, java.nio.ByteBuffer right)
      compare a byte buffer on the left with a {@param } on the right}
      <V2> java.nio.ByteBuffer convert​(V2 src, ValueAccessor<V2> accessor)
      Convert the data in {@param src} to {@param } {@param src} and the returned value may share a common byte array instance, so caller should assume that modifying the returned value will also modify the contents of {@param src}
      int copyByteArrayTo​(byte[] src, int srcOffset, java.nio.ByteBuffer dst, int dstOffset, int size)
      copies a byte array into this accessors value.
      int copyByteBufferTo​(java.nio.ByteBuffer src, int srcOffset, java.nio.ByteBuffer dst, int dstOffset, int size)
      copies a byte buffer into this accessors value.
      <V2> int copyTo​(java.nio.ByteBuffer src, int srcOffset, V2 dst, ValueAccessor<V2> dstAccessor, int dstOffset, int size)
      copy the {@param size} bytes from the {@param src} value, starting at the offset {@param srcOffset} into the {@param dst} value, starting at the offset {@param dstOffset}, using the accessor {@param dstAccessor}
      java.nio.ByteBuffer[] createArray​(int length)
      allocate an instance of the accessors backing type
      void digest​(java.nio.ByteBuffer value, int offset, int size, Digest digest)
      updates {@param digest} with {@param size} bytes from the contents of {@param value} starting at offset {@param offset}
      java.nio.ByteBuffer empty()
      return a value with a length of 0
      ValueAccessor.ObjectFactory<java.nio.ByteBuffer> factory()
      returns the ValueAccessor.ObjectFactory for the backing type {@param }
      byte getByte​(java.nio.ByteBuffer value, int offset)
      returns a byte from offset {@param offset}
      double getDouble​(java.nio.ByteBuffer value, int offset)  
      float getFloat​(java.nio.ByteBuffer value, int offset)  
      int getInt​(java.nio.ByteBuffer value, int offset)
      returns an int from offset {@param offset}
      long getLong​(java.nio.ByteBuffer value, int offset)
      returns a long from offset {@param offset}
      short getShort​(java.nio.ByteBuffer value, int offset)
      returns a short from offset {@param offset}
      int getUnsignedShort​(java.nio.ByteBuffer value, int offset)
      returns an unsigned short from offset {@param offset}
      int putByte​(java.nio.ByteBuffer dst, int offset, byte value)
      writes the byte value {@param value} to {@param dst} at offset {@param offset}
      int putFloat​(java.nio.ByteBuffer dst, int offset, float value)
      writes the float value {@param value} to {@param dst} at offset {@param offset}
      int putInt​(java.nio.ByteBuffer dst, int offset, int value)
      writes the int value {@param value} to {@param dst} at offset {@param offset}
      int putLong​(java.nio.ByteBuffer dst, int offset, long value)
      writes the long value {@param value} to {@param dst} at offset {@param offset}
      int putShort​(java.nio.ByteBuffer dst, int offset, short value)
      writes the short value {@param value} to {@param dst} at offset {@param offset}
      java.nio.ByteBuffer read​(DataInputPlus in, int length)
      Reads a value of {@param length} bytes from {@param in}
      int size​(java.nio.ByteBuffer value)  
      java.nio.ByteBuffer slice​(java.nio.ByteBuffer input, int offset, int length)
      Returns a value with the contents of {@param input} from {@param offset} to {@param length}.
      byte[] toArray​(java.nio.ByteBuffer value)
      returns a byte[] with the contents of {@param value} Depending on the accessor implementation, this method may: * allocate a new byte[] object and copy data into it * return the value, if the backing type is byte[]
      byte[] toArray​(java.nio.ByteBuffer value, int offset, int length)
      returns a byte[] with {@param length} bytes copied from the contents of {@param value} starting at offset {@param offset}.
      Ballot toBallot​(java.nio.ByteBuffer value)
      returns a TimeUUID from offset 0
      java.nio.ByteBuffer toBuffer​(java.nio.ByteBuffer value)
      returns a ByteBuffer with the contents of {@param value} Depending on the accessor implementation, this method may: * allocate a new ByteBuffer and copy data into it * return the value, if the backing type is a bytebuffer
      byte toByte​(java.nio.ByteBuffer value)
      returns a byte from offset 0
      double toDouble​(java.nio.ByteBuffer value)
      returns a double from offset 0
      float toFloat​(java.nio.ByteBuffer value)
      returns a float from offset 0
      float[] toFloatArray​(java.nio.ByteBuffer value, int dimension)
      returns a float[] from offset 0
      java.lang.String toHex​(java.nio.ByteBuffer value)  
      int toInt​(java.nio.ByteBuffer value)
      returns an int from offset 0
      long toLong​(java.nio.ByteBuffer value)
      returns a long from offset 0
      short toShort​(java.nio.ByteBuffer value)
      returns a short from offset 0
      java.lang.String toString​(java.nio.ByteBuffer value, java.nio.charset.Charset charset)  
      TimeUUID toTimeUUID​(java.nio.ByteBuffer value)
      returns a TimeUUID from offset 0
      java.util.UUID toUUID​(java.nio.ByteBuffer value)
      returns a UUID from offset 0
      java.nio.ByteBuffer valueOf​(boolean v)
      return a value with the bytes from {@param v}
      java.nio.ByteBuffer valueOf​(byte v)
      return a value with the bytes from {@param v}
      java.nio.ByteBuffer valueOf​(byte[] bytes)
      return a value containing the {@param bytes} Caller should assume that modifying the returned value will also modify the contents of {@param bytes}
      java.nio.ByteBuffer valueOf​(double v)
      return a value with the bytes from {@param v}
      java.nio.ByteBuffer valueOf​(float v)
      return a value with the bytes from {@param v}
      java.nio.ByteBuffer valueOf​(int v)
      return a value with the bytes from {@param v}
      java.nio.ByteBuffer valueOf​(long v)
      return a value with the bytes from {@param v}
      java.nio.ByteBuffer valueOf​(short v)
      return a value with the bytes from {@param v}
      java.nio.ByteBuffer valueOf​(java.lang.String v, java.nio.charset.Charset charset)
      return a value containing the bytes for the given string and charset
      java.nio.ByteBuffer valueOf​(java.nio.ByteBuffer bytes)
      return a value containing the {@param bytes} {@param src} and the returned value may share a common byte array instance, so caller should assume that modifying the returned value will also modify the contents of {@param src}
      java.nio.ByteBuffer valueOf​(java.util.UUID v)
      return a value with the bytes from {@param v}
      void write​(java.nio.ByteBuffer value, java.nio.ByteBuffer out)
      Write the contents of the given value into the ByteBuffer
      void write​(java.nio.ByteBuffer value, DataOutputPlus out)
      Write the contents of the given value into the a DataOutputPlus
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • instance

        public static final ValueAccessor<java.nio.ByteBuffer> instance
    • Method Detail

      • size

        public int size​(java.nio.ByteBuffer value)
        Specified by:
        size in interface ValueAccessor<java.nio.ByteBuffer>
        Returns:
        the size of the given value
      • createArray

        public java.nio.ByteBuffer[] createArray​(int length)
        Description copied from interface: ValueAccessor
        allocate an instance of the accessors backing type
        Specified by:
        createArray in interface ValueAccessor<java.nio.ByteBuffer>
        Parameters:
        length - size of backing typ to allocate
      • write

        public void write​(java.nio.ByteBuffer value,
                          DataOutputPlus out)
                   throws java.io.IOException
        Description copied from interface: ValueAccessor
        Write the contents of the given value into the a DataOutputPlus
        Specified by:
        write in interface ValueAccessor<java.nio.ByteBuffer>
        Throws:
        java.io.IOException
      • write

        public void write​(java.nio.ByteBuffer value,
                          java.nio.ByteBuffer out)
        Description copied from interface: ValueAccessor
        Write the contents of the given value into the ByteBuffer
        Specified by:
        write in interface ValueAccessor<java.nio.ByteBuffer>
      • copyTo

        public <V2> int copyTo​(java.nio.ByteBuffer src,
                               int srcOffset,
                               V2 dst,
                               ValueAccessor<V2> dstAccessor,
                               int dstOffset,
                               int size)
        Description copied from interface: ValueAccessor
        copy the {@param size} bytes from the {@param src} value, starting at the offset {@param srcOffset} into the {@param dst} value, starting at the offset {@param dstOffset}, using the accessor {@param dstAccessor}
        Specified by:
        copyTo in interface ValueAccessor<java.nio.ByteBuffer>
        Type Parameters:
        V2 - the destination value type
        Returns:
        the number of bytes copied ({@param size})
      • copyByteArrayTo

        public int copyByteArrayTo​(byte[] src,
                                   int srcOffset,
                                   java.nio.ByteBuffer dst,
                                   int dstOffset,
                                   int size)
        Description copied from interface: ValueAccessor
        copies a byte array into this accessors value.
        Specified by:
        copyByteArrayTo in interface ValueAccessor<java.nio.ByteBuffer>
      • copyByteBufferTo

        public int copyByteBufferTo​(java.nio.ByteBuffer src,
                                    int srcOffset,
                                    java.nio.ByteBuffer dst,
                                    int dstOffset,
                                    int size)
        Description copied from interface: ValueAccessor
        copies a byte buffer into this accessors value.
        Specified by:
        copyByteBufferTo in interface ValueAccessor<java.nio.ByteBuffer>
      • digest

        public void digest​(java.nio.ByteBuffer value,
                           int offset,
                           int size,
                           Digest digest)
        Description copied from interface: ValueAccessor
        updates {@param digest} with {@param size} bytes from the contents of {@param value} starting at offset {@param offset}
        Specified by:
        digest in interface ValueAccessor<java.nio.ByteBuffer>
      • read

        public java.nio.ByteBuffer read​(DataInputPlus in,
                                        int length)
                                 throws java.io.IOException
        Description copied from interface: ValueAccessor
        Reads a value of {@param length} bytes from {@param in}
        Specified by:
        read in interface ValueAccessor<java.nio.ByteBuffer>
        Throws:
        java.io.IOException
      • slice

        public java.nio.ByteBuffer slice​(java.nio.ByteBuffer input,
                                         int offset,
                                         int length)
        Description copied from interface: ValueAccessor
        Returns a value with the contents of {@param input} from {@param offset} to {@param length}. Depending on the accessor implementation, this method may: * allocate a new {@param } object of {@param length}, and copy data into it * return a view of {@param input} where changes to one will be reflected in the other
        Specified by:
        slice in interface ValueAccessor<java.nio.ByteBuffer>
      • compare

        public <V2> int compare​(java.nio.ByteBuffer left,
                                V2 right,
                                ValueAccessor<V2> accessorR)
        Description copied from interface: ValueAccessor
        lexicographically compare {@param left} to {@param right}
        Specified by:
        compare in interface ValueAccessor<java.nio.ByteBuffer>
        Type Parameters:
        V2 - backing type of
      • compareByteArrayTo

        public int compareByteArrayTo​(byte[] left,
                                      java.nio.ByteBuffer right)
        Description copied from interface: ValueAccessor
        compare a byte array on the left with a {@param } on the right}
        Specified by:
        compareByteArrayTo in interface ValueAccessor<java.nio.ByteBuffer>
      • compareByteBufferTo

        public int compareByteBufferTo​(java.nio.ByteBuffer left,
                                       java.nio.ByteBuffer right)
        Description copied from interface: ValueAccessor
        compare a byte buffer on the left with a {@param } on the right}
        Specified by:
        compareByteBufferTo in interface ValueAccessor<java.nio.ByteBuffer>
      • toBuffer

        public java.nio.ByteBuffer toBuffer​(java.nio.ByteBuffer value)
        Description copied from interface: ValueAccessor
        returns a ByteBuffer with the contents of {@param value} Depending on the accessor implementation, this method may: * allocate a new ByteBuffer and copy data into it * return the value, if the backing type is a bytebuffer
        Specified by:
        toBuffer in interface ValueAccessor<java.nio.ByteBuffer>
      • toArray

        public byte[] toArray​(java.nio.ByteBuffer value)
        Description copied from interface: ValueAccessor
        returns a byte[] with the contents of {@param value} Depending on the accessor implementation, this method may: * allocate a new byte[] object and copy data into it * return the value, if the backing type is byte[]
        Specified by:
        toArray in interface ValueAccessor<java.nio.ByteBuffer>
      • toArray

        public byte[] toArray​(java.nio.ByteBuffer value,
                              int offset,
                              int length)
        Description copied from interface: ValueAccessor
        returns a byte[] with {@param length} bytes copied from the contents of {@param value} starting at offset {@param offset}. Depending on the accessor implementation, this method may: * allocate a new byte[] object and copy data into it * return the value, if the backing type is byte[], offset is 0 and {@param length} == size(value)
        Specified by:
        toArray in interface ValueAccessor<java.nio.ByteBuffer>
      • toString

        public java.lang.String toString​(java.nio.ByteBuffer value,
                                         java.nio.charset.Charset charset)
                                  throws java.nio.charset.CharacterCodingException
        Specified by:
        toString in interface ValueAccessor<java.nio.ByteBuffer>
        Throws:
        java.nio.charset.CharacterCodingException
      • valueOf

        public java.nio.ByteBuffer valueOf​(java.util.UUID v)
        Description copied from interface: ValueAccessor
        return a value with the bytes from {@param v}
        Specified by:
        valueOf in interface ValueAccessor<java.nio.ByteBuffer>
      • toHex

        public java.lang.String toHex​(java.nio.ByteBuffer value)
        Specified by:
        toHex in interface ValueAccessor<java.nio.ByteBuffer>
      • toByte

        public byte toByte​(java.nio.ByteBuffer value)
        Description copied from interface: ValueAccessor
        returns a byte from offset 0
        Specified by:
        toByte in interface ValueAccessor<java.nio.ByteBuffer>
      • getByte

        public byte getByte​(java.nio.ByteBuffer value,
                            int offset)
        Description copied from interface: ValueAccessor
        returns a byte from offset {@param offset}
        Specified by:
        getByte in interface ValueAccessor<java.nio.ByteBuffer>
      • toShort

        public short toShort​(java.nio.ByteBuffer value)
        Description copied from interface: ValueAccessor
        returns a short from offset 0
        Specified by:
        toShort in interface ValueAccessor<java.nio.ByteBuffer>
      • getShort

        public short getShort​(java.nio.ByteBuffer value,
                              int offset)
        Description copied from interface: ValueAccessor
        returns a short from offset {@param offset}
        Specified by:
        getShort in interface ValueAccessor<java.nio.ByteBuffer>
      • getUnsignedShort

        public int getUnsignedShort​(java.nio.ByteBuffer value,
                                    int offset)
        Description copied from interface: ValueAccessor
        returns an unsigned short from offset {@param offset}
        Specified by:
        getUnsignedShort in interface ValueAccessor<java.nio.ByteBuffer>
      • toInt

        public int toInt​(java.nio.ByteBuffer value)
        Description copied from interface: ValueAccessor
        returns an int from offset 0
        Specified by:
        toInt in interface ValueAccessor<java.nio.ByteBuffer>
      • getInt

        public int getInt​(java.nio.ByteBuffer value,
                          int offset)
        Description copied from interface: ValueAccessor
        returns an int from offset {@param offset}
        Specified by:
        getInt in interface ValueAccessor<java.nio.ByteBuffer>
      • getFloat

        public float getFloat​(java.nio.ByteBuffer value,
                              int offset)
        Specified by:
        getFloat in interface ValueAccessor<java.nio.ByteBuffer>
      • getDouble

        public double getDouble​(java.nio.ByteBuffer value,
                                int offset)
        Specified by:
        getDouble in interface ValueAccessor<java.nio.ByteBuffer>
      • toLong

        public long toLong​(java.nio.ByteBuffer value)
        Description copied from interface: ValueAccessor
        returns a long from offset 0
        Specified by:
        toLong in interface ValueAccessor<java.nio.ByteBuffer>
      • getLong

        public long getLong​(java.nio.ByteBuffer value,
                            int offset)
        Description copied from interface: ValueAccessor
        returns a long from offset {@param offset}
        Specified by:
        getLong in interface ValueAccessor<java.nio.ByteBuffer>
      • toFloat

        public float toFloat​(java.nio.ByteBuffer value)
        Description copied from interface: ValueAccessor
        returns a float from offset 0
        Specified by:
        toFloat in interface ValueAccessor<java.nio.ByteBuffer>
      • toFloatArray

        public float[] toFloatArray​(java.nio.ByteBuffer value,
                                    int dimension)
        Description copied from interface: ValueAccessor
        returns a float[] from offset 0
        Specified by:
        toFloatArray in interface ValueAccessor<java.nio.ByteBuffer>
      • toDouble

        public double toDouble​(java.nio.ByteBuffer value)
        Description copied from interface: ValueAccessor
        returns a double from offset 0
        Specified by:
        toDouble in interface ValueAccessor<java.nio.ByteBuffer>
      • toUUID

        public java.util.UUID toUUID​(java.nio.ByteBuffer value)
        Description copied from interface: ValueAccessor
        returns a UUID from offset 0
        Specified by:
        toUUID in interface ValueAccessor<java.nio.ByteBuffer>
      • toTimeUUID

        public TimeUUID toTimeUUID​(java.nio.ByteBuffer value)
        Description copied from interface: ValueAccessor
        returns a TimeUUID from offset 0
        Specified by:
        toTimeUUID in interface ValueAccessor<java.nio.ByteBuffer>
      • toBallot

        public Ballot toBallot​(java.nio.ByteBuffer value)
        Description copied from interface: ValueAccessor
        returns a TimeUUID from offset 0
        Specified by:
        toBallot in interface ValueAccessor<java.nio.ByteBuffer>
      • putByte

        public int putByte​(java.nio.ByteBuffer dst,
                           int offset,
                           byte value)
        Description copied from interface: ValueAccessor
        writes the byte value {@param value} to {@param dst} at offset {@param offset}
        Specified by:
        putByte in interface ValueAccessor<java.nio.ByteBuffer>
        Returns:
        the number of bytes written to {@param value}
      • putShort

        public int putShort​(java.nio.ByteBuffer dst,
                            int offset,
                            short value)
        Description copied from interface: ValueAccessor
        writes the short value {@param value} to {@param dst} at offset {@param offset}
        Specified by:
        putShort in interface ValueAccessor<java.nio.ByteBuffer>
        Returns:
        the number of bytes written to {@param value}
      • putInt

        public int putInt​(java.nio.ByteBuffer dst,
                          int offset,
                          int value)
        Description copied from interface: ValueAccessor
        writes the int value {@param value} to {@param dst} at offset {@param offset}
        Specified by:
        putInt in interface ValueAccessor<java.nio.ByteBuffer>
        Returns:
        the number of bytes written to {@param value}
      • putLong

        public int putLong​(java.nio.ByteBuffer dst,
                           int offset,
                           long value)
        Description copied from interface: ValueAccessor
        writes the long value {@param value} to {@param dst} at offset {@param offset}
        Specified by:
        putLong in interface ValueAccessor<java.nio.ByteBuffer>
        Returns:
        the number of bytes written to {@param value}
      • putFloat

        public int putFloat​(java.nio.ByteBuffer dst,
                            int offset,
                            float value)
        Description copied from interface: ValueAccessor
        writes the float value {@param value} to {@param dst} at offset {@param offset}
        Specified by:
        putFloat in interface ValueAccessor<java.nio.ByteBuffer>
        Returns:
        the number of bytes written to {@param value}
      • empty

        public java.nio.ByteBuffer empty()
        Description copied from interface: ValueAccessor
        return a value with a length of 0
        Specified by:
        empty in interface ValueAccessor<java.nio.ByteBuffer>
      • valueOf

        public java.nio.ByteBuffer valueOf​(byte[] bytes)
        Description copied from interface: ValueAccessor
        return a value containing the {@param bytes} Caller should assume that modifying the returned value will also modify the contents of {@param bytes}
        Specified by:
        valueOf in interface ValueAccessor<java.nio.ByteBuffer>
      • valueOf

        public java.nio.ByteBuffer valueOf​(java.nio.ByteBuffer bytes)
        Description copied from interface: ValueAccessor
        return a value containing the {@param bytes} {@param src} and the returned value may share a common byte array instance, so caller should assume that modifying the returned value will also modify the contents of {@param src}
        Specified by:
        valueOf in interface ValueAccessor<java.nio.ByteBuffer>
      • valueOf

        public java.nio.ByteBuffer valueOf​(java.lang.String v,
                                           java.nio.charset.Charset charset)
        Description copied from interface: ValueAccessor
        return a value containing the bytes for the given string and charset
        Specified by:
        valueOf in interface ValueAccessor<java.nio.ByteBuffer>
      • valueOf

        public java.nio.ByteBuffer valueOf​(boolean v)
        Description copied from interface: ValueAccessor
        return a value with the bytes from {@param v}
        Specified by:
        valueOf in interface ValueAccessor<java.nio.ByteBuffer>
      • valueOf

        public java.nio.ByteBuffer valueOf​(byte v)
        Description copied from interface: ValueAccessor
        return a value with the bytes from {@param v}
        Specified by:
        valueOf in interface ValueAccessor<java.nio.ByteBuffer>
      • valueOf

        public java.nio.ByteBuffer valueOf​(short v)
        Description copied from interface: ValueAccessor
        return a value with the bytes from {@param v}
        Specified by:
        valueOf in interface ValueAccessor<java.nio.ByteBuffer>
      • valueOf

        public java.nio.ByteBuffer valueOf​(int v)
        Description copied from interface: ValueAccessor
        return a value with the bytes from {@param v}
        Specified by:
        valueOf in interface ValueAccessor<java.nio.ByteBuffer>
      • valueOf

        public java.nio.ByteBuffer valueOf​(long v)
        Description copied from interface: ValueAccessor
        return a value with the bytes from {@param v}
        Specified by:
        valueOf in interface ValueAccessor<java.nio.ByteBuffer>
      • valueOf

        public java.nio.ByteBuffer valueOf​(float v)
        Description copied from interface: ValueAccessor
        return a value with the bytes from {@param v}
        Specified by:
        valueOf in interface ValueAccessor<java.nio.ByteBuffer>
      • valueOf

        public java.nio.ByteBuffer valueOf​(double v)
        Description copied from interface: ValueAccessor
        return a value with the bytes from {@param v}
        Specified by:
        valueOf in interface ValueAccessor<java.nio.ByteBuffer>
      • convert

        public <V2> java.nio.ByteBuffer convert​(V2 src,
                                                ValueAccessor<V2> accessor)
        Description copied from interface: ValueAccessor
        Convert the data in {@param src} to {@param } {@param src} and the returned value may share a common byte array instance, so caller should assume that modifying the returned value will also modify the contents of {@param src}
        Specified by:
        convert in interface ValueAccessor<java.nio.ByteBuffer>
      • allocate

        public java.nio.ByteBuffer allocate​(int size)
        Description copied from interface: ValueAccessor
        Allocate and return a {@param } instance of {@param size} bytes on the heap.
        Specified by:
        allocate in interface ValueAccessor<java.nio.ByteBuffer>