Package gov.nasa.pds.objectAccess
Class ByteWiseFileAccessor
java.lang.Object
gov.nasa.pds.objectAccess.ByteWiseFileAccessor
- All Implemented Interfaces:
Closeable,AutoCloseable
Class that provides common I/O functionality for PDS data objects.
-
Constructor Summary
ConstructorsConstructorDescriptionByteWiseFileAccessor(File file, long offset, int length, long records) Constructs aByteWiseFileAccessorobject which maps a region of a data file into memory.ByteWiseFileAccessor(URL url, long offset, int length, long records) Constructs aByteWiseFileAccessorobject which maps a region of a data file into memory.ByteWiseFileAccessor(URL url, long offset, int length, long records, boolean checkSize) ByteWiseFileAccessor(URL url, long offset, int length, long records, boolean checkSize, RandomAccessFile raf) Constructs aByteWiseFileAccessorobject which maps a region of a data file into memory. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()longlonglongbooleanChecks to see if the buffer can still be read.voidmark()Marks the buffer.bytereadByte()Reads a byte from the buffer.byte[]readRecordBytes(long recordNum, int offset, int length) Readslengthbytes of data from a specified record at the given offset.voidreset()Resets the buffer.
-
Constructor Details
-
ByteWiseFileAccessor
public ByteWiseFileAccessor(File file, long offset, int length, long records) throws FileNotFoundException, IOException, InvalidTableException Constructs aByteWiseFileAccessorobject which maps a region of a data file into memory.- Parameters:
file- the data fileoffset- the offset within the data filelength- the record length in bytesrecords- the number of records- Throws:
FileNotFoundException- Iffiledoes not exist, is a directory rather than a regular file, or for some other reason cannot be opened for readingIOException- If an I/O error occursInvalidTableExceptionMissingDataExceptionIllegalArgumentException
-
ByteWiseFileAccessor
public ByteWiseFileAccessor(URL url, long offset, int length, long records) throws FileNotFoundException, IOException, InvalidTableException Constructs aByteWiseFileAccessorobject which maps a region of a data file into memory.- Parameters:
url- the data fileoffset- the offset within the data filelength- the record length in bytesrecords- the number of records- Throws:
FileNotFoundException- Iffiledoes not exist, is a directory rather than a regular file, or for some other reason cannot be opened for readingIOException- If an I/O error occursInvalidTableExceptionMissingDataExceptionIllegalArgumentException
-
ByteWiseFileAccessor
public ByteWiseFileAccessor(URL url, long offset, int length, long records, boolean checkSize) throws FileNotFoundException, IOException, InvalidTableException -
ByteWiseFileAccessor
public ByteWiseFileAccessor(URL url, long offset, int length, long records, boolean checkSize, RandomAccessFile raf) throws FileNotFoundException, IOException, InvalidTableException Constructs aByteWiseFileAccessorobject which maps a region of a data file into memory.- Parameters:
url- the data fileoffset- the offset within the data filelength- the record length in bytesrecords- the number of recordscheckSize- check that the size of the data file is equal to the size of the table (length * records) + offset.- Throws:
FileNotFoundException- Iffiledoes not exist, is a directory rather than a regular file, or for some other reason cannot be opened for readingIOException- If an I/O error occursInvalidTableExceptionMissingDataException
-
-
Method Details
-
readRecordBytes
public byte[] readRecordBytes(long recordNum, int offset, int length) Readslengthbytes 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 recordlength- 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() -
getTotalFileContentSize
public long getTotalFileContentSize() -
getTotalBytesRead
public long getTotalBytesRead() -
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException
-
getRandomAccessFile
-