Package gov.nih.mipav.model.file
Class MetadataExtractor.RandomAccessFileReader
java.lang.Object
gov.nih.mipav.model.file.MetadataExtractor.RandomAccessReader
gov.nih.mipav.model.file.MetadataExtractor.RandomAccessFileReader
- Enclosing class:
MetadataExtractor
Provides methods to read specific values from a
RandomAccessFile, with a consistent, checked exception structure for
issues.- Author:
- Drew Noakes https://drewnoakes.com
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final intprivate intprivate final RandomAccessFileprivate final long -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbytegetByte(int index) Gets the byte value at the specified byteindex.byte[]getBytes(int index, int count) Returns the required number of bytes from the specified index from the underlying source.longReturns the length of the data source in bytes.protected booleanisValidIndex(int index, int bytesRequested) private voidseek(int index) inttoUnshiftedOffset(int localOffset) protected voidvalidateIndex(int index, int bytesRequested) Ensures that the buffered bytes extend to cover the specified index.Methods inherited from class gov.nih.mipav.model.file.MetadataExtractor.RandomAccessReader
getBit, getDouble64, getFloat32, getInt16, getInt24, getInt32, getInt64, getInt8, getNullTerminatedBytes, getNullTerminatedString, getNullTerminatedStringValue, getS15Fixed16, getString, getString, getStringValue, getUInt16, getUInt32, getUInt8, isMotorolaByteOrder, setMotorolaByteOrder
-
Field Details
-
_file
-
_length
private final long _length -
_currentIndex
private int _currentIndex -
_baseOffset
private final int _baseOffset
-
-
Constructor Details
-
RandomAccessFileReader
- Throws:
IOException
-
RandomAccessFileReader
- Throws:
IOException
-
-
Method Details
-
toUnshiftedOffset
public int toUnshiftedOffset(int localOffset) - Specified by:
toUnshiftedOffsetin classMetadataExtractor.RandomAccessReader
-
getLength
public long getLength()Description copied from class:MetadataExtractor.RandomAccessReaderReturns the length of the data source in bytes.This is a simple operation for implementations (such as
MetadataExtractor.RandomAccessFileReaderandMetadataExtractor.ByteArrayReader) that have the entire data source available.Users of this method must be aware that sequentially accessed implementations such as
MetadataExtractor.RandomAccessStreamReaderwill have to read and buffer the entire data source in order to determine the length.- Specified by:
getLengthin classMetadataExtractor.RandomAccessReader- Returns:
- the length of the data source, in bytes.
-
getByte
Description copied from class:MetadataExtractor.RandomAccessReaderGets the byte value at the specified byteindex.Implementations should not perform any bounds checking in this method. That should be performed in
validateIndexandisValidIndex.- Specified by:
getBytein classMetadataExtractor.RandomAccessReader- Parameters:
index- The index from which to read the byte- Returns:
- The read byte value
- Throws:
IOException- if the byte is unable to be read
-
getBytes
Description copied from class:MetadataExtractor.RandomAccessReaderReturns the required number of bytes from the specified index from the underlying source.- Specified by:
getBytesin classMetadataExtractor.RandomAccessReader- Parameters:
index- The index from which the bytes begins in the underlying sourcecount- The number of bytes to be returned- Returns:
- The requested bytes
- Throws:
IOException- if the byte is unable to be read
-
seek
- Throws:
IOException
-
isValidIndex
- Specified by:
isValidIndexin classMetadataExtractor.RandomAccessReader- Throws:
IOException
-
validateIndex
Description copied from class:MetadataExtractor.RandomAccessReaderEnsures that the buffered bytes extend to cover the specified index. If not, an attempt is made to read to that point.If the stream ends before the point is reached, a
MetadataExtractor.BufferBoundsExceptionis raised.- Specified by:
validateIndexin classMetadataExtractor.RandomAccessReader- Parameters:
index- the index from which the required bytes startbytesRequested- the number of bytes which are required- Throws:
IOException- if the stream ends before the required number of bytes are acquired
-