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:
java.io.Closeable,java.lang.AutoCloseable,java.nio.channels.ByteChannel,java.nio.channels.Channel,java.nio.channels.GatheringByteChannel,java.nio.channels.InterruptibleChannel,java.nio.channels.ReadableByteChannel,java.nio.channels.ScatteringByteChannel,java.nio.channels.SeekableByteChannel,java.nio.channels.WritableByteChannel
public class FileEncrypt extends FileBaseDefault
An encrypted file with a read cache.
-
-
Field Summary
Fields Modifier and Type Field Description private java.nio.channels.FileChannelbasestatic intBLOCK_SIZEThe block size.(package private) static intBLOCK_SIZE_MASKThe block size bit mask.private byte[]encryptionKeyprivate static intHASH_ITERATIONSThe number of iterations.private static byte[]HEADER(package private) static intHEADER_LENGTHThe length of the file header.private java.lang.Stringnameprivate static intSALT_LENGTHThe length of the salt, in bytes.private static intSALT_POSprivate longsizeThe current file size, from a user perspective.private XTSxts
-
Constructor Summary
Constructors Constructor Description FileEncrypt(java.lang.String name, byte[] encryptionKey, java.nio.channels.FileChannel base)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private XTScreateXTS()voidforce(boolean metaData)protected voidimplCloseChannel()protected voidimplTruncate(long newSize)The truncate implementation.private XTSinit()intread(java.nio.ByteBuffer dst, long position)private static voidreadFully(java.nio.channels.FileChannel file, long pos, java.nio.ByteBuffer dst)private voidreadInternal(java.nio.ByteBuffer dst, long position, int len, XTS xts)longsize()java.lang.StringtoString()java.nio.channels.FileLocktryLock(long position, long size, boolean shared)intwrite(java.nio.ByteBuffer src, long position)private static voidwriteFully(java.nio.channels.FileChannel file, long pos, java.nio.ByteBuffer src)private voidwriteInternal(java.nio.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.spi.AbstractInterruptibleChannel
begin, close, end, isOpen
-
-
-
-
Field Detail
-
BLOCK_SIZE
public static final int BLOCK_SIZE
The block size.- See Also:
- Constant Field Values
-
BLOCK_SIZE_MASK
static final int BLOCK_SIZE_MASK
The block size bit mask.- See Also:
- Constant Field Values
-
HEADER_LENGTH
static final int HEADER_LENGTH
The 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:
- Constant Field Values
-
HEADER
private static final byte[] HEADER
-
SALT_POS
private static final int SALT_POS
-
SALT_LENGTH
private static final int SALT_LENGTH
The length of the salt, in bytes.- See Also:
- Constant Field Values
-
HASH_ITERATIONS
private static final int HASH_ITERATIONS
The number of iterations. It is relatively low; a higher value would slow down opening files on Android too much.- See Also:
- Constant Field Values
-
base
private final java.nio.channels.FileChannel base
-
size
private volatile long size
The current file size, from a user perspective.
-
name
private final java.lang.String name
-
xts
private volatile XTS xts
-
encryptionKey
private byte[] encryptionKey
-
-
Method Detail
-
init
private XTS init() throws java.io.IOException
- Throws:
java.io.IOException
-
createXTS
private XTS createXTS() throws java.io.IOException
- Throws:
java.io.IOException
-
implCloseChannel
protected void implCloseChannel() throws java.io.IOException- Overrides:
implCloseChannelin classFileBase- Throws:
java.io.IOException
-
read
public int read(java.nio.ByteBuffer dst, long position) throws java.io.IOException
-
readInternal
private void readInternal(java.nio.ByteBuffer dst, long position, int len, XTS xts) throws java.io.IOException- Throws:
java.io.IOException
-
readFully
private static void readFully(java.nio.channels.FileChannel file, long pos, java.nio.ByteBuffer dst) throws java.io.IOException- Throws:
java.io.IOException
-
write
public int write(java.nio.ByteBuffer src, long position) throws java.io.IOException
-
writeInternal
private void writeInternal(java.nio.ByteBuffer src, long position, int len, XTS xts) throws java.io.IOException- Throws:
java.io.IOException
-
writeFully
private static void writeFully(java.nio.channels.FileChannel file, long pos, java.nio.ByteBuffer src) throws java.io.IOException- Throws:
java.io.IOException
-
size
public long size() throws java.io.IOException- Specified by:
sizein interfacejava.nio.channels.SeekableByteChannel- Specified by:
sizein classjava.nio.channels.FileChannel- Throws:
java.io.IOException
-
implTruncate
protected void implTruncate(long newSize) throws java.io.IOExceptionDescription copied from class:FileBaseDefaultThe truncate implementation.- Specified by:
implTruncatein classFileBaseDefault- Parameters:
newSize- the new size- Throws:
java.io.IOException- on failure
-
force
public void force(boolean metaData) throws java.io.IOException
-
tryLock
public java.nio.channels.FileLock tryLock(long position, long size, boolean shared) throws java.io.IOException
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-