@NotThreadSafe public abstract class CipherReadOnlyFile extends DecoratingReadOnlyFile
init(SeekableBlockCipher, long, long)
before it can actually read anything!
Note that this class implements its own virtual file pointer.
Thus, if you would like to access the underlying ReadOnlyFile
again after you have finished working with an instance of this class,
you should synchronize their file pointers using the pattern as described
in the base class DecoratingReadOnlyFile.
CipherOutputStream| Modifier and Type | Field and Description |
|---|---|
private byte[] |
block
The buffer for the decrypted file data.
|
private long |
blockStart
The current offset in the encrypted file where the data starts that
has been decrypted to the block.
|
private byte[] |
buffer
The buffer for the encrypted file data.
|
private long |
bufferStart
The current offset in the encrypted file where the buffer window starts.
|
private SeekableBlockCipher |
cipher
The seekable block cipher which allows random access.
|
private static long |
INVALID |
private long |
length
The length of the encrypted data.
|
private long |
pos
The virtual file pointer in the encrypted data.
|
private long |
start
Start offset of the encrypted data.
|
delegate| Modifier | Constructor and Description |
|---|---|
protected |
CipherReadOnlyFile(ReadOnlyFile rof)
Creates a read only file for transparent random read access to an
encrypted file.
|
| Modifier and Type | Method and Description |
|---|---|
private void |
checkOpen()
Asserts that this cipher output stream is in open state, which requires
that
cipher is not null. |
void |
close()
Closes this read only file and releases any resources associated with it.
|
protected byte[] |
computeMac(Mac mac)
Returns the authentication code of the encrypted data in this cipher
read-only file using the given Message Authentication Code (MAC) object.
|
long |
getFilePointer() |
protected void |
init(SeekableBlockCipher cipher,
long start,
long length)
Initializes this cipher read only file - must be called before first
read access!
|
long |
length() |
private void |
positionBlock()
Positions the block with the decrypted data for partial reading so that
it contains the current virtual file pointer in the encrypted file.
|
private void |
positionBuffer()
Positions the window so that the block containing
the current virtual file pointer in the encrypted file is entirely
contained in it.
|
int |
read() |
int |
read(byte[] dst,
int offset,
int remaining) |
void |
seek(long pos) |
toStringread, readFully, readFullyprivate byte[] block
private long blockStart
private byte[] buffer
private long bufferStart
@Nullable private SeekableBlockCipher cipher
private static final long INVALID
private long length
private long pos
private long start
@CreatesObligation protected CipherReadOnlyFile(@Nullable@WillCloseWhenClosed ReadOnlyFile rof)
init(SeekableBlockCipher, long, long)
before it can actually read anything!rof - A read-only file.
This may be null, but must be properly initialized
before a call to init(de.schlichtherle.truezip.crypto.SeekableBlockCipher, long, long).private void checkOpen()
throws IOException
cipher is not null.IOException - If the preconditions do not hold.public void close()
throws IOException
IOException.close in interface ReadOnlyFileclose in interface Closeableclose in interface AutoCloseableclose in class DecoratingReadOnlyFileIOException - If an I/O error occurs.protected byte[] computeMac(Mac mac) throws IOException
mac - a properly initialized MAC object.IOException - on any I/O error.public long getFilePointer()
throws IOException
getFilePointer in interface ReadOnlyFilegetFilePointer in class DecoratingReadOnlyFileIOExceptionprotected final void init(SeekableBlockCipher cipher, long start, long length) throws IOException
cipher - the seekable block cipher.start - the start offset of the encrypted data in this file.length - the length of the encrypted data in this file.IOException - If this read only file has already been closed.
This exception is not recoverable.IllegalStateException - if DecoratingReadOnlyFile.delegate is null or
if this object has already been initialized.IllegalArgumentException - if cipher is null or
if start or length are less than zero.public long length()
throws IOException
length in interface ReadOnlyFilelength in class DecoratingReadOnlyFileIOExceptionprivate void positionBlock()
throws IOException
IOException - on any I/O error.
The block is not moved in this case.private void positionBuffer()
throws IOException
IOException - on any I/O error.
The buffer gets invalidated in this case.public int read()
throws IOException
read in interface ReadOnlyFileread in class DecoratingReadOnlyFileIOExceptionpublic int read(byte[] dst,
int offset,
int remaining)
throws IOException
read in interface ReadOnlyFileread in class DecoratingReadOnlyFileIOExceptionpublic void seek(long pos)
throws IOException
seek in interface ReadOnlyFileseek in class DecoratingReadOnlyFileIOExceptionCopyright © 2005-2012 Schlichtherle IT Services. All Rights Reserved.