public class FileStore
extends java.lang.Object
SecureFileStore| Modifier and Type | Field and Description |
|---|---|
static int |
HEADER_LENGTH
The size of the file header in bytes.
|
protected java.lang.String |
name
The file name.
|
| Modifier | Constructor and Description |
|---|---|
protected |
FileStore(DataHandler handler,
java.lang.String name,
java.lang.String mode)
Create a new file using the given settings.
|
| Modifier and Type | Method and Description |
|---|---|
void |
autoDelete()
Automatically delete the file once it is no longer in use.
|
void |
close()
Close the file.
|
void |
closeAndDeleteSilently()
Close the file (ignoring exceptions) and delete the file.
|
void |
closeFile()
Close the file.
|
void |
closeSilently()
Close the file without throwing any exceptions.
|
protected byte[] |
generateSalt()
Generate the random salt bytes if required.
|
long |
getFilePointer()
Get the current location of the file pointer.
|
void |
init()
Initialize the file.
|
protected void |
initKey(byte[] salt)
Initialize the key using the given salt.
|
long |
length()
Get the file size in bytes.
|
static FileStore |
open(DataHandler handler,
java.lang.String name,
java.lang.String mode)
Open a non encrypted file store with the given settings.
|
static FileStore |
open(DataHandler handler,
java.lang.String name,
java.lang.String mode,
java.lang.String cipher,
byte[] key)
Open an encrypted file store with the given settings.
|
static FileStore |
open(DataHandler handler,
java.lang.String name,
java.lang.String mode,
java.lang.String cipher,
byte[] key,
int keyIterations)
Open an encrypted file store with the given settings.
|
void |
openFile()
Re-open the file.
|
void |
readFully(byte[] b,
int off,
int len)
Read a number of bytes.
|
void |
readFullyDirect(byte[] b,
int off,
int len)
Read a number of bytes without decrypting.
|
void |
releaseLock()
Release the file lock.
|
void |
seek(long pos)
Go to the specified file location.
|
void |
setCheckedWriting(boolean value) |
void |
setLength(long newLength)
Set the length of the file.
|
void |
stopAutoDelete()
No longer automatically delete the file once it is no longer in use.
|
void |
sync()
Call fsync.
|
boolean |
tryLock()
Try to lock the file.
|
void |
write(byte[] b,
int off,
int len)
Write a number of bytes.
|
protected void |
writeDirect(byte[] b,
int off,
int len)
Write a number of bytes without encrypting.
|
public static final int HEADER_LENGTH
protected java.lang.String name
protected FileStore(DataHandler handler, java.lang.String name, java.lang.String mode)
handler - the callback objectname - the file namemode - the access mode ("r", "rw", "rws", "rwd")public static FileStore open(DataHandler handler, java.lang.String name, java.lang.String mode)
handler - the data handlername - the file namemode - the access mode (r, rw, rws, rwd)public static FileStore open(DataHandler handler, java.lang.String name, java.lang.String mode, java.lang.String cipher, byte[] key)
handler - the data handlername - the file namemode - the access mode (r, rw, rws, rwd)cipher - the name of the cipher algorithmkey - the encryption keypublic static FileStore open(DataHandler handler, java.lang.String name, java.lang.String mode, java.lang.String cipher, byte[] key, int keyIterations)
handler - the data handlername - the file namemode - the access mode (r, rw, rws, rwd)cipher - the name of the cipher algorithmkey - the encryption keykeyIterations - the number of iterations the key should be hashedprotected byte[] generateSalt()
protected void initKey(byte[] salt)
salt - the saltpublic void setCheckedWriting(boolean value)
public void init()
public void close()
public void closeSilently()
public void closeAndDeleteSilently()
public void readFullyDirect(byte[] b,
int off,
int len)
b - the target bufferoff - the offsetlen - the number of bytes to readpublic void readFully(byte[] b,
int off,
int len)
b - the target bufferoff - the offsetlen - the number of bytes to readpublic void seek(long pos)
pos - the locationprotected void writeDirect(byte[] b,
int off,
int len)
b - the source bufferoff - the offsetlen - the number of bytes to writepublic void write(byte[] b,
int off,
int len)
b - the source bufferoff - the offsetlen - the number of bytes to writepublic void setLength(long newLength)
newLength - the new file sizepublic long length()
public long getFilePointer()
public void sync()
public void autoDelete()
public void stopAutoDelete()
public void closeFile()
throws java.io.IOException
java.io.IOException - on failurepublic void openFile()
throws java.io.IOException
java.io.IOException - on failurepublic boolean tryLock()
public void releaseLock()