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
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 TypeMethodDescriptionvoid
Method decrements number of resource users.abstract long
Gets offset of current byte.static SeekableInputStream
getSeekableStream
(InputStream stream) Returns InternalInputStream or ASMemoryInStream constructed from given stream depending on stream length.abstract ASInputStream
getStream
(long startOffset, long length) Gets substream of this stream that starts at given offset and has given length.abstract long
Gets total length of stream.void
Method increments number of resource users.boolean
isEOF()
abstract int
peek()
Gets next byte without reading it.byte
readByte()
Reads next byte from stream.abstract void
seek
(long offset) Goes to a particular byte in stream.void
seekFromCurrentPosition
(long pos) Sets reading pointer several bytes forward.void
seekFromEnd
(long pos) Seeks given number of bytes from the end of stream.void
unread()
Resets reading pointer one byte backwards.void
unread
(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, skipNBytes, transferTo
-
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
-
getStreamLength
Gets total length of stream.- Returns:
- length of stream in bytes.
- Throws:
IOException
-
peek
Gets next byte without reading it.- 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
-
incrementResourceUsers
public void incrementResourceUsers()Method increments number of resource users.- Specified by:
incrementResourceUsers
in classASInputStream
-
decrementResourceUsers
public void decrementResourceUsers()Description copied from class:ASInputStream
Method decrements number of resource users.- Specified by:
decrementResourceUsers
in classASInputStream
-
isEOF
- Returns:
- true if end of stream is reached.
- Throws:
IOException
-
unread
Resets reading pointer one byte backwards.- Throws:
IOException
-
unread
Resets reading pointer several bytes backwards.- 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.- 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
-