Package org.verapdf.as.io
Class ASMemoryInStream
java.lang.Object
java.io.InputStream
org.verapdf.as.io.ASInputStream
org.verapdf.io.SeekableInputStream
org.verapdf.as.io.ASMemoryInStream
- All Implemented Interfaces:
Closeable,AutoCloseable,BaseParserInputStream
This class binds the SeekableInputStream interface to a memory buffer.
- Author:
- Sergey Shemyakov
-
Field Summary
Fields inherited from class org.verapdf.as.io.ASInputStream
isClosed, isSourceClosed, resourceUsers -
Constructor Summary
ConstructorsConstructorDescriptionASMemoryInStream(byte[] buffer) Constructor from byte array.ASMemoryInStream(byte[] buffer, int bufferSize) Constructor from byte array and actual data length.ASMemoryInStream(byte[] buffer, int bufferSize, boolean copyBuffer) Constructor from byte array and actual data length.ASMemoryInStream(InputStream stream) Constructor from other stream.ASMemoryInStream(ASMemoryInStream stream, int offset, int length) Constructor that creates substream from other ASMemoryInStream. -
Method Summary
Modifier and TypeMethodDescriptionintvoidCloses stream.longlongGets offset of current byte.getSeekableStream(long startOffset, long length) getStream(long startOffset, long length) Gets substream of this stream that starts at given offset and has given length.longGets total length of stream.booleanvoidmark(int readlimit) booleanintpeek()Gets next byte without reading it.intread()Reads single byte.intread(byte[] buffer, int size) Reads up to size bytes of data into given array.voidreset()Resets stream.voidseek(long offset) Goes to a particular byte in stream.intskip(int size) Skips up to size bytes of data.Methods inherited from class org.verapdf.io.SeekableInputStream
decrementResourceUsers, getSeekableStream, getSeekableStream, incrementResourceUsers, isEOF, readByte, seekFromCurrentPosition, seekFromEnd, unread, unreadMethods inherited from class org.verapdf.as.io.ASInputStream
close, createStreamFromStreamMethods inherited from class java.io.InputStream
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
-
Constructor Details
-
ASMemoryInStream
public ASMemoryInStream(byte[] buffer) Constructor from byte array. Buffer is copied while initializing ASMemoryInStream.- Parameters:
buffer- byte array containing data.
-
ASMemoryInStream
Constructor from other stream. It reads stream into byte buffer.- Parameters:
stream- is stream to read into byte array.- Throws:
IOException
-
ASMemoryInStream
Constructor that creates substream from other ASMemoryInStream. Note that no buffer copy is performed.- Parameters:
stream- is stream, from which substream will be taken.offset- is beginning of data to copy.length- is length of data to copy.
-
ASMemoryInStream
public ASMemoryInStream(byte[] buffer, int bufferSize) Constructor from byte array and actual data length. Buffer is copied while initializing ASMemoryInStream.- Parameters:
buffer- byte array containing data.bufferSize- actual length of data in buffer.
-
ASMemoryInStream
public ASMemoryInStream(byte[] buffer, int bufferSize, boolean copyBuffer) Constructor from byte array and actual data length. Whether buffer is copied deeply or just reference is copied can be manually set.- Parameters:
buffer- byte array containing data.bufferSize- actual length of data in buffer.copyBuffer- is true if buffer should be copied deeply. Note that if it is set into false then internal buffer can be changed from outside of this class.
-
-
Method Details
-
getCurrentOffset
public long getCurrentOffset()- Specified by:
getCurrentOffsetin classSeekableInputStream
-
read
Reads up to size bytes of data into given array.- Specified by:
readin classASInputStream- Parameters:
buffer- is array into which data is read.size- is maximal amount of data that can be read.- Returns:
- actual amount of bytes reas.
- Throws:
IOException
-
read
Reads single byte.- Specified by:
readin interfaceBaseParserInputStream- Specified by:
readin classASInputStream- Returns:
- byte read or -1 if end is reached.
- Throws:
IOException
-
peek
Gets next byte without reading it.- Specified by:
peekin interfaceBaseParserInputStream- Specified by:
peekin classSeekableInputStream- Returns:
- next byte.
- Throws:
IOException
-
skip
Skips up to size bytes of data.- Specified by:
skipin interfaceBaseParserInputStream- Specified by:
skipin classASInputStream- Parameters:
size- is amount of bytes to skip.- Returns:
- actual amount of bytes skipped.
- Throws:
IOException
-
closeResource
Closes stream.- Specified by:
closeResourcein classASInputStream- Throws:
IOException
-
markSupported
public boolean markSupported()- Overrides:
markSupportedin classInputStream
-
mark
public void mark(int readlimit) - Overrides:
markin classInputStream
-
reset
Resets stream.- Specified by:
resetin classASInputStream- Throws:
IOException
-
getStreamLength
Gets total length of stream.- Specified by:
getStreamLengthin classSeekableInputStream- Returns:
- length of stream in bytes.
- Throws:
IOException
-
getOffset
Gets offset of current byte.- Specified by:
getOffsetin classSeekableInputStream- Returns:
- offset of byte to be read next.
- Throws:
IOException
-
seek
Description copied from class:SeekableInputStreamGoes to a particular byte in stream.- Specified by:
seekin classSeekableInputStream- Parameters:
offset- is offset of a byte to go to.- Throws:
IOException
-
available
public int available()- Overrides:
availablein classInputStream- Returns:
- the amount of bytes left in stream.
-
isCopiedBuffer
public boolean isCopiedBuffer()- Returns:
- true if internal buffer was copied deeply.
-
getStream
Description copied from class:SeekableInputStreamGets substream of this stream that starts at given offset and has given length.- Specified by:
getStreamin classSeekableInputStream- Parameters:
startOffset- is starting offset of substream.length- is length of substream.- Throws:
IOException
-
getSeekableStream
- Specified by:
getSeekableStreamin classSeekableInputStream- Throws:
IOException
-