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.Closeable
Class that provides common I/O functionality for PDS data objects.
-
-
Constructor Summary
Constructors Constructor Description ByteWiseFileAccessor(java.io.File file, long offset, int length, long records)
Constructs aByteWiseFileAccessor
object which maps a region of a data file into memory.ByteWiseFileAccessor(java.net.URL url, long offset, int length, long records)
Constructs aByteWiseFileAccessor
object 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 aByteWiseFileAccessor
object which maps a region of a data file into memory.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
long
getCurrentPosition()
java.io.RandomAccessFile
getRandomAccessFile()
long
getTotalBytesRead()
long
getTotalFileContentSize()
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(long recordNum, int offset, int length)
Readslength
bytes of data from a specified record at the given offset.void
reset()
Resets the buffer.
-
-
-
Constructor Detail
-
ByteWiseFileAccessor
public ByteWiseFileAccessor(java.io.File file, long offset, int length, long records) throws java.io.FileNotFoundException, java.io.IOException, InvalidTableException
Constructs aByteWiseFileAccessor
object 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:
java.io.FileNotFoundException
- Iffile
does not exist, is a directory rather than a regular file, or for some other reason cannot be opened for readingjava.io.IOException
- If an I/O error occursInvalidTableException
MissingDataException
java.lang.IllegalArgumentException
-
ByteWiseFileAccessor
public ByteWiseFileAccessor(java.net.URL url, long offset, int length, long records) throws java.io.FileNotFoundException, java.io.IOException, InvalidTableException
Constructs aByteWiseFileAccessor
object 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:
java.io.FileNotFoundException
- Iffile
does not exist, is a directory rather than a regular file, or for some other reason cannot be opened for readingjava.io.IOException
- If an I/O error occursInvalidTableException
MissingDataException
java.lang.IllegalArgumentException
-
ByteWiseFileAccessor
public 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
-
ByteWiseFileAccessor
public ByteWiseFileAccessor(java.net.URL url, long offset, int length, long records, boolean checkSize, java.io.RandomAccessFile raf) throws java.io.FileNotFoundException, java.io.IOException, InvalidTableException
Constructs aByteWiseFileAccessor
object 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:
java.io.FileNotFoundException
- Iffile
does not exist, is a directory rather than a regular file, or for some other reason cannot be opened for readingjava.io.IOException
- If an I/O error occursInvalidTableException
MissingDataException
-
-
Method Detail
-
readRecordBytes
public byte[] readRecordBytes(long recordNum, int offset, int length)
Readslength
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 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
public void close() throws java.io.IOException
- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
- Throws:
java.io.IOException
-
getRandomAccessFile
public java.io.RandomAccessFile getRandomAccessFile()
-
-