Class ByteWiseFileAccessor

java.lang.Object
gov.nasa.pds.objectAccess.ByteWiseFileAccessor

public class ByteWiseFileAccessor
extends Object
Class that provides common I/O functionality for PDS data objects.
  • Constructor Summary

    Constructors
    Constructor Description
    ByteWiseFileAccessor​(File file, long offset, int length, int records)
    Constructs a ByteWiseFileAccessor object which maps a region of a data file into memory.
    ByteWiseFileAccessor​(URL url, long offset, int length)
    Constructor.
    ByteWiseFileAccessor​(URL url, long offset, int length, int records)
    Constructs a ByteWiseFileAccessor object which maps a region of a data file into memory.
    ByteWiseFileAccessor​(URL url, long offset, int length, int records, boolean checkSize)
    Constructs a ByteWiseFileAccessor object which maps a region of a data file into memory.
  • Method Summary

    Modifier and Type Method Description
    long getCurrentPosition()  
    long getFileContentSize()  
    boolean hasRemaining()
    Checks to see if the buffer can still be read.
    void mark()
    Marks the buffer.
    byte readByte()
    Reads a byte from the buffer.
    byte[] readRecordBytes​(int recordNum, int offset, int length)
    Reads length bytes of data from a specified record at the given offset.
    void reset()
    Resets the buffer.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • ByteWiseFileAccessor

      public ByteWiseFileAccessor​(File file, long offset, int length, int records) throws FileNotFoundException, IOException
      Constructs a ByteWiseFileAccessor object which maps a region of a data file into memory.
      Parameters:
      file - the data file
      offset - the offset within the data file
      length - the record length in bytes
      records - the number of records
      Throws:
      FileNotFoundException - If file does not exist, is a directory rather than a regular file, or for some other reason cannot be opened for reading
      IOException - If an I/O error occurs
    • ByteWiseFileAccessor

      public ByteWiseFileAccessor​(URL url, long offset, int length, int records) throws FileNotFoundException, IOException
      Constructs a ByteWiseFileAccessor object which maps a region of a data file into memory.
      Parameters:
      url - the data file
      offset - the offset within the data file
      length - the record length in bytes
      records - the number of records
      Throws:
      FileNotFoundException - If file does not exist, is a directory rather than a regular file, or for some other reason cannot be opened for reading
      IOException - If an I/O error occurs
    • ByteWiseFileAccessor

      public ByteWiseFileAccessor​(URL url, long offset, int length, int records, boolean checkSize) throws FileNotFoundException, IOException
      Constructs a ByteWiseFileAccessor object which maps a region of a data file into memory.
      Parameters:
      url - the data file
      offset - the offset within the data file
      length - the record length in bytes
      records - the number of records
      checkSize - check that the size of the data file is equal to the size of the table (length * records) + offset.
      Throws:
      FileNotFoundException - If file does not exist, is a directory rather than a regular file, or for some other reason cannot be opened for reading
      IOException - If an I/O error occurs
    • ByteWiseFileAccessor

      public ByteWiseFileAccessor​(URL url, long offset, int length) throws IOException
      Constructor.
      Parameters:
      url - The data file.
      offset - The offset within the data file.
      Throws:
      IOException - If an I/O error occurs.
  • Method Details

    • readRecordBytes

      public byte[] readRecordBytes​(int recordNum, int offset, int length)
      Reads length bytes of data from a specified record at the given offset.
      Parameters:
      recordNum - the record number to read bytes from (1-relative)
      offset - an offset within the record
      length - the number of bytes to read from the record
      Returns:
      an array of bytes
    • readByte

      public byte readByte()
      Reads a byte from the buffer.
      Returns:
      A byte.
    • mark

      public void mark()
      Marks the buffer.
    • reset

      public void reset()
      Resets the buffer.
    • hasRemaining

      public boolean hasRemaining()
      Checks to see if the buffer can still be read.
      Returns:
      'true' if there are more bytes to be read. 'false' otherwise.
    • getCurrentPosition

      public long getCurrentPosition()
    • getFileContentSize

      public long getFileContentSize()