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
public class ASMemoryInStream extends SeekableInputStream
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
Constructors Constructor Description ASMemoryInStream(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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intavailable()voidcloseResource()Closes stream.longgetOffset()Gets offset of current byte.ASInputStreamgetStream(long startOffset, long length)Gets substream of this stream that starts at given offset and has given length.longgetStreamLength()Gets total length of stream.booleanisCopiedBuffer()intpeek()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, incrementResourceUsers, isEOF, readByte, seekFromCurrentPosition, seekFromEnd, unread, unread
-
Methods inherited from class org.verapdf.as.io.ASInputStream
close, createStreamFromStream
-
Methods inherited from class java.io.InputStream
mark, markSupported, nullInputStream, read, read, readAllBytes, readNBytes, readNBytes, skip, transferTo
-
-
-
-
Constructor Detail
-
ASMemoryInStream
public ASMemoryInStream(byte[] buffer)
Constructor from byte array. Buffer is copied while initializing ASMemoryInStream.- Parameters:
buffer- byte array containing data.
-
ASMemoryInStream
public ASMemoryInStream(InputStream stream) throws IOException
Constructor from other stream. It reads stream into byte buffer.- Parameters:
stream- is stream to read into byte array.- Throws:
IOException
-
ASMemoryInStream
public ASMemoryInStream(ASMemoryInStream stream, int offset, int length)
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 Detail
-
read
public int read(byte[] buffer, int size) throws IOExceptionReads 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
public int read() throws IOExceptionReads single byte.- Specified by:
readin classASInputStream- Returns:
- byte read or -1 if end is reached.
- Throws:
IOException
-
peek
public int peek() throws IOExceptionGets next byte without reading it.- Specified by:
peekin classSeekableInputStream- Returns:
- next byte.
- Throws:
IOException
-
skip
public int skip(int size) throws IOExceptionSkips up to size bytes of data.- Specified by:
skipin classASInputStream- Parameters:
size- is amount of bytes to skip.- Returns:
- actual amount of bytes skipped.
- Throws:
IOException
-
closeResource
public void closeResource() throws IOExceptionCloses stream.- Specified by:
closeResourcein classASInputStream- Throws:
IOException
-
reset
public void reset() throws IOExceptionResets stream.- Specified by:
resetin classASInputStream- Throws:
IOException
-
getStreamLength
public long getStreamLength() throws IOExceptionGets total length of stream.- Specified by:
getStreamLengthin classSeekableInputStream- Returns:
- length of stream in bytes.
- Throws:
IOException
-
getOffset
public long getOffset() throws IOExceptionGets offset of current byte.- Specified by:
getOffsetin classSeekableInputStream- Returns:
- offset of byte to be read next.
- Throws:
IOException
-
seek
public void seek(long offset) throws IOExceptionDescription 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
public ASInputStream getStream(long startOffset, long length) throws IOException
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
-
-