Module de.carne.mcd

Class MCDInputBuffer

  • All Implemented Interfaces:
    MCDBuffer

    public final class MCDInputBuffer
    extends java.lang.Object
    implements MCDBuffer
    Buffered byte channel access during decoding.
    • Constructor Summary

      Constructors 
      Constructor Description
      MCDInputBuffer​(java.nio.channels.ReadableByteChannel in, java.nio.ByteOrder byteOrder)
      Constructs a new MCDInputBuffer instance.
      MCDInputBuffer​(java.nio.channels.ReadableByteChannel in, java.nio.ByteOrder byteOrder, int bufferSize)
      Constructs a new MCDInputBuffer instance.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void commit()
      Commits any buffered data operation.
      float decodeF32()
      Decodes a float value.
      double decodeF64()
      Decodes a double byte value.
      short decodeI16()
      Decodes a short value.
      java.nio.ByteBuffer decodeI16Array​(int arrayLength)
      Decodes an array of short values.
      int decodeI32()
      Decodes an int value.
      java.nio.ByteBuffer decodeI32Array​(int arrayLength)
      Decodes an array of int values.
      long decodeI64()
      Decodes a long value.
      java.nio.ByteBuffer decodeI64Array​(int arrayLength)
      Decodes an array of long values.
      byte decodeI8()
      Decodes a byte value.
      java.nio.ByteBuffer decodeI8Array​(int arrayLength)
      Decodes an array of byte values.
      void decodeMagic​(byte expectedMagic)
      Decodes the given magic byte.
      void decodeMagic​(int expectedMagic)
      Decodes the given magic dword.
      void decodeMagic​(long expectedMagic)
      Decodes the given magic qword.
      void decodeMagic​(short expectedMagic)
      Decodes the given magic word.
      void discard()
      Discard any buffered data operation.
      void discard​(int length)
      Discards a specific number of uncommitted bytes.
      long getTotalRead()
      Gets the total number of bytes read via this MCDInputBuffer instance.
      int read()
      Reads a single byte value.
      boolean setAutoCommit​(boolean autoCommit)
      Sets the auto-commit flag for this MCDBuffer instance.
      void skip​(long length)
      Skips the requested number of bytes from the byte channel.
      java.nio.channels.SeekableByteChannel slice​(long length)
      Slices the requested number of bytes from the byte channel and wraps them into a SeekableByteChannel instance for later decoding.
      static short[] toI16Array​(java.nio.ByteBuffer buffer)
      Decodes a short array from a buffer returned from decodeI16Array(int).
      static int[] toI32Array​(java.nio.ByteBuffer buffer)
      Decodes an int array from a buffer returned from decodeI32Array(int).
      static long[] toI64Array​(java.nio.ByteBuffer buffer)
      Decodes a long array from a buffer returned from decodeI64Array(int).
      static byte[] toI8Array​(java.nio.ByteBuffer buffer)
      Decodes a byte array from a buffer returned from decodeI8Array(int).
      @NonNull java.lang.String toString()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • MCDInputBuffer

        public MCDInputBuffer​(java.nio.channels.ReadableByteChannel in,
                              java.nio.ByteOrder byteOrder)
        Constructs a new MCDInputBuffer instance.
        Parameters:
        in - the ReadableByteChannel to read from.
        byteOrder - the ByteOrder to use for decoding.
      • MCDInputBuffer

        public MCDInputBuffer​(java.nio.channels.ReadableByteChannel in,
                              java.nio.ByteOrder byteOrder,
                              int bufferSize)
        Constructs a new MCDInputBuffer instance.
        Parameters:
        in - the ReadableByteChannel to read from.
        byteOrder - the ByteOrder to use for decoding.
        bufferSize - the buffer size to use.
    • Method Detail

      • getTotalRead

        public long getTotalRead()
        Gets the total number of bytes read via this MCDInputBuffer instance.
        Returns:
        the total number of bytes read via this MCDInputBuffer instance.
      • setAutoCommit

        public boolean setAutoCommit​(boolean autoCommit)
        Description copied from interface: MCDBuffer
        Sets the auto-commit flag for this MCDBuffer instance.
        Specified by:
        setAutoCommit in interface MCDBuffer
        Parameters:
        autoCommit - whether to auto-commit any buffer operation or not.
        Returns:
        the previous auto-commit flag state.
      • commit

        public void commit()
                    throws java.io.IOException
        Description copied from interface: MCDBuffer
        Commits any buffered data operation.
        Specified by:
        commit in interface MCDBuffer
        Throws:
        java.io.IOException - if an I/O error occurs.
      • discard

        public void discard()
        Description copied from interface: MCDBuffer
        Discard any buffered data operation.
        Specified by:
        discard in interface MCDBuffer
      • discard

        public void discard​(int length)
        Discards a specific number of uncommitted bytes.

        If length is positive the corresponding number of bytes are kept as uncommitted and any following byte is discarded. If length is negative the last -length bytes are discarded and any other byte is kept as uncommitted.

        Parameters:
        length - the amount of bytes to discard.
      • slice

        public java.nio.channels.SeekableByteChannel slice​(long length)
                                                    throws java.io.IOException
        Slices the requested number of bytes from the byte channel and wraps them into a SeekableByteChannel instance for later decoding.

        This function requires this buffer instance to be committed prior to calling it.

        Parameters:
        length - the number of bytes to slice.
        Returns:
        the SeekableByteChannel providing access to the sliced bytes.
        Throws:
        java.io.IOException - if an I/O error occurs.
      • skip

        public void skip​(long length)
                  throws java.io.IOException
        Skips the requested number of bytes from the byte channel.

        This function requires this buffer instance to be committed prior to calling it.

        Parameters:
        length - the number of bytes to skip.
        Throws:
        java.io.IOException - if an I/O error occurs.
      • read

        public int read()
                 throws java.io.IOException
        Reads a single byte value.

        In contrast to the decode functions this function handles EOF gracefully by returning -1.

        Returns:
        the read byte value or -1 if EOF has been reached.
        Throws:
        java.io.IOException - if an I/O error occurs.
      • decodeI8

        public byte decodeI8()
                      throws java.io.IOException
        Decodes a byte value.
        Returns:
        the decoded value.
        Throws:
        java.io.IOException - if an I/O error occurs.
      • decodeI8Array

        public java.nio.ByteBuffer decodeI8Array​(int arrayLength)
                                          throws java.io.IOException
        Decodes an array of byte values.
        Parameters:
        arrayLength - the array length to decode.
        Returns:
        the decoded value.
        Throws:
        java.io.IOException - if an I/O error occurs.
      • toI8Array

        public static byte[] toI8Array​(java.nio.ByteBuffer buffer)
        Decodes a byte array from a buffer returned from decodeI8Array(int).
        Parameters:
        buffer - the buffer to decode.
        Returns:
        the decoded array.
      • decodeMagic

        public void decodeMagic​(byte expectedMagic)
                         throws java.io.IOException
        Decodes the given magic byte.
        Parameters:
        expectedMagic - the expected magic byte.
        Throws:
        java.io.IOException - if the decoded byte does not match the expected magic byte or if an I/O error occurs.
      • decodeI16

        public short decodeI16()
                        throws java.io.IOException
        Decodes a short value.
        Returns:
        the decoded value.
        Throws:
        java.io.IOException - if an I/O error occurs.
      • decodeI16Array

        public java.nio.ByteBuffer decodeI16Array​(int arrayLength)
                                           throws java.io.IOException
        Decodes an array of short values.
        Parameters:
        arrayLength - the array length to decode.
        Returns:
        the decoded value.
        Throws:
        java.io.IOException - if an I/O error occurs.
      • toI16Array

        public static short[] toI16Array​(java.nio.ByteBuffer buffer)
        Decodes a short array from a buffer returned from decodeI16Array(int).
        Parameters:
        buffer - the buffer to decode.
        Returns:
        the decoded array.
      • decodeMagic

        public void decodeMagic​(short expectedMagic)
                         throws java.io.IOException
        Decodes the given magic word.
        Parameters:
        expectedMagic - the expected magic word.
        Throws:
        java.io.IOException - if the decoded word does not match the expected magic word or if an I/O error occurs.
      • decodeI32

        public int decodeI32()
                      throws java.io.IOException
        Decodes an int value.
        Returns:
        the decoded value.
        Throws:
        java.io.IOException - if an I/O error occurs.
      • decodeI32Array

        public java.nio.ByteBuffer decodeI32Array​(int arrayLength)
                                           throws java.io.IOException
        Decodes an array of int values.
        Parameters:
        arrayLength - the array length to decode.
        Returns:
        the decoded value.
        Throws:
        java.io.IOException - if an I/O error occurs.
      • toI32Array

        public static int[] toI32Array​(java.nio.ByteBuffer buffer)
        Decodes an int array from a buffer returned from decodeI32Array(int).
        Parameters:
        buffer - the buffer to decode.
        Returns:
        the decoded array.
      • decodeMagic

        public void decodeMagic​(int expectedMagic)
                         throws java.io.IOException
        Decodes the given magic dword.
        Parameters:
        expectedMagic - the expected magic dword.
        Throws:
        java.io.IOException - if the decoded dword does not match the expected magic dword or if an I/O error occurs.
      • decodeI64

        public long decodeI64()
                       throws java.io.IOException
        Decodes a long value.
        Returns:
        the decoded value.
        Throws:
        java.io.IOException - if an I/O error occurs.
      • decodeI64Array

        public java.nio.ByteBuffer decodeI64Array​(int arrayLength)
                                           throws java.io.IOException
        Decodes an array of long values.
        Parameters:
        arrayLength - the array length to decode.
        Returns:
        the decoded value.
        Throws:
        java.io.IOException - if an I/O error occurs.
      • toI64Array

        public static long[] toI64Array​(java.nio.ByteBuffer buffer)
        Decodes a long array from a buffer returned from decodeI64Array(int).
        Parameters:
        buffer - the buffer to decode.
        Returns:
        the decoded array.
      • decodeMagic

        public void decodeMagic​(long expectedMagic)
                         throws java.io.IOException
        Decodes the given magic qword.
        Parameters:
        expectedMagic - the expected magic qword.
        Throws:
        java.io.IOException - if the decoded qword does not match the expected magic qword or if an I/O error occurs.
      • decodeF32

        public float decodeF32()
                        throws java.io.IOException
        Decodes a float value.
        Returns:
        the decoded value.
        Throws:
        java.io.IOException - if an I/O error occurs.
      • decodeF64

        public double decodeF64()
                         throws java.io.IOException
        Decodes a double byte value.
        Returns:
        the decoded value.
        Throws:
        java.io.IOException - if an I/O error occurs.
      • toString

        public @NonNull java.lang.String toString()
        Overrides:
        toString in class java.lang.Object