Class SalmonDrive

java.lang.Object
com.mku.file.VirtualDrive
com.mku.salmon.SalmonDrive
Direct Known Subclasses:
AndroidDrive, JavaDrive

public abstract class SalmonDrive extends VirtualDrive
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 Details

    • SalmonDrive

      public SalmonDrive()
  • Method Details

    • initialize

      public void initialize(IRealFile realRoot, boolean createIfNotExists)
      Initialize a virtual drive at the directory path provided
      Parameters:
      realRoot - The root of the real directory
      createIfNotExists - Create the drive if it does not exist
    • getConfigFilename

      public static String getConfigFilename()
    • setConfigFilename

      public static void setConfigFilename(String configFilename)
    • getAuthConfigFilename

      public static String getAuthConfigFilename()
    • setAuthConfigFilename

      public static void setAuthConfigFilename(String authConfigFilename)
    • getVirtualDriveDirectoryName

      public static String getVirtualDriveDirectoryName()
    • setVirtualDriveDirectoryName

      public static void setVirtualDriveDirectoryName(String virtualDriveDirectoryName)
    • getExportDirectoryName

      public static String getExportDirectoryName()
    • setExportDirectoryName

      public static void setExportDirectoryName(String exportDirectoryName)
    • getShareDirectoryName

      public static String getShareDirectoryName()
    • setShareDirectoryName

      public static void setShareDirectoryName(String shareDirectoryName)
    • 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

      public SalmonDriveKey getKey()
      Return the encryption key that is used for encryption / decryption
      Returns:
      The drive key
    • setPassword

      public void setPassword(String pass) throws IOException
      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 error
      SalmonSecurityException - Thrown if there is a security exception
      IntegrityException - 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 drive
      driveClassType - The class type of the drive to open (ie: JavaDrive.class)
      password - The password
      sequencer - 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 password
      sequencer - 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 sequence
      IOException - Thrown if there is an IO error.
    • getDefaultAuthConfigFilename

      public static String 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

      public String getAuthId()
      Get the authorization ID for the current device.
      Returns:
      The authorization id.
      Throws:
      SequenceException - Thrown if there is an error with the nonce sequence
      SalmonAuthException - Thrown if there is an Authorization error
    • getRoot

      public SalmonFile getRoot()
      Return the virtual root directory of the drive.
      Specified by:
      getRoot in class VirtualDrive
      Returns:
      The virtual root directory of the drive
      Throws:
      SalmonAuthException - Thrown if there is an Authorization error
    • getRealRoot

      protected IRealFile getRealRoot()
    • getBytesFromRealFile

      public byte[] getBytesFromRealFile(IRealFile file, int bufferSize) throws IOException
      Get the byte contents of a file from the real filesystem.
      Parameters:
      file - The file
      bufferSize - The buffer to be used when reading
      Returns:
      The contents of the file
      Throws:
      IOException - Thrown if there is an IO error.
    • getExportDir

      public IRealFile getExportDir()
      Return the default external export dir that all file can be exported to.
      Returns:
      The file on the real filesystem.
    • getDriveConfig

      protected SalmonDriveConfig getDriveConfig() throws IOException
      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

      public INonceSequencer getSequencer()
      Get the nonce sequencer used for the current drive.
      Returns:
      The nonce sequencer
    • setSequencer

      public void setSequencer(INonceSequencer sequencer)
      Set the nonce sequencer used for the current drive.
      Parameters:
      sequencer - The nonce sequencer