- All Superinterfaces:
AutoCloseable,Channel,Closeable,ReadableByteChannel
- All Known Subinterfaces:
OffsettableSeekableSource
- All Known Implementing Classes:
BaseSeekableSource,BufferedSeekableSource,ByteArraySeekableSource,FileChannelSeekableSource,MemoryMappedSeekableSource
Readable source that provides random access capabilities.
- Author:
- Andrea Vacondio
-
Method Summary
Modifier and TypeMethodDescriptiondefault InputStreamCreates anInputStreamfrom thisSeekableSource.default InputStreamCreates anInputStreamfrom thisSeekableSourceresetting the stream to the beginning.default SeekableSourceback()Skips backward moving back the source position of one bytedefault SeekableSourceback(long offset) Skips backward the given number of bytes moving back the source positiondefault SeekableSourceforward(long offset) Skips the given number of bytes moving forward the source positionid()default intpeek()Reads the next byte and sets the position back by one.default intpeekBack()Reads the previous byte and sets the position back where it was.longposition()position(long position) Sets the source position.intread()Reads a byte of data from this source.voiddefault voidreset()Resets stream back to beginninglongsize()view(long startingPosition, long length) Methods inherited from interface java.nio.channels.ReadableByteChannel
read
-
Method Details
-
id
String id()- Returns:
- the unique id for the source.
-
position
- Returns:
- the current source position as a positive long
- Throws:
IOException
-
position
Sets the source position. Setting the position to a value that is greater than the source's size is legal but does not change the size of the source. A later attempt to read bytes at such a position will immediately return an end-of-file indication.- Parameters:
position- a non-negative long for the new position- Returns:
- this source
- Throws:
IOException
-
size
long size()- Returns:
- The source size, measured in bytes
-
read
Reads a byte of data from this source. The byte is returned as an integer in the range 0 to 255 (0x00-0xff).- Returns:
- the next byte of data, or
-1if there is no more data. - Throws:
IOException
-
view
- Parameters:
startingPosition-length-- Returns:
- a readable view of a portion of this
SeekableSource. Reading from the view doesn't affect theSeekableSourceposition. Closing theSeekableSourcemakes all the views unreadable but closing the view has no effect on theSeekableSource. A view may or may not work on a thread bound copy of theSeekableSourceso as a general rule it should not be created and handed to other threads. - Throws:
IOException- if something goes wrong while creating the view
-
back
Skips backward the given number of bytes moving back the source position- Parameters:
offset- the number of bytes to skip back.- Returns:
- this source
- Throws:
IOException
-
back
Skips backward moving back the source position of one byte- Returns:
- this source
- Throws:
IOException- See Also:
-
forward
Skips the given number of bytes moving forward the source position- Parameters:
offset- the number of bytes to skip .- Returns:
- this source
- Throws:
IOException
-
peek
Reads the next byte and sets the position back by one.- Returns:
- the next byte or
-1if there is no more data. - Throws:
IOException- See Also:
-
peekBack
Reads the previous byte and sets the position back where it was.- Returns:
- the previous byte or
-1if we are at the beginning of the source. - Throws:
IOException- See Also:
-
asInputStream
Creates anInputStreamfrom thisSeekableSource.- Returns:
- the input stream wrapping the given
SeekableSource
-
reset
default void reset()Resets stream back to beginning -
requireOpen
- Throws:
IllegalStateException- if the source is closedIOException
-
asNewInputStream
Creates anInputStreamfrom thisSeekableSourceresetting the stream to the beginning.- Returns:
- the input stream wrapping the given
SeekableSource
-