@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
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 |
---|---|
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()
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.
|
toString
read, 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 ReadOnlyFile
close
in interface Closeable
close
in interface AutoCloseable
close
in class DecoratingReadOnlyFile
IOException
- 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
ReadOnlyFile
getFilePointer
in interface ReadOnlyFile
getFilePointer
in class DecoratingReadOnlyFile
IOException
- 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
ReadOnlyFile
length
in interface ReadOnlyFile
length
in class DecoratingReadOnlyFile
IOException
- On any I/O failure.public int read() throws IOException
ReadOnlyFile
read
in interface ReadOnlyFile
read
in class DecoratingReadOnlyFile
IOException
- On any I/O failure.public int read(byte[] dst, int offset, int remaining) throws IOException
ReadOnlyFile
len
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 ReadOnlyFile
read
in class DecoratingReadOnlyFile
dst
- 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
ReadOnlyFile
DefaultReadOnlyFile
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 ReadOnlyFile
seek
in class DecoratingReadOnlyFile
pos
- The current byte position as a zero-based index.IOException
- If pos
is less than 0
or on any
I/O failure.Copyright © 2005–2018 Schlichtherle IT Services. All rights reserved.