Class BufferedRandomInput

  • All Implemented Interfaces:
    BasicInput

    public class BufferedRandomInput
    extends java.lang.Object
    implements BasicInput
    BasicInput implementation based on a RandomAccessFile. Buffering of the underlying file is performed on the assumption that access will be largely sequential.
    Since:
    8 Nov 2017
    Author:
    Mark Taylor
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static int DFLT_BUFSIZE  
    • Constructor Summary

      Constructors 
      Constructor Description
      BufferedRandomInput​(java.io.RandomAccessFile file, long offset0)
      Constructs a BufferedRandomInput with a default sized buffer.
      BufferedRandomInput​(java.io.RandomAccessFile file, long offset0, int bufsize)
      Constructs a BufferedRandomInput with a buffer of specified size.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void close()
      Releases resources belonging to this object.
      long getOffset()
      Returns the curent position in this stream (optional operation).
      boolean isRandom()
      Indicates whether this object supports random access.
      byte readByte()
      Reads a byte from the stream.
      void readBytes​(byte[] bbuf)
      Reads bytes into an array from the stream.
      double readDouble()
      Reads an 8-byte floating point value from the stream.
      float readFloat()
      Reads a 4-byte floating point value from the stream.
      int readInt()
      Reads a 4-byte integer from the stream.
      long readLong()
      Reads an 8-byte integer from the stream.
      short readShort()
      Reads a 2-byte integer from the stream.
      void seek​(long offset)
      Moves the current position of this stream to a given byte offset (optional operation).
      void skip​(long nbytes)
      Skips a given number of bytes forwards through the stream.
      • Methods inherited from class java.lang.Object

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

      • DFLT_BUFSIZE

        public static final int DFLT_BUFSIZE
    • Constructor Detail

      • BufferedRandomInput

        public BufferedRandomInput​(java.io.RandomAccessFile file,
                                   long offset0)
                            throws java.io.IOException
        Constructs a BufferedRandomInput with a default sized buffer.
        Parameters:
        file - file
        offset0 - offset into file of stream start
        Throws:
        java.io.IOException
      • BufferedRandomInput

        public BufferedRandomInput​(java.io.RandomAccessFile file,
                                   long offset0,
                                   int bufsize)
                            throws java.io.IOException
        Constructs a BufferedRandomInput with a buffer of specified size.
        Parameters:
        file - file
        offset0 - offset into file of stream start
        bufsize - buffer size
        Throws:
        java.io.IOException
    • Method Detail

      • readByte

        public byte readByte()
                      throws java.io.IOException
        Description copied from interface: BasicInput
        Reads a byte from the stream. The current position is advanced.
        Specified by:
        readByte in interface BasicInput
        Returns:
        byte value
        Throws:
        java.io.IOException
      • readShort

        public short readShort()
                        throws java.io.IOException
        Description copied from interface: BasicInput
        Reads a 2-byte integer from the stream. The current position is advanced.
        Specified by:
        readShort in interface BasicInput
        Returns:
        short value
        Throws:
        java.io.IOException
      • readInt

        public int readInt()
                    throws java.io.IOException
        Description copied from interface: BasicInput
        Reads a 4-byte integer from the stream. The current position is advanced.
        Specified by:
        readInt in interface BasicInput
        Returns:
        int value
        Throws:
        java.io.IOException
      • readLong

        public long readLong()
                      throws java.io.IOException
        Description copied from interface: BasicInput
        Reads an 8-byte integer from the stream. The current position is advanced.
        Specified by:
        readLong in interface BasicInput
        Returns:
        long value
        Throws:
        java.io.IOException
      • readFloat

        public float readFloat()
                        throws java.io.IOException
        Description copied from interface: BasicInput
        Reads a 4-byte floating point value from the stream. The current position is advanced.
        Specified by:
        readFloat in interface BasicInput
        Returns:
        float value
        Throws:
        java.io.IOException
      • readDouble

        public double readDouble()
                          throws java.io.IOException
        Description copied from interface: BasicInput
        Reads an 8-byte floating point value from the stream. The current position is advanced.
        Specified by:
        readDouble in interface BasicInput
        Returns:
        double value
        Throws:
        java.io.IOException
      • readBytes

        public void readBytes​(byte[] bbuf)
                       throws java.io.IOException
        Description copied from interface: BasicInput
        Reads bytes into an array from the stream. The current position is advanced.
        Specified by:
        readBytes in interface BasicInput
        Parameters:
        bbuf - array into which the bytes are read; the number of bytes read is the length of the array
        Throws:
        java.io.IOException
      • isRandom

        public boolean isRandom()
        Description copied from interface: BasicInput
        Indicates whether this object supports random access. The seek and getOffset methods may only be called if this method returns true.
        Specified by:
        isRandom in interface BasicInput
        Returns:
        true iff random access is supported
      • skip

        public void skip​(long nbytes)
                  throws java.io.IOException
        Description copied from interface: BasicInput
        Skips a given number of bytes forwards through the stream. An exception is thrown if there are not enough bytes left.
        Specified by:
        skip in interface BasicInput
        Parameters:
        nbytes - number of bytes to skip
        Throws:
        java.io.IOException
      • getOffset

        public long getOffset()
        Description copied from interface: BasicInput
        Returns the curent position in this stream (optional operation).
        Specified by:
        getOffset in interface BasicInput
      • seek

        public void seek​(long offset)
                  throws java.io.IOException
        Description copied from interface: BasicInput
        Moves the current position of this stream to a given byte offset (optional operation).
        Specified by:
        seek in interface BasicInput
        Throws:
        java.io.IOException
      • close

        public void close()
                   throws java.io.IOException
        Description copied from interface: BasicInput
        Releases resources belonging to this object. Attempts to use it after a call to this method result in undefined behaviour.
        Specified by:
        close in interface BasicInput
        Throws:
        java.io.IOException