Package gov.nasa.pds.objectAccess
Class ByteWiseFileAccessor
- java.lang.Object
- 
- gov.nasa.pds.objectAccess.ByteWiseFileAccessor
 
- 
- All Implemented Interfaces:
- java.io.Closeable,- java.lang.AutoCloseable
 
 public class ByteWiseFileAccessor extends java.lang.Object implements java.io.CloseableClass that provides common I/O functionality for PDS data objects.
- 
- 
Constructor SummaryConstructors Constructor Description ByteWiseFileAccessor(java.io.File file, long offset, int length, long records)Constructs aByteWiseFileAccessorobject which maps a region of a data file into memory.ByteWiseFileAccessor(java.net.URL url, long offset, int length, long records)Constructs aByteWiseFileAccessorobject which maps a region of a data file into memory.ByteWiseFileAccessor(java.net.URL url, long offset, int length, long records, boolean checkSize)ByteWiseFileAccessor(java.net.URL url, long offset, int length, long records, boolean checkSize, java.io.RandomAccessFile raf)Constructs aByteWiseFileAccessorobject which maps a region of a data file into memory.
 - 
Method SummaryAll Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()longgetCurrentPosition()java.io.RandomAccessFilegetRandomAccessFile()longgetTotalBytesRead()longgetTotalFileContentSize()booleanhasRemaining()Checks 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 Detail- 
ByteWiseFileAccessorpublic ByteWiseFileAccessor(java.io.File file, long offset, int length, long records) throws java.io.FileNotFoundException, java.io.IOException, InvalidTableExceptionConstructs aByteWiseFileAccessorobject 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:
- java.io.FileNotFoundException- If- filedoes not exist, is a directory rather than a regular file, or for some other reason cannot be opened for reading
- java.io.IOException- If an I/O error occurs
- InvalidTableException
- MissingDataException
- java.lang.IllegalArgumentException
 
 - 
ByteWiseFileAccessorpublic ByteWiseFileAccessor(java.net.URL url, long offset, int length, long records) throws java.io.FileNotFoundException, java.io.IOException, InvalidTableExceptionConstructs aByteWiseFileAccessorobject 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:
- java.io.FileNotFoundException- If- filedoes not exist, is a directory rather than a regular file, or for some other reason cannot be opened for reading
- java.io.IOException- If an I/O error occurs
- InvalidTableException
- MissingDataException
- java.lang.IllegalArgumentException
 
 - 
ByteWiseFileAccessorpublic ByteWiseFileAccessor(java.net.URL url, long offset, int length, long records, boolean checkSize) throws java.io.FileNotFoundException, java.io.IOException, InvalidTableException- Throws:
- java.io.FileNotFoundException
- java.io.IOException
- InvalidTableException
 
 - 
ByteWiseFileAccessorpublic ByteWiseFileAccessor(java.net.URL url, long offset, int length, long records, boolean checkSize, java.io.RandomAccessFile raf) throws java.io.FileNotFoundException, java.io.IOException, InvalidTableExceptionConstructs aByteWiseFileAccessorobject 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:
- java.io.FileNotFoundException- If- filedoes not exist, is a directory rather than a regular file, or for some other reason cannot be opened for reading
- java.io.IOException- If an I/O error occurs
- InvalidTableException
- MissingDataException
 
 
- 
 - 
Method Detail- 
readRecordBytespublic 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 record
- length- the number of bytes to read from the record
- Returns:
- an array of bytes
 
 - 
readBytepublic byte readByte() Reads a byte from the buffer.- Returns:
- A byte.
 
 - 
markpublic void mark() Marks the buffer.
 - 
resetpublic void reset() Resets the buffer.
 - 
hasRemainingpublic boolean hasRemaining() Checks to see if the buffer can still be read.- Returns:
- 'true' if there are more bytes to be read. 'false' otherwise.
 
 - 
getCurrentPositionpublic long getCurrentPosition() 
 - 
getTotalFileContentSizepublic long getTotalFileContentSize() 
 - 
getTotalBytesReadpublic long getTotalBytesRead() 
 - 
closepublic void close() throws java.io.IOException- Specified by:
- closein interface- java.lang.AutoCloseable
- Specified by:
- closein interface- java.io.Closeable
- Throws:
- java.io.IOException
 
 - 
getRandomAccessFilepublic java.io.RandomAccessFile getRandomAccessFile() 
 
- 
 
-