public class VirtualFileSystem
extends java.lang.Object
Modifier and Type | Method and Description |
---|---|
void |
beginTransaction()
Call this function before performance sensitive write operations to
increase performance
|
void |
completeTransaction()
Call this function after performance sensitive write operations complete
|
void |
createNewContainer(byte[] key)
Create a new VFS container file at the path given in
setContainerPath(String) and key . |
void |
createNewContainer(javax.crypto.SecretKey key)
Create a new VFS container file at the path given in
setContainerPath(String) and key . |
void |
createNewContainer(java.lang.String password)
Create a new VFS container file at the path given from
setContainerPath(String) and password . |
void |
createNewContainer(java.lang.String containerPath,
byte[] key)
Create a new VFS container file using the path and key given.
|
void |
createNewContainer(java.lang.String containerPath,
javax.crypto.SecretKey key)
Create a new VFS container file using the path and key given.
|
void |
createNewContainer(java.lang.String containerPath,
java.lang.String password)
Create a new VFS container file using the path and password given.
|
boolean |
deleteContainer()
Delete all files associated with the container itself, i.e.
|
boolean |
deleteContainer(java.lang.String containerPath)
Delete all files associated with the container itself, i.e.
|
void |
detachThread()
If accessing an IOCipher container in any thread separate from where
mount(byte[]) was called, that thread will have its own IOCipher
state. |
static VirtualFileSystem |
get()
Get the instance of the VirtualFileSystem.
|
java.lang.String |
getContainerPath()
Get the full path to the file used as the virtual file system container.
|
boolean |
isMounted() |
void |
mount(byte[] key)
Open and mount a virtual file system container encrypted with the
provided key.
|
void |
mount(javax.crypto.SecretKey key)
Open and mount a virtual file system container encrypted with the
provided key.
|
void |
mount(java.lang.String password)
Open and mount a virtual file system container encrypted with the
provided password as a
String . |
void |
mount(java.lang.String containerPath,
byte[] key)
Open and mount a virtual file system container encrypted with the
provided key.
|
void |
mount(java.lang.String containerPath,
javax.crypto.SecretKey key)
Open and mount a virtual file system container encrypted with the
provided key.
|
void |
mount(java.lang.String containerPath,
java.lang.String password)
Open and mount a virtual file system container encrypted with the
provided password as a
String . |
void |
setContainerPath(java.lang.String containerPath)
Set the path to the container file that is the virtual file system.
|
void |
unmount()
Unmount the file system.
|
public static VirtualFileSystem get()
public void setContainerPath(java.lang.String containerPath) throws java.lang.IllegalArgumentException
String
to avoid confusion between
File
and File
.{@code
- containerPath} the physical disk file that serves as the
VFS container{@link
- IllegalArgumentException} if the containing directory does
not exist or is not readablejava.lang.IllegalArgumentException
public java.lang.String getContainerPath()
public void createNewContainer(java.lang.String password) throws java.lang.IllegalArgumentException
setContainerPath(String)
and password
.
If the container path was not set does not exist, it will throw an
IllegalArgumentException
.
{@code
- password} the password to set in the new VFS container{@link
- IllegalArgumentException}java.lang.IllegalArgumentException
public void createNewContainer(byte[] key) throws java.lang.IllegalArgumentException
setContainerPath(String)
and key
.
If the container path was not set does not exist, it will throw an
IllegalArgumentException
.
{@code
- key} the raw AES key to set in the new VFS container{@link
- IllegalArgumentException}java.lang.IllegalArgumentException
public void createNewContainer(javax.crypto.SecretKey key) throws java.lang.IllegalArgumentException
setContainerPath(String)
and key
.
If the container path was not set does not exist, it will throw an
IllegalArgumentException
.
{@code
- key} the raw AES key to set in the new VFS container{@link
- IllegalArgumentException}java.lang.IllegalArgumentException
public void createNewContainer(java.lang.String containerPath, java.lang.String password) throws java.lang.IllegalArgumentException
If the container path given does not exist or is not read/write, it will
throw an IllegalArgumentException
.
{@code
- containerPath} the physical disk file that serves as the
VFS container{@link
- IllegalArgumentException} if the containing directory does
not exist or is not readablejava.lang.IllegalArgumentException
public void createNewContainer(java.lang.String containerPath, byte[] key) throws java.lang.IllegalArgumentException
If the container path given does not exist or is not read/write, it will
throw an IllegalArgumentException
.
{@code
- containerPath} the physical disk file that serves as the
VFS container{@code
- key} the raw AES key to set in the new VFS container{@link
- IllegalArgumentException} if the containing directory does
not exist or is not readablejava.lang.IllegalArgumentException
public void createNewContainer(java.lang.String containerPath, javax.crypto.SecretKey key) throws java.lang.IllegalArgumentException
If the container path given does not exist or is not read/write, it will
throw an IllegalArgumentException
.
{@code
- containerPath} the physical disk file that serves as the
VFS container{@code
- key} the raw AES key to set in the new VFS container{@link
- IllegalArgumentException} if the containing directory does
not exist or is not readablejava.lang.IllegalArgumentException
public boolean deleteContainer()
true
if all related files were deleted, false
otherwisepublic boolean deleteContainer(java.lang.String containerPath)
containerPath
- the path to the sqlfs database filetrue
if all related files were deleted, false
otherwisepublic void mount(java.lang.String password) throws java.lang.IllegalArgumentException
String
. This String
is then used
to derive the AES key using SQLCipher's key derivation method. This
method is the least preferred option because it is not possible to clear
the password from memory since String
instances are immutable.
If the vfs is already mounted, it will throw an
IllegalStateException
. If the file does not exist or the password
is wrong, it will throw an IllegalArgumentException
.
password
- the password to unlock the VFS containerIllegalArgumentException,
- IllegalStateExceptionjava.lang.IllegalArgumentException
public void mount(java.lang.String containerPath, java.lang.String password)
String
. This String
is then used
to derive the AES key using SQLCipher's key derivation method. This
method is the least preferred option because it is not possible to clear
the password from memory since String
instances are immutable.
If the vfs is already mounted, it will throw an
IllegalStateException
. If the file does not exist or the password
is wrong, it will throw an IllegalArgumentException
.
containerPath
- the path to the file to mountpassword
- the password to unlock the VFS containerIllegalArgumentException,
- IllegalStateExceptionpublic void mount(byte[] key) throws java.lang.IllegalArgumentException
SecretKey
instance here to be passed directly to the underlying database layer. It
is not a password that will then be used to derive a key, like with
mount(String)
. This method only accepts raw byte values, if you
need to send a Unicode string, use mount(String)
. Also, a
byte[]
can be zeroed out when it is no longer needed. This method
and mount(SecretKey)
were designed to be used with the CacheWord
library.
If the vfs is already mounted, it will throw an
IllegalStateException
. If the file does not exist or the key is
wrong, it will throw an IllegalArgumentException
.
{@code
- key} the container's raw AES keyIllegalArgumentException,
- IllegalStateExceptionjava.lang.IllegalArgumentException
public void mount(java.lang.String containerPath, byte[] key)
SecretKey
instance here to be passed directly to the underlying database layer. It
is not a password that will then be used to derive a key, like with
mount(String)
. This method only accepts raw byte values, if you
need to send a Unicode string, use mount(String)
. Also, a
byte[]
can be zeroed out when it is no longer needed. This method
and mount(SecretKey)
were designed to be used with the CacheWord
library.
If the vfs is already mounted, it will throw an
IllegalStateException
. If the file does not exist or the key is
wrong, it will throw an IllegalArgumentException
.
containerPath
- the path to the file to mount{@code
- key} the container's raw AES keyIllegalArgumentException,
- IllegalStateExceptionpublic void mount(javax.crypto.SecretKey key)
SecretKey
instance here to be passed directly to the underlying database layer. It
is not a password that will then be used to derive a key, like with
mount(String)
. This method and mount(byte[])
were
designed to be used with the CacheWord library.
If the vfs is already mounted, it will throw an
IllegalStateException
. If the file does not exist or the key is
wrong, it will throw an IllegalArgumentException
.
{@code
- key} the container's raw AES keyIllegalArgumentException,
- IllegalStateExceptionpublic void mount(java.lang.String containerPath, javax.crypto.SecretKey key)
SecretKey
instance here to be passed directly to the underlying database layer. It
is not a password that will then be used to derive a key, like with
mount(String)
. This method and mount(byte[])
were
designed to be used with the CacheWord library.
If the vfs is already mounted, it will throw an
IllegalStateException
. If the file does not exist or the key is
wrong, it will throw an IllegalArgumentException
.
containerPath
- the path to the file to mount{@code
- key} the container's raw AES keyIllegalArgumentException,
- IllegalStateExceptionpublic void unmount() throws java.lang.IllegalStateException
IllegalStateException
if the vfs is not mounted, or if it cannot be unmounted because it is
busy (some threads are still active on it).java.lang.IllegalStateException
public boolean isMounted()
public void detachThread()
mount(byte[])
was called, that thread will have its own IOCipher
state. For threads that do not quit when complete or are reused, like
Android's AsyncTask
or any "thread pool" model, this method must
be called when each thread is finished using the container. Otherwise,
that thread will keep its connection to the container open, and it will
not be possible to unmount()
successfully.public void beginTransaction()
public void completeTransaction()