Package com.mku.salmon.streams
Class SalmonFileInputStream
java.lang.Object
java.io.InputStream
com.mku.salmon.streams.SalmonFileInputStream
- All Implemented Interfaces:
Closeable,AutoCloseable
Implementation of a Java InputStream for seeking and reading a SalmonFile.
This class provides a seekable source with parallel substreams and cached buffers
for performance.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classClass will be used to cache decrypted data that can later be read via the ReadAt() method without requesting frequent decryption reads. -
Constructor Summary
ConstructorsConstructorDescriptionSalmonFileInputStream(SalmonFile salmonFile, int buffersCount, int bufferSize, int threads, int backOffset) Instantiate a seekable stream from an encrypted file source -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Close the stream and associated backed streams and clear buffers.longlonggetSize()Get the size of the stream.intread()Read a byte from the stream.intread(byte[] buffer, int offset, int count) Reads and decrypts the contents of an encrypted filevoidreset()voidsetPositionEnd(long pos) voidsetPositionStart(long pos) longskip(long bytes) Skip a number of bytes.Methods inherited from class java.io.InputStream
available, mark, markSupported, nullInputStream, read, readAllBytes, readNBytes, readNBytes, skipNBytes, transferTo
-
Constructor Details
-
SalmonFileInputStream
public SalmonFileInputStream(SalmonFile salmonFile, int buffersCount, int bufferSize, int threads, int backOffset) throws IOException Instantiate a seekable stream from an encrypted file source- Parameters:
salmonFile- 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:
IOException- Thrown if there is an IO error.
-
-
Method Details
-
skip
public long skip(long bytes) Skip a number of bytes.- Overrides:
skipin classInputStream- Parameters:
bytes- the number of bytes to be skipped.- Returns:
- The byte skipped
-
reset
public void reset()- Overrides:
resetin classInputStream
-
read
Read a byte from the stream.- Specified by:
readin classInputStream- Returns:
- The bytes read
- Throws:
IOException- Thrown if there is an IO error.
-
read
Reads and decrypts the contents of an encrypted file- Overrides:
readin classInputStream- 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:
IOException
-
getSize
public long getSize()Get the size of the stream.- Returns:
- The size
-
getPositionStart
public long getPositionStart() -
setPositionStart
public void setPositionStart(long pos) -
setPositionEnd
public void setPositionEnd(long pos) -
close
Close the stream and associated backed streams and clear buffers.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein classInputStream- Throws:
IOException- Thrown if there is an IO error.
-