Class RadInputStream
- java.lang.Object
-
- java.io.InputStream
-
- de.bernd_michaely.common.io.random.RadInputStream
-
- All Implemented Interfaces:
Closeable
,AutoCloseable
public class RadInputStream extends InputStream
InputStream based on a RandomAccessData data source. It provides a view to a subregion of the underlying data source through anInputStream
. The usage would happen typically in two stages:- Use a
RandomAccessData
instance directly to efficiently locate offset and length of the embedded data. - Create a RadInputStream object on the
RandomAccessData
instance to access the embedded data through anInputStream
.
RandomAccessData randomAccessData = RandomAccessDataFactory.createInstance(...); X3fImageData imageData = ... try (InputStream is = new RadInputStream( randomAccessData, imageData.getDataOffset(), imageData.getDataLength())) { ... }
-
-
Constructor Summary
Constructors Constructor Description RadInputStream(RandomAccessData randomAccessData)
Provides a view to the underlyingRandomAccessData
data source in full length as anInputStream
.RadInputStream(RandomAccessData randomAccessData, long offset, long length)
Provides a view to a subregion of the underlyingRandomAccessData
data source as anInputStream
.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
available()
void
close()
Closes this stream and releases any system resources associated with it.boolean
isClosed()
Returns true, if this stream has been closed.void
mark(int readlimit)
Remembers the current position of this stream.boolean
markSupported()
This input stream does not support marking with remembering of data.int
read()
int
read(byte[] b, int off, int len)
void
reset()
Repositions this stream to the last marked position.long
skip(long n)
Seeks efficiently relative to the current position to any offset within the data source.-
Methods inherited from class java.io.InputStream
nullInputStream, read, readAllBytes, readNBytes, readNBytes, transferTo
-
-
-
-
Constructor Detail
-
RadInputStream
public RadInputStream(RandomAccessData randomAccessData) throws RandomAccessDataException
Provides a view to the underlyingRandomAccessData
data source in full length as anInputStream
.- Parameters:
randomAccessData
- the underlying data source- Throws:
RandomAccessDataException
- if an error occurs during I/O operation
-
RadInputStream
public RadInputStream(RandomAccessData randomAccessData, long offset, long length) throws RandomAccessDataException
Provides a view to a subregion of the underlyingRandomAccessData
data source as anInputStream
.- Parameters:
randomAccessData
- the underlying data sourceoffset
- start index within the underlying data sourcelength
- the length in bytes of the view of the embedded data- Throws:
RandomAccessDataException
- if an error occurs during I/O operation
-
-
Method Detail
-
available
public int available() throws IOException
- Overrides:
available
in classInputStream
- Throws:
IOException
-
isClosed
public boolean isClosed()
Returns true, if this stream has been closed.- Returns:
- true, if this stream has been closed
-
close
public void close()
Closes this stream and releases any system resources associated with it. If the stream is already closed then invoking this method has no effect. Note, that this method does not close the underlyingRandomAccessData
object.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Overrides:
close
in classInputStream
-
mark
public void mark(int readlimit)
Remembers the current position of this stream. No data will be remembered. That is, after a call to reset(), subsequent reads may or may not re-read the same data, if the underlying data source has been written to.- Overrides:
mark
in classInputStream
- Parameters:
readlimit
- has no effect for this stream type
-
markSupported
public boolean markSupported()
This input stream does not support marking with remembering of data. It does however support efficient repositioning and skipping within the data source.- Overrides:
markSupported
in classInputStream
- Returns:
- false
-
read
public int read() throws IOException
- Specified by:
read
in classInputStream
- Throws:
IOException
-
read
public int read(byte[] b, int off, int len) throws IOException
- Overrides:
read
in classInputStream
- Throws:
IOException
-
reset
public void reset() throws IOException
Repositions this stream to the last marked position. It does not remember any data, that is, subsequent reads may or may not re-read the same data, if the underlying data source has been written to.- Overrides:
reset
in classInputStream
- Throws:
IOException
- if an error occurs during I/O operation
-
skip
public long skip(long n) throws IOException
Seeks efficiently relative to the current position to any offset within the data source. It is possible to jump backwards with negative values.- Overrides:
skip
in classInputStream
- Parameters:
n
- the number of bytes to seek, negative value to jump backwards- Returns:
- the number of bytes actually skipped
- Throws:
IOException
- if an error occurs during I/O operation
-
-