Package com.mku.streams
Class InputStreamWrapper
- java.lang.Object
-
- java.io.InputStream
-
- com.mku.streams.InputStreamWrapper
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable
public class InputStreamWrapper extends java.io.InputStreamInputStream wrapper for RandomAccessStream. Use this class to wrap any RandomAccessStream to a Java InputStream to use with 3rd party libraries.
-
-
Constructor Summary
Constructors Constructor Description InputStreamWrapper(RandomAccessStream stream)Instantiates an InputStreamWrapper from a RandomAccessStream.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()Closes the base stream.intread()Read a byte from the stream.intread(byte[] buffer, int offset, int count)Read a sequance of bytes from the base stream into the buffer provided.voidreset()Reset the stream.longskip(long pos)Skip number of bytes on the stream.
-
-
-
Constructor Detail
-
InputStreamWrapper
public InputStreamWrapper(RandomAccessStream stream)
Instantiates an InputStreamWrapper from a RandomAccessStream.- Parameters:
stream- The stream that you want to wrap.
-
-
Method Detail
-
read
public int read() throws java.io.IOExceptionRead a byte from the stream. Blocking is dependent on the base stream.- Specified by:
readin classjava.io.InputStream- Returns:
- -1 if there are no more bytes from the stream otherwise the next byte value (0-255).
- Throws:
java.io.IOException- Thrown if there is an IO error.
-
read
public int read(byte[] buffer, int offset, int count) throws java.io.IOExceptionRead a sequance of bytes from the base stream into the buffer provided.- Overrides:
readin classjava.io.InputStream- Parameters:
buffer- the buffer into which the data is read.offset- the start offset in arraybat which the data is written.count- the maximum number of bytes to read.- Returns:
- The number of bytes read.
- Throws:
java.io.IOException- with an optional inner Exception if the base stream is a AesStream
-
close
public void close() throws java.io.IOExceptionCloses the base stream.- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Overrides:
closein classjava.io.InputStream- Throws:
java.io.IOException- Thrown if there is an IO error.
-
reset
public void reset() throws java.io.IOExceptionReset the stream.- Overrides:
resetin classjava.io.InputStream- Throws:
java.io.IOException- Thrown if there is an IO error.
-
skip
public long skip(long pos) throws java.io.IOExceptionSkip number of bytes on the stream.- Overrides:
skipin classjava.io.InputStream- Parameters:
pos- the number of bytes to be skipped.- Returns:
- The number of bytes that were skipped.
- Throws:
java.io.IOException- Thrown if there is an IO error.
-
-