Package com.mku.salmonfs.streams
Class AesFileInputStream
- java.lang.Object
-
- java.io.InputStream
-
- com.mku.salmonfs.streams.AesFileInputStream
-
- All Implemented Interfaces:
java.io.Closeable
,java.lang.AutoCloseable
public class AesFileInputStream extends java.io.InputStream
InputStream wrapper for seeking and reading an encrypted AesFile. This class provides a seekable source with parallel streams and cached buffers for performance.
-
-
Constructor Summary
Constructors Constructor Description AesFileInputStream(AesFile aesFile, int buffersCount, int bufferSize, int threads, int backOffset)
Instantiate a seekable stream from an encrypted file source
-
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.long
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.int
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.void
setPositionEnd(long pos)
Set the end position for the stream.void
setPositionStart(long pos)
Set the start position for the stream.long
skip(long bytes)
Skip a number of bytes.
-
-
-
Constructor Detail
-
AesFileInputStream
public AesFileInputStream(AesFile aesFile, int buffersCount, int bufferSize, int threads, int backOffset) throws java.io.IOException
Instantiate a seekable stream from an encrypted file source- Parameters:
aesFile
- The source file.buffersCount
- Number of buffers to use.bufferSize
- The length of each buffer.threads
- The number of threads/streams to source the file in parallel.backOffset
- The back offset.- Throws:
java.io.IOException
- Thrown if there is an IO error.
-
-
Method Detail
-
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.
-
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
-
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.
-
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.
-
-