Package gov.nih.mipav.model.file
Class MetadataExtractor.RandomAccessStreamReader
- java.lang.Object
-
- gov.nih.mipav.model.file.MetadataExtractor.RandomAccessReader
-
- gov.nih.mipav.model.file.MetadataExtractor.RandomAccessStreamReader
-
- Enclosing class:
- MetadataExtractor
public class MetadataExtractor.RandomAccessStreamReader extends MetadataExtractor.RandomAccessReader
- Author:
- Drew Noakes https://drewnoakes.com
-
-
Field Summary
Fields Modifier and Type Field Description private int_chunkLengthprivate java.util.ArrayList<byte[]>_chunksprivate boolean_isStreamFinishedprivate java.io.InputStream_streamprivate long_streamLengthstatic intDEFAULT_CHUNK_LENGTH
-
Constructor Summary
Constructors Constructor Description RandomAccessStreamReader(java.io.InputStream stream)RandomAccessStreamReader(java.io.InputStream stream, int chunkLength)RandomAccessStreamReader(java.io.InputStream stream, int chunkLength, long streamLength)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description bytegetByte(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.longgetLength()Reads to the end of the stream, in order to determine the total number of bytes.protected booleanisValidIndex(int index, int bytesRequested)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 Detail
-
DEFAULT_CHUNK_LENGTH
public static final int DEFAULT_CHUNK_LENGTH
- See Also:
- Constant Field Values
-
_stream
private final java.io.InputStream _stream
-
_chunkLength
private final int _chunkLength
-
_chunks
private final java.util.ArrayList<byte[]> _chunks
-
_isStreamFinished
private boolean _isStreamFinished
-
_streamLength
private long _streamLength
-
-
Constructor Detail
-
RandomAccessStreamReader
public RandomAccessStreamReader(java.io.InputStream stream)
-
RandomAccessStreamReader
public RandomAccessStreamReader(java.io.InputStream stream, int chunkLength)
-
RandomAccessStreamReader
public RandomAccessStreamReader(java.io.InputStream stream, int chunkLength, long streamLength)
-
-
Method Detail
-
getLength
public long getLength() throws java.io.IOExceptionReads to the end of the stream, in order to determine the total number of bytes. In general, this is not a good idea for this implementation ofMetadataExtractor.RandomAccessReader.- Specified by:
getLengthin classMetadataExtractor.RandomAccessReader- Returns:
- the length of the data source, in bytes.
- Throws:
java.io.IOException
-
validateIndex
protected void validateIndex(int index, int bytesRequested) throws java.io.IOExceptionEnsures 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:
MetadataExtractor.BufferBoundsException- if the stream ends before the required number of bytes are acquiredjava.io.IOException- if the stream ends before the required number of bytes are acquired
-
isValidIndex
protected boolean isValidIndex(int index, int bytesRequested) throws java.io.IOException- Specified by:
isValidIndexin classMetadataExtractor.RandomAccessReader- Throws:
java.io.IOException
-
toUnshiftedOffset
public int toUnshiftedOffset(int localOffset)
- Specified by:
toUnshiftedOffsetin classMetadataExtractor.RandomAccessReader
-
getByte
public byte getByte(int index) throws java.io.IOExceptionDescription 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:
MetadataExtractor.BufferBoundsException- if the requested byte is beyond the end of the underlying data sourcejava.io.IOException- if the byte is unable to be read
-
getBytes
public byte[] getBytes(int index, int count) throws java.io.IOExceptionDescription 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:
MetadataExtractor.BufferBoundsException- if the requested bytes extend beyond the end of the underlying data sourcejava.io.IOException- if the byte is unable to be read
-
-