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,BaseParserInputStream
- Direct Known Subclasses:
ASMemoryInStream,InternalInputStream
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 -
Method Summary
Modifier and TypeMethodDescriptionvoidMethod decrements number of resource users.abstract longabstract longGets offset of current byte.abstract SeekableInputStreamgetSeekableStream(long startOffset, long length) static SeekableInputStreamgetSeekableStream(InputStream stream) Returns InternalInputStream or ASMemoryInStream constructed from given stream depending on stream length.static SeekableInputStreamgetSeekableStream(InputStream stream, Integer maxStreamSize) abstract ASInputStreamgetStream(long startOffset, long length) Gets substream of this stream that starts at given offset and has given length.abstract longGets total length of stream.voidMethod 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, skipMethods inherited from class java.io.InputStream
available, mark, markSupported, nullInputStream, read, read, readAllBytes, readNBytes, readNBytes, skip, skipNBytes, transferToMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.verapdf.parser.BaseParserInputStream
close, read, read, skip
-
Constructor Details
-
SeekableInputStream
public SeekableInputStream()
-
-
Method Details
-
seek
Goes to a particular byte in stream.- Parameters:
offset- is offset of a byte to go to.- Throws:
IOException
-
getOffset
Gets offset of current byte.- Returns:
- offset of byte to be read next.
- Throws:
IOException
-
getCurrentOffset
public abstract long getCurrentOffset() -
getStreamLength
Gets total length of stream.- Returns:
- length of stream in bytes.
- Throws:
IOException
-
peek
Gets next byte without reading it.- Specified by:
peekin interfaceBaseParserInputStream- Returns:
- next byte.
- Throws:
IOException
-
getStream
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
-
getSeekableStream
public abstract SeekableInputStream getSeekableStream(long startOffset, long length) throws IOException - Throws:
IOException
-
incrementResourceUsers
public void incrementResourceUsers()Method increments number of resource users.- Specified by:
incrementResourceUsersin classASInputStream
-
decrementResourceUsers
public void decrementResourceUsers()Description copied from class:ASInputStreamMethod decrements number of resource users.- Specified by:
decrementResourceUsersin classASInputStream
-
isEOF
- Specified by:
isEOFin interfaceBaseParserInputStream- Returns:
- true if end of stream is reached.
- Throws:
IOException
-
unread
Resets reading pointer one byte backwards.- Specified by:
unreadin interfaceBaseParserInputStream- Throws:
IOException
-
unread
Resets reading pointer several bytes backwards.- Specified by:
unreadin interfaceBaseParserInputStream- Parameters:
count- is number of bytes to unread.- Throws:
IOException
-
seekFromCurrentPosition
Sets reading pointer several bytes forward.- Parameters:
pos- is amount of bytes to skip.- Throws:
IOException
-
seekFromEnd
Seeks 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
Reads next byte from stream.- Specified by:
readBytein interfaceBaseParserInputStream- Returns:
- the byte read.
- Throws:
IOException
-
getSeekableStream
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
-
getSeekableStream
public static SeekableInputStream getSeekableStream(InputStream stream, Integer maxStreamSize) throws IOException - Throws:
IOException
-