Package org.verapdf.io
Class SeekableInputStream
- java.lang.Object
-
- java.io.InputStream
-
- org.verapdf.as.io.ASInputStream
-
- org.verapdf.io.SeekableInputStream
-
- All Implemented Interfaces:
Closeable,AutoCloseable
- Direct Known Subclasses:
ASMemoryInStream,InternalInputStream
public abstract class SeekableInputStream extends ASInputStream
Represents stream in which seek for a particular byte offset can be performed. On creation, contents of this stream should be written into file or memory buffer.- Author:
- Sergey Shemyakov
-
-
Field Summary
-
Fields inherited from class org.verapdf.as.io.ASInputStream
isClosed, isSourceClosed, resourceUsers
-
-
Constructor Summary
Constructors Constructor Description SeekableInputStream()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voiddecrementResourceUsers()Method decrements number of resource users.abstract longgetOffset()Gets offset of current byte.static SeekableInputStreamgetSeekableStream(InputStream stream)Returns InternalInputStream or ASMemoryInStream constructed from given stream depending on stream length.abstract ASInputStreamgetStream(long startOffset, long length)Gets substream of this stream that starts at given offset and has given length.abstract longgetStreamLength()Gets total length of stream.voidincrementResourceUsers()Method increments number of resource users.booleanisEOF()abstract intpeek()Gets next byte without reading it.bytereadByte()Reads next byte from stream.abstract voidseek(long offset)Goes to a particular byte in stream.voidseekFromCurrentPosition(long pos)Sets reading pointer several bytes forward.voidseekFromEnd(long pos)Seeks given number of bytes from the end of stream.voidunread()Resets reading pointer one byte backwards.voidunread(int count)Resets reading pointer several bytes backwards.-
Methods inherited from class org.verapdf.as.io.ASInputStream
close, closeResource, createStreamFromStream, read, read, reset, skip
-
Methods inherited from class java.io.InputStream
available, mark, markSupported, nullInputStream, read, read, readAllBytes, readNBytes, readNBytes, skip, transferTo
-
-
-
-
Method Detail
-
seek
public abstract void seek(long offset) throws IOExceptionGoes to a particular byte in stream.- Parameters:
offset- is offset of a byte to go to.- Throws:
IOException
-
getOffset
public abstract long getOffset() throws IOExceptionGets offset of current byte.- Returns:
- offset of byte to be read next.
- Throws:
IOException
-
getStreamLength
public abstract long getStreamLength() throws IOExceptionGets total length of stream.- Returns:
- length of stream in bytes.
- Throws:
IOException
-
peek
public abstract int peek() throws IOExceptionGets next byte without reading it.- Returns:
- next byte.
- Throws:
IOException
-
getStream
public abstract ASInputStream getStream(long startOffset, long length) throws IOException
Gets substream of this stream that starts at given offset and has given length.- Parameters:
startOffset- is starting offset of substream.length- is length of substream.- Throws:
IOException
-
incrementResourceUsers
public void incrementResourceUsers()
Method increments number of resource users. {@see closeResource}- Specified by:
incrementResourceUsersin classASInputStream
-
decrementResourceUsers
public void decrementResourceUsers()
Description copied from class:ASInputStreamMethod decrements number of resource users. {@see closeResource}- Specified by:
decrementResourceUsersin classASInputStream
-
isEOF
public boolean isEOF() throws IOException- Returns:
- true if end of stream is reached.
- Throws:
IOException
-
unread
public void unread() throws IOExceptionResets reading pointer one byte backwards.- Throws:
IOException
-
unread
public void unread(int count) throws IOExceptionResets reading pointer several bytes backwards.- Parameters:
count- is number of bytes to unread.- Throws:
IOException
-
seekFromCurrentPosition
public void seekFromCurrentPosition(long pos) throws IOExceptionSets reading pointer several bytes forward.- Parameters:
pos- is amount of bytes to skip.- Throws:
IOException
-
seekFromEnd
public void seekFromEnd(long pos) throws IOExceptionSeeks given number of bytes from the end of stream.- Parameters:
pos- is a number of bytes to seek from the end of stream.- Throws:
IOException
-
readByte
public byte readByte() throws IOExceptionReads next byte from stream.- Returns:
- the byte read.
- Throws:
IOException
-
getSeekableStream
public static SeekableInputStream getSeekableStream(InputStream stream) throws IOException
Returns InternalInputStream or ASMemoryInStream constructed from given stream depending on stream length.- Parameters:
stream- is stream to turn into seekable stream.- Returns:
- SeekableStream that contains data of passed stream.
- Throws:
IOException
-
-