|
TrueZIP 6.8.2 | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectde.schlichtherle.io.rof.AbstractReadOnlyFile
de.schlichtherle.io.rof.FilterReadOnlyFile
de.schlichtherle.crypto.io.CipherReadOnlyFile
public abstract class CipherReadOnlyFile
A read only file for transparent random read access to an encrypted file.
The client must call 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 FilterReadOnlyFile.
| Field Summary | |
|---|---|
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. |
| Fields inherited from class de.schlichtherle.io.rof.FilterReadOnlyFile |
|---|
rof |
| Constructor Summary | |
|---|---|
CipherReadOnlyFile(ReadOnlyFile rof)
Creates a read only file for transparent random read access to an encrypted file. |
|
| Method Summary | |
|---|---|
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. |
private void |
ensureInit()
Ensures that this file is open and has been initialized. |
long |
getFilePointer()
|
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()
Ensures that the block with the decrypted data for partial reading is positioned so that it contains the current virtual file pointer in the encrypted file. |
private void |
positionWindow()
Ensures that the window is positioned 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)
Reads up to len bytes of data from this read only file into
the given array. |
void |
seek(long fp)
Sets the file pointer offset, measured from the beginning of this file, at which the next read occurs. |
| Methods inherited from class de.schlichtherle.io.rof.AbstractReadOnlyFile |
|---|
read, readFully, readFully, skipBytes |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
private static final int MAX_WINDOW_LEN
private long start
private long length
private long fp
private long windowOff
private byte[] window
MAX_WINDOW_LEN.
private SeekableBlockCipher cipher
private long blockOff
private byte[] block
private boolean closed
| Constructor Detail |
|---|
public CipherReadOnlyFile(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 init before
the call to init().| Method Detail |
|---|
private static final long min(long a,
long b)
public 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 FilterReadOnlyFile.rof is null
or cipher is null.
This exception is recoverable.
protected byte[] computeMac(Mac mac)
throws IOException
mac - A properly initialized MAC object.
IOException - On any I/O related issue.
public long length()
throws IOException
length in interface ReadOnlyFilelength in class FilterReadOnlyFileIOException
public long getFilePointer()
throws IOException
getFilePointer in interface ReadOnlyFilegetFilePointer in class FilterReadOnlyFileIOException
public void seek(long fp)
throws IOException
ReadOnlyFileSimpleReadOnlyFile subclasses
RandomAccessFile and passes "r" as a
parameter to the superclass constructor.
On the Windows platform, this implementation allows to seek past the
end of file, but on the Linux platform it doesn't.
seek in interface ReadOnlyFileseek in class FilterReadOnlyFilefp - The offset position, measured in bytes from the beginning
of the file, at which to set the file pointer.
IOException - If pos is less than 0 or if
an I/O error occurs.
public int read()
throws IOException
read in interface ReadOnlyFileread in class FilterReadOnlyFileIOException
public int read(byte[] buf,
int off,
int len)
throws IOException
ReadOnlyFilelen bytes of data from this read only file into
the given array.
This method blocks until at least one byte of input is available.
read in interface ReadOnlyFileread in class FilterReadOnlyFilebuf - The buffer to fill with data.off - The start offset of the data.len - The maximum number of bytes to read.
-1 if there is
no more data because the end of the file has been reached.
IOException - On any I/O related issue.
private final void ensureInit()
throws IOException
IOException - If the preconditions do not hold.
public void close()
throws IOException
IOException.
close in interface ReadOnlyFileclose in class FilterReadOnlyFileIOException - If an I/O error occurs.
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.
|
TrueZIP 6.8.2 | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||