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
- Direct Known Subclasses:
AesFileInputStream
public class InputStreamWrapper extends java.io.InputStream
InputStream wrapper for RandomAccessStream. Use this class to wrap any RandomAccessStream to a Java InputStream to use with 3rd party libraries.
-
-
Field Summary
Fields Modifier and Type Field Description static int
DEFAULT_BACK_OFFSET
The default backwards buffer offsetstatic int
DEFAULT_BUFFER_SIZE
Default cache buffer should be high enough for some mpeg videos to work the cache buffers should be aligned to the AesFile chunk size for efficiencystatic int
DEFAULT_BUFFERS
The default buffer countprotected static int
MAX_BUFFERS
The maximum allowed buffer count
-
Constructor Summary
Constructors Constructor Description InputStreamWrapper(RandomAccessStream stream)
Instantiates an InputStreamWrapper from a RandomAccessStream.InputStreamWrapper(RandomAccessStream stream, int buffersCount, int bufferSize, int backOffset)
Instantiates an InputStreamWrapper from a RandomAccessStream with buffer options.InputStreamWrapper(RandomAccessStream stream, int buffersCount, int bufferSize, int backOffset, int alignSize)
Instantiates an InputStreamWrapper from a RandomAccessStream with buffer options.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
Close the stream and associated backed streams and clear buffers.protected int
fillBuffer(Buffer cacheBuffer, long startPosition, int length)
Fills a cache buffer with the decrypted data from the encrypted source file.protected int
fillBufferPart(Buffer cacheBuffer, long start, int offset, int length, RandomAccessStream stream)
Fills a cache buffer with the decrypted data from a part of an encrypted fileint
getAlignSize()
Get the align sizeint
getBackOffset()
protected int
getBuffersCount()
Get the buffers countint
getBufferSize()
Get the buffer sizelong
getLength()
Get the size of the stream.long
getPositionEnd()
Get the end position for the stream.long
getPositionStart()
Get the start position for the stream.long
getTotalSize()
Get the total sizeint
read()
Read a byte from the stream.int
read(byte[] buffer, int offset, int count)
Reads and decrypts the contents of an encrypted filevoid
reset()
Reset the stream.protected void
setBackOffset(int backOffset)
protected void
setBuffersCount(int buffersCount)
Set the buffers countvoid
setPositionEnd(long pos)
Set the end position for the stream.void
setPositionStart(long pos)
Set the start position for the stream.protected void
setTotalSize(long totalSize)
Set the total sizelong
skip(long bytes)
Skip a number of bytes.
-
-
-
Field Detail
-
DEFAULT_BUFFER_SIZE
public static final int DEFAULT_BUFFER_SIZE
Default cache buffer should be high enough for some mpeg videos to work the cache buffers should be aligned to the AesFile chunk size for efficiency- See Also:
- Constant Field Values
-
DEFAULT_BUFFERS
public static final int DEFAULT_BUFFERS
The default buffer count- See Also:
- Constant Field Values
-
DEFAULT_BACK_OFFSET
public static final int DEFAULT_BACK_OFFSET
The default backwards buffer offset- See Also:
- Constant Field Values
-
MAX_BUFFERS
protected static final int MAX_BUFFERS
The maximum allowed buffer count- See Also:
- Constant Field Values
-
-
Constructor Detail
-
InputStreamWrapper
public InputStreamWrapper(RandomAccessStream stream)
Instantiates an InputStreamWrapper from a RandomAccessStream.- Parameters:
stream
- The stream that you want to wrap.
-
InputStreamWrapper
public InputStreamWrapper(RandomAccessStream stream, int buffersCount, int bufferSize, int backOffset)
Instantiates an InputStreamWrapper from a RandomAccessStream with buffer options.- Parameters:
stream
- The stream that you want to wrap.buffersCount
- The number of buffers to usebufferSize
- The buffer sizebackOffset
- The back offset
-
InputStreamWrapper
public InputStreamWrapper(RandomAccessStream stream, int buffersCount, int bufferSize, int backOffset, int alignSize)
Instantiates an InputStreamWrapper from a RandomAccessStream with buffer options.- Parameters:
stream
- The stream that you want to wrap.buffersCount
- The number of buffers to usebufferSize
- The buffer sizebackOffset
- The back offsetalignSize
- The align size
-
-
Method Detail
-
getBufferSize
public int getBufferSize()
Get the buffer size- Returns:
- The buffer size
-
getTotalSize
public long getTotalSize()
Get the total size- Returns:
- The total size
-
setTotalSize
protected void setTotalSize(long totalSize)
Set the total size- Parameters:
totalSize
- The total size
-
getAlignSize
public int getAlignSize()
Get the align size- Returns:
- The align size
-
skip
public long skip(long bytes)
Skip a number of bytes.- Overrides:
skip
in classjava.io.InputStream
- Parameters:
bytes
- the number of bytes to be skipped.- Returns:
- The byte skipped
-
reset
public void reset()
Reset the stream.- Overrides:
reset
in classjava.io.InputStream
-
read
public int read() throws java.io.IOException
Read a byte from the stream.- Specified by:
read
in classjava.io.InputStream
- Returns:
- The bytes read
- Throws:
java.io.IOException
- Thrown if there is an IO error.
-
getBackOffset
public int getBackOffset()
-
setBackOffset
protected void setBackOffset(int backOffset)
-
read
public int read(byte[] buffer, int offset, int count) throws java.io.IOException
Reads and decrypts the contents of an encrypted file- Overrides:
read
in classjava.io.InputStream
- Parameters:
buffer
- The buffer that will store the decrypted contentsoffset
- The position on the buffer that the decrypted data will startcount
- The length of the data requested- Throws:
java.io.IOException
-
fillBuffer
protected int fillBuffer(Buffer cacheBuffer, long startPosition, int length) throws java.io.IOException
Fills a cache buffer with the decrypted data from the encrypted source file.- Parameters:
cacheBuffer
- The cache buffer that will store the decrypted contentsstartPosition
- The start positionlength
- The length of the data requested- Returns:
- The number of bytes read
- Throws:
java.io.IOException
- When IO error occurs
-
fillBufferPart
protected int fillBufferPart(Buffer cacheBuffer, long start, int offset, int length, RandomAccessStream stream) throws java.io.IOException
Fills a cache buffer with the decrypted data from a part of an encrypted file- Parameters:
cacheBuffer
- The cache buffer that will store the decrypted contentsstart
- The start positionoffset
- The offsetlength
- The length of the data requestedstream
- The stream that will be used to read from- Returns:
- The number of total bytes read.
- Throws:
java.io.IOException
- When IO error occurs
-
getLength
public long getLength()
Get the size of the stream.- Returns:
- The size
-
getPositionStart
public long getPositionStart()
Get the start position for the stream.- Returns:
- The start position.
-
setPositionStart
public void setPositionStart(long pos)
Set the start position for the stream.- Parameters:
pos
- The start position.
-
getPositionEnd
public long getPositionEnd()
Get the end position for the stream.- Returns:
- The end position.
-
setPositionEnd
public void setPositionEnd(long pos)
Set the end position for the stream.- Parameters:
pos
- The end position.
-
getBuffersCount
protected int getBuffersCount()
Get the buffers count- Returns:
- The buffers count
-
setBuffersCount
protected void setBuffersCount(int buffersCount)
Set the buffers count- Parameters:
buffersCount
- The buffers count
-
close
public void close() throws java.io.IOException
Close the stream and associated backed streams and clear buffers.- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
- Overrides:
close
in classjava.io.InputStream
- Throws:
java.io.IOException
- Thrown if there is an IO error.
-
-