Class EndianNioInput

  • All Implemented Interfaces:
    EndianDataInput, java.io.DataInput

    public class EndianNioInput
    extends java.lang.Object
    implements EndianDataInput
    Wrap a NIO ByteBuffer for use as either EndianDataInput or EndianDataOutput compatible with any Capsule subclass. Includes inverse skip handling for fixed-length typed reads and writes.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected java.nio.ByteBuffer buf  
      protected boolean isBE  
      protected static org.slf4j.Logger sLogger  
      protected int toSkip  
    • Constructor Summary

      Constructors 
      Constructor Description
      EndianNioInput​(java.nio.ByteBuffer buf)
      Wrap the given bytebuffer for use in the Capsule class and any of its subclasses.
      EndianNioInput​(java.nio.ByteBuffer buf, int skip)
      Wrap the given bytebuffer for use in the Capsule class and any of its subclasses, initializing the preliminary bytes to skip.
    • Field Detail

      • sLogger

        protected static org.slf4j.Logger sLogger
      • isBE

        protected boolean isBE
      • buf

        protected final java.nio.ByteBuffer buf
      • toSkip

        protected int toSkip
    • Constructor Detail

      • EndianNioInput

        public EndianNioInput​(java.nio.ByteBuffer buf)
        Wrap the given bytebuffer for use in the Capsule class and any of its subclasses.
      • EndianNioInput

        public EndianNioInput​(java.nio.ByteBuffer buf,
                              int skip)
        Wrap the given bytebuffer for use in the Capsule class and any of its subclasses, initializing the preliminary bytes to skip.
    • Method Detail

      • readFully

        public void readFully​(byte[] dst)
                       throws java.io.IOException
        Specified by:
        readFully in interface java.io.DataInput
        Throws:
        java.io.IOException
      • readFully

        public void readFully​(byte[] dst,
                              int offset,
                              int length)
                       throws java.io.IOException
        Specified by:
        readFully in interface java.io.DataInput
        Throws:
        java.io.IOException
      • skipBytes

        public int skipBytes​(int n)
                      throws java.io.IOException
        Specified by:
        skipBytes in interface java.io.DataInput
        Throws:
        java.io.IOException
      • get

        protected byte get()
      • readBoolean

        public boolean readBoolean()
                            throws java.io.IOException
        Specified by:
        readBoolean in interface java.io.DataInput
        Throws:
        java.io.IOException
      • readByte

        public byte readByte()
                      throws java.io.IOException
        Specified by:
        readByte in interface java.io.DataInput
        Throws:
        java.io.IOException
      • readUnsignedByte

        public int readUnsignedByte()
                             throws java.io.IOException
        Specified by:
        readUnsignedByte in interface java.io.DataInput
        Throws:
        java.io.IOException
      • checkReadSkip

        protected void checkReadSkip​(int n)
                              throws java.io.IOException
        Throws:
        java.io.IOException
      • readShort

        public short readShort()
                        throws java.io.IOException
        Specified by:
        readShort in interface java.io.DataInput
        Throws:
        java.io.IOException
      • readUnsignedShort

        public int readUnsignedShort()
                              throws java.io.IOException
        Specified by:
        readUnsignedShort in interface java.io.DataInput
        Throws:
        java.io.IOException
      • readChar

        public char readChar()
                      throws java.io.IOException
        Specified by:
        readChar in interface java.io.DataInput
        Throws:
        java.io.IOException
      • readInt

        public int readInt()
                    throws java.io.IOException
        Specified by:
        readInt in interface java.io.DataInput
        Throws:
        java.io.IOException
      • readLong

        public long readLong()
                      throws java.io.IOException
        Specified by:
        readLong in interface java.io.DataInput
        Throws:
        java.io.IOException
      • readFloat

        public float readFloat()
                        throws java.io.IOException
        Specified by:
        readFloat in interface java.io.DataInput
        Throws:
        java.io.IOException
      • readDouble

        public double readDouble()
                          throws java.io.IOException
        Specified by:
        readDouble in interface java.io.DataInput
        Throws:
        java.io.IOException
      • readLine

        public java.lang.String readLine()
                                  throws java.io.IOException
        Specified by:
        readLine in interface java.io.DataInput
        Throws:
        java.io.IOException
      • readUTF

        public java.lang.String readUTF()
                                 throws java.io.IOException
        Specified by:
        readUTF in interface java.io.DataInput
        Throws:
        java.io.IOException
      • readShortLE

        public short readShortLE()
                          throws java.io.IOException
        Description copied from interface: EndianDataInput
        Little-endian alternative to readShort()
        Specified by:
        readShortLE in interface EndianDataInput
        Returns:
        Throws:
        java.io.IOException
      • readCharLE

        public char readCharLE()
                        throws java.io.IOException
        Description copied from interface: EndianDataInput
        Little-endian alternative to readChar()
        Specified by:
        readCharLE in interface EndianDataInput
        Returns:
        Throws:
        java.io.IOException
      • readDoubleLE

        public double readDoubleLE()
                            throws java.io.IOException
        Description copied from interface: EndianDataInput
        Little-endian alternative to readDouble()
        Specified by:
        readDoubleLE in interface EndianDataInput
        Returns:
        Throws:
        java.io.IOException
      • readFloatLE

        public float readFloatLE()
                          throws java.io.IOException
        Description copied from interface: EndianDataInput
        Little-endian alternative to readFloat()
        Specified by:
        readFloatLE in interface EndianDataInput
        Returns:
        Throws:
        java.io.IOException
      • readIntLE

        public int readIntLE()
                      throws java.io.IOException
        Description copied from interface: EndianDataInput
        Little-endian alternative to readInt()
        Specified by:
        readIntLE in interface EndianDataInput
        Returns:
        Throws:
        java.io.IOException
      • readLongLE

        public long readLongLE()
                        throws java.io.IOException
        Description copied from interface: EndianDataInput
        Little-endian alternative to readLong()
        Specified by:
        readLongLE in interface EndianDataInput
        Returns:
        Throws:
        java.io.IOException
      • readUnsignedShortLE

        public int readUnsignedShortLE()
                                throws java.io.IOException
        Description copied from interface: EndianDataInput
        Little-endian alternative to readUnsignedShort()
        Specified by:
        readUnsignedShortLE in interface EndianDataInput
        Returns:
        Throws:
        java.io.IOException
      • readUnsignedInt

        public long readUnsignedInt()
                             throws java.io.IOException
        Description copied from interface: EndianDataInput
        Extension to the DataInput interface similar to readUnsignedShort(), but delivering an unsigned integer in a long.
        Specified by:
        readUnsignedInt in interface EndianDataInput
        Returns:
        Throws:
        java.io.IOException
      • readUnsignedIntLE

        public long readUnsignedIntLE()
                               throws java.io.IOException
        Description copied from interface: EndianDataInput
        Little-endian alternative to readUnsignedInt()
        Specified by:
        readUnsignedIntLE in interface EndianDataInput
        Returns:
        Throws:
        java.io.IOException
      • readUnsignedLong

        public java.math.BigInteger readUnsignedLong()
                                              throws java.io.IOException
        Description copied from interface: EndianDataInput
        Extension to the DataInput interface similar to readUnsignedShort(), but delivering an unsigned long in a bignum.
        Specified by:
        readUnsignedLong in interface EndianDataInput
        Returns:
        Throws:
        java.io.IOException
      • readUnsignedLongLE

        public java.math.BigInteger readUnsignedLongLE()
                                                throws java.io.IOException
        Description copied from interface: EndianDataInput
        Little-endian alternative to readUnsignedLong()
        Specified by:
        readUnsignedLongLE in interface EndianDataInput
        Returns:
        Throws:
        java.io.IOException
      • getBuffer

        public java.nio.ByteBuffer getBuffer()
      • remaining

        public int remaining()
                      throws java.io.IOException
        Throws:
        java.io.IOException
      • asLimitedInput

        public EndianDataInput asLimitedInput​(long limit)
        Unlike the implementation in EndianInputStream, this method immediately "consumes" the given number of bytes from the wrapped NIO buffer after creating the limited slice.
        Specified by:
        asLimitedInput in interface EndianDataInput
        Parameters:
        limit - Number of bytes to read from this subordinate source before signalling end of file. Underlying implementations may truncate this to 32 bits.
        Returns: