Class ByteBuffersDataInput

    • Constructor Summary

      Constructors 
      Constructor Description
      ByteBuffersDataInput​(java.util.List<java.nio.ByteBuffer> buffers)
      Read data from a set of contiguous buffers.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      private int blockIndex​(long pos)  
      private int blockOffset​(long pos)  
      private int blockSize()  
      (package private) static int determineBlockPage​(java.util.List<java.nio.ByteBuffer> buffers)  
      private static void ensureAssumptions​(java.util.List<java.nio.ByteBuffer> buffers)  
      private java.nio.FloatBuffer getFloatBuffer​(long pos)  
      private java.nio.LongBuffer getLongBuffer​(long pos)  
      private static boolean isPowerOfTwo​(int v)  
      long length()
      The number of bytes in the file.
      long position()  
      long ramBytesUsed()
      Return the memory usage of this object in bytes.
      byte readByte()
      Reads and returns a single byte.
      byte readByte​(long pos)
      Reads a byte at the given position in the file
      void readBytes​(byte[] arr, int off, int len)
      Reads a specified number of bytes into an array at the specified offset.
      void readBytes​(java.nio.ByteBuffer buffer, int len)
      Reads exactly len bytes into the given buffer.
      void readFloats​(float[] arr, int off, int len)
      Reads a specified number of floats into an array at the specified offset.
      protected void readGroupVInt​(long[] dst, int offset)
      Override if you have a efficient implementation.
      int readInt()
      Reads four bytes and returns an int (LE byte order).
      int readInt​(long pos)
      Reads an integer (LE byte order) at the given position in the file
      long readLong()
      Reads eight bytes and returns a long (LE byte order).
      long readLong​(long pos)
      Reads a long (LE byte order) at the given position in the file
      void readLongs​(long[] arr, int off, int len)
      Read a specified number of longs.
      short readShort()
      Reads two bytes and returns a short (LE byte order).
      short readShort​(long pos)
      Reads a short (LE byte order) at the given position in the file
      void seek​(long position)  
      long size()
      Deprecated.
      Use length() instead.
      void skipBytes​(long numBytes)
      Skip over numBytes bytes.
      ByteBuffersDataInput slice​(long offset, long length)  
      private static java.util.List<java.nio.ByteBuffer> sliceBufferList​(java.util.List<java.nio.ByteBuffer> buffers, long offset, long length)  
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

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

      • blocks

        private final java.nio.ByteBuffer[] blocks
      • floatBuffers

        private final java.nio.FloatBuffer[] floatBuffers
      • longBuffers

        private final java.nio.LongBuffer[] longBuffers
      • blockBits

        private final int blockBits
      • blockMask

        private final int blockMask
      • length

        private final long length
      • offset

        private final long offset
      • pos

        private long pos
    • Constructor Detail

      • ByteBuffersDataInput

        public ByteBuffersDataInput​(java.util.List<java.nio.ByteBuffer> buffers)
        Read data from a set of contiguous buffers. All data buffers except for the last one must have an identical remaining number of bytes in the buffer (that is a power of two). The last buffer can be of an arbitrary remaining length.
    • Method Detail

      • size

        @Deprecated
        public long size()
        Deprecated.
        Use length() instead.
        Returns the total number of bytes in this stream.
      • ramBytesUsed

        public long ramBytesUsed()
        Description copied from interface: Accountable
        Return the memory usage of this object in bytes. Negative values are illegal.
        Specified by:
        ramBytesUsed in interface Accountable
      • readBytes

        public void readBytes​(java.nio.ByteBuffer buffer,
                              int len)
                       throws java.io.EOFException
        Reads exactly len bytes into the given buffer. The buffer must have enough remaining limit.

        If there are fewer than len bytes in the input, EOFException is thrown.

        Throws:
        java.io.EOFException
      • readBytes

        public void readBytes​(byte[] arr,
                              int off,
                              int len)
                       throws java.io.EOFException
        Description copied from class: DataInput
        Reads a specified number of bytes into an array at the specified offset.
        Specified by:
        readBytes in class DataInput
        Parameters:
        arr - the array to read bytes into
        off - the offset in the array to start storing bytes
        len - the number of bytes to read
        Throws:
        java.io.EOFException
        See Also:
        DataOutput.writeBytes(byte[],int)
      • readGroupVInt

        protected void readGroupVInt​(long[] dst,
                                     int offset)
                              throws java.io.IOException
        Description copied from class: DataInput
        Override if you have a efficient implementation. In general this is when the input supports random access.
        Overrides:
        readGroupVInt in class DataInput
        Throws:
        java.io.IOException
      • readFloats

        public void readFloats​(float[] arr,
                               int off,
                               int len)
                        throws java.io.EOFException
        Description copied from class: DataInput
        Reads a specified number of floats into an array at the specified offset.
        Overrides:
        readFloats in class DataInput
        Parameters:
        arr - the array to read bytes into
        off - the offset in the array to start storing floats
        len - the number of floats to read
        Throws:
        java.io.EOFException
      • readLongs

        public void readLongs​(long[] arr,
                              int off,
                              int len)
                       throws java.io.EOFException
        Description copied from class: DataInput
        Read a specified number of longs.
        Overrides:
        readLongs in class DataInput
        Throws:
        java.io.EOFException
      • getFloatBuffer

        private java.nio.FloatBuffer getFloatBuffer​(long pos)
      • getLongBuffer

        private java.nio.LongBuffer getLongBuffer​(long pos)
      • position

        public long position()
      • seek

        public void seek​(long position)
                  throws java.io.EOFException
        Throws:
        java.io.EOFException
      • skipBytes

        public void skipBytes​(long numBytes)
                       throws java.io.IOException
        Description copied from class: DataInput
        Skip over numBytes bytes. This method may skip bytes in whatever way is most optimal, and may not have the same behavior as reading the skipped bytes. In general, negative numBytes are not supported.
        Specified by:
        skipBytes in class DataInput
        Throws:
        java.io.IOException
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • blockIndex

        private final int blockIndex​(long pos)
      • blockOffset

        private final int blockOffset​(long pos)
      • blockSize

        private int blockSize()
      • isPowerOfTwo

        private static final boolean isPowerOfTwo​(int v)
      • ensureAssumptions

        private static void ensureAssumptions​(java.util.List<java.nio.ByteBuffer> buffers)
      • determineBlockPage

        static int determineBlockPage​(java.util.List<java.nio.ByteBuffer> buffers)
      • sliceBufferList

        private static java.util.List<java.nio.ByteBuffer> sliceBufferList​(java.util.List<java.nio.ByteBuffer> buffers,
                                                                           long offset,
                                                                           long length)