Class FileBuffer

java.lang.Object
bdsup2sub.tools.FileBuffer

public class FileBuffer extends Object
Very simple version of a read only memory mapped file used for parsing large packet based files.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private byte[]
    Buffer in memory
    private static final int
    Size of the buffer in memory
    private FileChannel
    File channel of the input file
    File input stream of the input file
    private String
    File name of the input file
    private long
    Length of file
    private long
    Current offset in file = start of memory buffer
    private long
    Last valid offset that is stored in internal buffer
  • Constructor Summary

    Constructors
    Constructor
    Description
    FileBuffer(String filename)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Close file buffer (closes input file).
    void
     
    int
    getByte(long offset)
    Read one byte from the buffer.
    void
    getBytes(long ofs, byte[] b, int len)
    Read multiple bytes from the buffer.
    int
    getDWord(long offset)
    Read one (big endian) 32bit dword from the buffer.
    int
    getDWordLE(long offset)
    Read one (little endian) 32bit dword from the buffer.
    long
    Get size of input file.
    int
    getWord(long offset)
    Read one (big endian) 16bit word from the buffer.
    int
    getWordLE(long offset)
    Read one (little endian) 16bit word from the buffer.
    private void
    readBuffer(long offset)
    Move offset, read file to memory buffer.

    Methods inherited from class java.lang.Object

    clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • BUFFERSIZE

      private static final int BUFFERSIZE
      Size of the buffer in memory
      See Also:
    • buf

      private byte[] buf
      Buffer in memory
    • filename

      private String filename
      File name of the input file
    • fi

      private FileInputStream fi
      File input stream of the input file
    • fc

      private FileChannel fc
      File channel of the input file
    • offset

      private long offset
      Current offset in file = start of memory buffer
    • offsetEnd

      private long offsetEnd
      Last valid offset that is stored in internal buffer
    • length

      private long length
      Length of file
  • Constructor Details

  • Method Details

    • readBuffer

      private void readBuffer(long offset) throws FileBufferException
      Move offset, read file to memory buffer.
      Parameters:
      offset - New file offset
      Throws:
      FileBufferException
    • getByte

      public int getByte(long offset) throws FileBufferException
      Read one byte from the buffer.
      Parameters:
      offset - File offset
      Returns:
      Byte read from the buffer
      Throws:
      FileBufferException
    • getWord

      public int getWord(long offset) throws FileBufferException
      Read one (big endian) 16bit word from the buffer.
      Parameters:
      offset - File offset
      Returns:
      Word read from the buffer
      Throws:
      FileBufferException
    • getWordLE

      public int getWordLE(long offset) throws FileBufferException
      Read one (little endian) 16bit word from the buffer.
      Parameters:
      offset - File offset
      Returns:
      Word read from the buffer
      Throws:
      FileBufferException
    • getDWord

      public int getDWord(long offset) throws FileBufferException
      Read one (big endian) 32bit dword from the buffer.
      Parameters:
      offset - File offset
      Returns:
      Dword read from the buffer
      Throws:
      FileBufferException
    • getDWordLE

      public int getDWordLE(long offset) throws FileBufferException
      Read one (little endian) 32bit dword from the buffer.
      Parameters:
      offset - File offset
      Returns:
      Dword read from the buffer
      Throws:
      FileBufferException
    • getBytes

      public void getBytes(long ofs, byte[] b, int len) throws FileBufferException
      Read multiple bytes from the buffer.
      Parameters:
      ofs - File offset
      b - Buffer to store bytes (has to be allocated and large enough)
      len - Number of bytes to read
      Throws:
      FileBufferException
    • getSize

      public long getSize()
      Get size of input file.
      Returns:
      Size of input file in bytes
    • close

      public void close()
      Close file buffer (closes input file).
    • finalize

      public void finalize() throws Throwable
      Overrides:
      finalize in class Object
      Throws:
      Throwable