Package com.mku.salmon
Class SalmonDrive
java.lang.Object
com.mku.file.VirtualDrive
com.mku.salmon.SalmonDrive
- Direct Known Subclasses:
AndroidDrive
,JavaDrive
Class provides an abstract virtual drive that can be extended for use with
any filesystem ie disk, net, cloud, etc.
Each drive implementation needs a corresponding implementation of
IRealFile
.-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Lock the drive and close associated resources.static SalmonDrive
createDrive
(IRealFile dir, Class<?> driveClassType, String password, INonceSequencer sequencer) Create a new drive in the provided location.static String
Get the authorization ID for the current device.byte[]
getBytesFromRealFile
(IRealFile file, int bufferSize) Get the byte contents of a file from the real filesystem.static String
static String
Get the default auth config filename.int
Return the default file chunk sizeprotected SalmonDriveConfig
Return the configuration properties of this drive.byte[]
Get the drive ID.Return the default external export dir that all file can be exported to.static String
getKey()
Return the encryption key that is used for encryption / decryptionprotected IRealFile
getRoot()
Return the virtual root directory of the drive.Get the nonce sequencer used for the current drive.static String
static String
boolean
Return true if the drive is already created and has a configuration file.protected void
initFS()
Initialize the drive virtual filesystem.void
initialize
(IRealFile realRoot, boolean createIfNotExists) Initialize a virtual drive at the directory path providedstatic SalmonDrive
openDrive
(IRealFile dir, Class<?> driveClassType, String password, INonceSequencer sequencer) Set the drive location to an external directory.void
Revoke authorization for this device.static void
setAuthConfigFilename
(String authConfigFilename) static void
setConfigFilename
(String configFilename) void
setDefaultFileChunkSize
(int fileChunkSize) Set the default file chunk size to be used with hash integrity.static void
setExportDirectoryName
(String exportDirectoryName) void
setPassword
(String pass) Change the user password.void
setSequencer
(INonceSequencer sequencer) Set the nonce sequencer used for the current drive.static void
setShareDirectoryName
(String shareDirectoryName) static void
setVirtualDriveDirectoryName
(String virtualDriveDirectoryName) Methods inherited from class com.mku.file.VirtualDrive
getPrivateDir, onUnlockError, onUnlockSuccess
-
Constructor Details
-
SalmonDrive
public SalmonDrive()
-
-
Method Details
-
initialize
Initialize a virtual drive at the directory path provided- Parameters:
realRoot
- The root of the real directorycreateIfNotExists
- Create the drive if it does not exist
-
getConfigFilename
-
setConfigFilename
-
getAuthConfigFilename
-
setAuthConfigFilename
-
getVirtualDriveDirectoryName
-
setVirtualDriveDirectoryName
-
getExportDirectoryName
-
setExportDirectoryName
-
getDefaultFileChunkSize
public int getDefaultFileChunkSize()Return the default file chunk size- Returns:
- The default chunk size.
-
setDefaultFileChunkSize
public void setDefaultFileChunkSize(int fileChunkSize) Set the default file chunk size to be used with hash integrity.- Parameters:
fileChunkSize
- The file chunk size
-
getKey
Return the encryption key that is used for encryption / decryption- Returns:
- The drive key
-
setPassword
Change the user password.- Parameters:
pass
- The new password.- Throws:
IOException
- Thrown if there is an IO error.SalmonAuthException
- Thrown if there is an Authorization errorSalmonSecurityException
- Thrown if there is a security exceptionIntegrityException
- Thrown if the data are corrupt or tampered with.SequenceException
- Thrown if there is an error with the nonce sequence
-
initFS
protected void initFS()Initialize the drive virtual filesystem. -
openDrive
public static SalmonDrive openDrive(IRealFile dir, Class<?> driveClassType, String password, INonceSequencer sequencer) throws IOException Set the drive location to an external directory. This requires you previously use SetDriveClass() to provide a class for the drive- Parameters:
dir
- The directory path that will be used for storing the contents of the drivedriveClassType
- The class type of the drive to open (ie: JavaDrive.class)password
- The passwordsequencer
- The sequencer to use for this drive- Returns:
- The drive
- Throws:
IOException
- Thrown if there is an IO error.
-
createDrive
public static SalmonDrive createDrive(IRealFile dir, Class<?> driveClassType, String password, INonceSequencer sequencer) throws IOException Create a new drive in the provided location.- Parameters:
dir
- Directory to store the drive configuration and virtual filesystem.driveClassType
- The class type of the drive to create (ie: JavaDrive.class)password
- The passwordsequencer
- The sequencer to use for this drive- Returns:
- The newly created drive.
- Throws:
IntegrityException
- Thrown if the data are corrupt or tampered with.SequenceException
- Thrown if there is an error with the nonce sequenceIOException
- Thrown if there is an IO error.
-
getDefaultAuthConfigFilename
Get the default auth config filename.- Returns:
- The default auth config filename
-
revokeAuthorization
public void revokeAuthorization()Revoke authorization for this device. This will effectively terminate write operations on the current disk by the current device. Warning: If you need to authorize write operations to the device again you will need to have another device to export an authorization config file and reimport it.- See Also:
-
getAuthId
Get the authorization ID for the current device.- Returns:
- The authorization id.
- Throws:
SequenceException
- Thrown if there is an error with the nonce sequenceSalmonAuthException
- Thrown if there is an Authorization error
-
getRoot
Return the virtual root directory of the drive.- Specified by:
getRoot
in classVirtualDrive
- Returns:
- The virtual root directory of the drive
- Throws:
SalmonAuthException
- Thrown if there is an Authorization error
-
getRealRoot
-
getBytesFromRealFile
Get the byte contents of a file from the real filesystem.- Parameters:
file
- The filebufferSize
- The buffer to be used when reading- Returns:
- The contents of the file
- Throws:
IOException
- Thrown if there is an IO error.
-
getExportDir
Return the default external export dir that all file can be exported to.- Returns:
- The file on the real filesystem.
-
getDriveConfig
Return the configuration properties of this drive.- Returns:
- The drive configuration.
- Throws:
IOException
- Thrown if there is an IO error.
-
hasConfig
public boolean hasConfig()Return true if the drive is already created and has a configuration file.- Returns:
- True if already created
-
getDriveId
public byte[] getDriveId()Get the drive ID.- Returns:
- The drive ID
-
close
public void close()Lock the drive and close associated resources. -
getSequencer
Get the nonce sequencer used for the current drive.- Returns:
- The nonce sequencer
-
setSequencer
Set the nonce sequencer used for the current drive.- Parameters:
sequencer
- The nonce sequencer
-