@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.
CipherOutputStreamdelegate| 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 |
|---|---|
void |
close()
Closes this read only file and releases any resources associated with it.
|
protected byte[] |
computeMac(org.bouncycastle.crypto.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()
Returns the current byte position in the file as a zero-based index.
|
protected void |
init(SeekableBlockCipher cipher,
long start,
long length)
Initializes this cipher read only file - must be called before first
read access!
|
long |
length()
Returns the length of the file in bytes.
|
int |
read()
Reads and returns the next byte or -1 if the end of the file has been
reached.
|
int |
read(byte[] dst,
int offset,
int remaining)
Reads up to
len bytes of data from this read only file into
the given array. |
void |
seek(long pos)
Sets the current byte position in the file as a zero-based index at
which the next read occurs.
|
toStringread, readFully, readFully@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).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(org.bouncycastle.crypto.Mac mac)
throws IOException
mac - a properly initialized MAC object.IOException - on any I/O error.public long getFilePointer()
throws IOException
ReadOnlyFilegetFilePointer in interface ReadOnlyFilegetFilePointer in class DecoratingReadOnlyFileIOException - On any I/O failure.protected 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
ReadOnlyFilelength in interface ReadOnlyFilelength in class DecoratingReadOnlyFileIOException - On any I/O failure.public int read()
throws IOException
ReadOnlyFileread in interface ReadOnlyFileread in class DecoratingReadOnlyFileIOException - On any I/O failure.public int read(byte[] dst,
int offset,
int remaining)
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 unless
len is zero.read in interface ReadOnlyFileread in class DecoratingReadOnlyFiledst - The buffer to fill with data.offset - The start offset of the data.remaining - 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 failure.public void seek(long pos)
throws IOException
ReadOnlyFileDefaultReadOnlyFile
passes "r" as a parameter to the constructor of its super-class
RandomAccessFile.
With Oracle's JSE implementation, 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 DecoratingReadOnlyFilepos - The current byte position as a zero-based index.IOException - If pos is less than 0 or on any
I/O failure.Copyright © 2005-2013 Schlichtherle IT Services. All Rights Reserved.