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
Modifier and TypeClassDescriptionstatic class
Class will be used to cache decrypted data that can later be read via the ReadAt() method without requesting frequent decryption reads. -
Constructor Summary
ConstructorDescriptionSalmonFileInputStream
(SalmonFile salmonFile, int buffersCount, int bufferSize, int threads, int backOffset) Instantiate a seekable stream from an encrypted file source -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Close the stream and associated backed streams and clear buffers.long
long
getSize()
Get the size of 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()
void
setPositionEnd
(long pos) void
setPositionStart
(long pos) long
skip
(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:
skip
in classInputStream
- Parameters:
bytes
- the number of bytes to be skipped.- Returns:
- The byte skipped
-
reset
public void reset()- Overrides:
reset
in classInputStream
-
read
Read a byte from the stream.- Specified by:
read
in 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:
read
in 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:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Overrides:
close
in classInputStream
- Throws:
IOException
- Thrown if there is an IO error.
-