@NotThreadSafe @DefaultAnnotation(value=edu.umd.cs.findbugs.annotations.NonNull.class) 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 block buffer to use for decryption of partial blocks.
|
private long |
blockOff
The current offset in the encrypted file where the data starts that
has been decrypted to the block.
|
private SeekableBlockCipher |
cipher
The seekable block cipher which allows random access.
|
private boolean |
closed
Whether this read only file has been closed or not.
|
private long |
fp
The virtual file pointer in the encrypted data.
|
private long |
length
The length of the encrypted data.
|
private static int |
MAX_WINDOW_LEN
The maximum buffer length of the window to the encrypted file.
|
private long |
start
Start offset of the encrypted data.
|
private byte[] |
window
The buffer window to the encrypted file.
|
private long |
windowOff
The current offset in the encrypted file where the buffer window starts.
|
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 |
assertOpen()
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 static long |
min(long a,
long b)
Returns the smaller parameter.
|
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 |
positionWindow()
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[] buf,
int off,
int len) |
void |
seek(long fp) |
toStringread, readFully, readFullyprivate byte[] block
private long blockOff
@Nullable private SeekableBlockCipher cipher
private boolean closed
private long fp
private long length
private static final int MAX_WINDOW_LEN
private long start
private byte[] window
MAX_WINDOW_LEN.private long windowOff
protected CipherReadOnlyFile(@Nullable 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 assertOpen()
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 related issue.public long getFilePointer()
throws IOException
getFilePointer in interface ReadOnlyFilegetFilePointer in class DecoratingReadOnlyFileIOExceptionprotected final void init(SeekableBlockCipher cipher, long start, long length) throws IOException
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 this object has already been
initialized.
This exception is not recoverable.NullPointerException - If DecoratingReadOnlyFile.delegate or cipher is
null.
This exception is recoverable.public long length()
throws IOException
length in interface ReadOnlyFilelength in class DecoratingReadOnlyFileIOExceptionprivate static long min(long a,
long b)
private void positionBlock()
throws IOException
IOException - On any I/O related issue.
The block is not moved in this case.private void positionWindow()
throws IOException
IOException - On any I/O related issue.
The window is invalidated in this case.public int read()
throws IOException
read in interface ReadOnlyFileread in class DecoratingReadOnlyFileIOExceptionpublic int read(byte[] buf,
int off,
int len)
throws IOException
read in interface ReadOnlyFileread in class DecoratingReadOnlyFileIOExceptionpublic void seek(long fp)
throws IOException
seek in interface ReadOnlyFileseek in class DecoratingReadOnlyFileIOExceptionCopyright © 2004-2011 Schlichtherle IT Services. All Rights Reserved.