Class RandomAccessFileKaitaiStream

  • All Implemented Interfaces:
    Closeable, AutoCloseable

    public class RandomAccessFileKaitaiStream
    extends KaitaiStream
    An implementation of KaitaiStream backed by a RandomAccessFile. Allows reading from local files. Generally, one would want to use ByteBufferKaitaiStream instead, as it most likely would be faster, but there are two situations when one should consider this one instead:
    • Processing many small files. Every ByteBuffer invocation requires a mmap call, which can be relatively expensive (per file).
    • Accessing extra-long files (>31 bits positioning). Unfortunately, Java's implementation of mmap uses ByteBuffer, which is not addressable beyond 31 bit offsets, even if you use a 64-bit platform.
    • Method Detail

      • isEof

        public boolean isEof()
        Description copied from class: KaitaiStream
        Check if stream pointer is at the end of stream.
        Specified by:
        isEof in class KaitaiStream
        Returns:
        true if we are located at the end of the stream
      • seek

        public void seek​(int newPos)
        Description copied from class: KaitaiStream
        Set stream pointer to designated position (int).
        Specified by:
        seek in class KaitaiStream
        Parameters:
        newPos - new position (offset in bytes from the beginning of the stream)
      • seek

        public void seek​(long newPos)
        Description copied from class: KaitaiStream
        Set stream pointer to designated position (long).
        Specified by:
        seek in class KaitaiStream
        Parameters:
        newPos - new position (offset in bytes from the beginning of the stream)
      • pos

        public int pos()
        Description copied from class: KaitaiStream
        Get current position of a stream pointer.
        Specified by:
        pos in class KaitaiStream
        Returns:
        pointer position, number of bytes from the beginning of the stream
      • size

        public long size()
        Description copied from class: KaitaiStream
        Get total size of the stream in bytes.
        Specified by:
        size in class KaitaiStream
        Returns:
        size of the stream in bytes
      • readS1

        public byte readS1()
        Description copied from class: KaitaiStream
        Reads one signed 1-byte integer, returning it properly as Java's "byte" type.
        Specified by:
        readS1 in class KaitaiStream
        Returns:
        1-byte integer read from a stream
      • readBytes

        public byte[] readBytes​(long n)
        Description copied from class: KaitaiStream
        Reads designated number of bytes from the stream.
        Specified by:
        readBytes in class KaitaiStream
        Parameters:
        n - number of bytes to read
        Returns:
        read bytes as byte array
      • readBytesFull

        public byte[] readBytesFull()
        Description copied from class: KaitaiStream
        Reads all the remaining bytes in a stream as byte array.
        Specified by:
        readBytesFull in class KaitaiStream
        Returns:
        all remaining bytes in a stream as byte array
      • readBytesTerm

        public byte[] readBytesTerm​(int term,
                                    boolean includeTerm,
                                    boolean consumeTerm,
                                    boolean eosError)
        Specified by:
        readBytesTerm in class KaitaiStream