Package com.mku.streams
Class InputStreamWrapper
java.lang.Object
java.io.InputStream
com.mku.streams.InputStreamWrapper
- All Implemented Interfaces:
Closeable
,AutoCloseable
Wrapper stream of RandomAccessStream to a native InputStream implementation.
Use this class to wrap any RandomAccessStream to a Java InputStream.
-
Constructor Summary
ConstructorDescriptionInputStreamWrapper
(RandomAccessStream stream) Instantiates an InputStreamWrapper from a RandomAccessStream. -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Closes the base stream.int
read()
Read a byte from the stream.int
read
(byte[] buffer, int offset, int count) Read a sequance of bytes from the base stream into the buffer provided.void
reset()
Reset the stream.long
skip
(long pos) Skip number of bytes on the stream.Methods inherited from class java.io.InputStream
available, mark, markSupported, nullInputStream, read, readAllBytes, readNBytes, readNBytes, skipNBytes, transferTo
-
Constructor Details
-
InputStreamWrapper
Instantiates an InputStreamWrapper from a RandomAccessStream.- Parameters:
stream
- The stream that you want to wrap.
-
-
Method Details
-
read
Read a byte from the stream. Blocking is dependent on the base stream.- Specified by:
read
in classInputStream
- Returns:
- -1 if there are no more bytes from the stream otherwise the next byte value (0-255).
- Throws:
IOException
- Thrown if there is an IO error.
-
read
Read a sequance of bytes from the base stream into the buffer provided.- Overrides:
read
in classInputStream
- Parameters:
buffer
- the buffer into which the data is read.offset
- the start offset in arrayb
at which the data is written.count
- the maximum number of bytes to read.- Returns:
- The number of bytes read.
- Throws:
IOException
- with an optional inner Exception if the base stream is a SalmonStream
-
close
Closes the base stream.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Overrides:
close
in classInputStream
- Throws:
IOException
- Thrown if there is an IO error.
-
reset
Reset the stream.- Overrides:
reset
in classInputStream
- Throws:
IOException
- Thrown if there is an IO error.
-
skip
Skip number of bytes on the stream.- Overrides:
skip
in classInputStream
- Parameters:
pos
- the number of bytes to be skipped.- Returns:
- The number of bytes that were skipped.
- Throws:
IOException
- Thrown if there is an IO error.
-