Package org.h2.store.fs.encrypt
Class FileEncrypt
java.lang.Object
java.nio.channels.spi.AbstractInterruptibleChannel
java.nio.channels.FileChannel
org.h2.store.fs.FileBase
org.h2.store.fs.FileBaseDefault
org.h2.store.fs.encrypt.FileEncrypt
- All Implemented Interfaces:
Closeable
,AutoCloseable
,ByteChannel
,Channel
,GatheringByteChannel
,InterruptibleChannel
,ReadableByteChannel
,ScatteringByteChannel
,SeekableByteChannel
,WritableByteChannel
An encrypted file with a read cache.
-
Nested Class Summary
Nested classes/interfaces inherited from class java.nio.channels.FileChannel
FileChannel.MapMode
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final FileChannel
static final int
The block size.(package private) static final int
The block size bit mask.private byte[]
private static final int
The number of iterations.private static final byte[]
(package private) static final int
The length of the file header.private final String
private static final int
The length of the salt, in bytes.private static final int
private long
The current file size, from a user perspective.private XTS
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate XTS
void
force
(boolean metaData) protected void
protected void
implTruncate
(long newSize) The truncate implementation.private XTS
init()
int
read
(ByteBuffer dst, long position) private static void
readFully
(FileChannel file, long pos, ByteBuffer dst) private void
readInternal
(ByteBuffer dst, long position, int len, XTS xts) long
size()
toString()
tryLock
(long position, long size, boolean shared) int
write
(ByteBuffer src, long position) private static void
writeFully
(FileChannel file, long pos, ByteBuffer src) private void
writeInternal
(ByteBuffer src, long position, int len, XTS xts) Methods inherited from class org.h2.store.fs.FileBaseDefault
position, position, read, truncate, write
Methods inherited from class org.h2.store.fs.FileBase
lock, map, read, transferFrom, transferTo, write
Methods inherited from class java.nio.channels.FileChannel
lock, map, open, open, read, tryLock, write
Methods inherited from class java.nio.channels.spi.AbstractInterruptibleChannel
begin, close, end, isOpen
-
Field Details
-
BLOCK_SIZE
public static final int BLOCK_SIZEThe block size.- See Also:
-
BLOCK_SIZE_MASK
static final int BLOCK_SIZE_MASKThe block size bit mask.- See Also:
-
HEADER_LENGTH
static final int HEADER_LENGTHThe length of the file header. Using a smaller header is possible, but would mean reads and writes are not aligned to the block size.- See Also:
-
HEADER
private static final byte[] HEADER -
SALT_POS
private static final int SALT_POS -
SALT_LENGTH
private static final int SALT_LENGTHThe length of the salt, in bytes.- See Also:
-
HASH_ITERATIONS
private static final int HASH_ITERATIONSThe number of iterations. It is relatively low; a higher value would slow down opening files on Android too much.- See Also:
-
base
-
size
private volatile long sizeThe current file size, from a user perspective. -
name
-
xts
-
encryptionKey
private byte[] encryptionKey
-
-
Constructor Details
-
FileEncrypt
-
-
Method Details
-
init
- Throws:
IOException
-
createXTS
- Throws:
IOException
-
implCloseChannel
- Overrides:
implCloseChannel
in classFileBase
- Throws:
IOException
-
read
- Overrides:
read
in classFileBase
- Throws:
IOException
-
readInternal
- Throws:
IOException
-
readFully
- Throws:
IOException
-
write
- Overrides:
write
in classFileBase
- Throws:
IOException
-
writeInternal
- Throws:
IOException
-
writeFully
- Throws:
IOException
-
size
- Specified by:
size
in interfaceSeekableByteChannel
- Specified by:
size
in classFileChannel
- Throws:
IOException
-
implTruncate
Description copied from class:FileBaseDefault
The truncate implementation.- Specified by:
implTruncate
in classFileBaseDefault
- Parameters:
newSize
- the new size- Throws:
IOException
- on failure
-
force
- Overrides:
force
in classFileBase
- Throws:
IOException
-
tryLock
- Overrides:
tryLock
in classFileBase
- Throws:
IOException
-
toString
-