de.unikassel.android.sdcframework.transmission
Class FileManager

Package class diagram package FileManager
java.lang.Object
  extended by de.unikassel.android.sdcframework.transmission.FileManager
All Implemented Interfaces:
UpdatableTransmissionComponent<TransmissionConfiguration>

public class FileManager
extends Object
implements UpdatableTransmissionComponent<TransmissionConfiguration>

A file management component for the transmission service.

Does provide the functionality to create a device information XML file as well as a temporary file directory. In addition it does manage the archive creation.


Field Summary
static String ARCHIVE_FILE
          The filename for the archive without extension
private  String archiveFileName
          The file path and base name without extension for archive files
private  String currentArchive
          The file to store a new created archive in
private  String deviceFile
          The file to store permanent device info in
private  FileEncryptionStrategy encryptionStrategy
          The file encryption used to create archives
private  FileCompressor fileCompressor
          The file compressor used to create archives
private  String sampleFile
          The temporary file to store serialized samples in
static String TEMP_DIR_NAME
          The name of the temporary sub directory for files
 
Constructor Summary
FileManager(Context applicationContext, TransmissionConfiguration config, UUID uuid)
          Constructor
 
Method Summary
 boolean createArchive(SampleCollection samples)
          Does create a new archive containing the device description file and the XML file with the serialized sample collection
private  String createArchiveWithFiles(List<String> files)
          Method to create an archive from files
private  void createDeviceInformation(UUID uuid)
          Does create the device information file to be added to the sample collection archive file ( if it does not exist )
private  void createTmpDirectory(String dir)
          Does create the temporary directory if it does not exist
private  void deleteFile(String fileName)
          Does cleanup any temporary files stored
 void doCleanUp(boolean deleteArchive)
          Does cleanup any temporary files stored
private  String encryptArchive(String sArchive)
          Method to encrypt the archive if configured
 String getCurrentArchive()
          Getter for the current archive file name
 String getDeviceFile()
          Getter for the device file name
 FileCompressor getFileCompressor()
          Getter for the fileCompressor
protected  PublicKey getPubKeyFromAssetFolder(Context context)
          Does load the public key file from the asset folder.
protected  PublicKey getPubKeyFromFilesFolder(Context context)
          Does load the public key file from the private files folder.
 String getSampleFile()
          Getter for the current sample file name
 boolean hasArchive()
          Test method for existing archives
private  void testForExistingArchive(String dir)
          Does check for an existing archive file
 void updateConfiguration(Context context, TransmissionConfiguration config)
          Method to update the component by a configuration
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TEMP_DIR_NAME

public static final String TEMP_DIR_NAME
The name of the temporary sub directory for files

See Also:
Constant Field Values

ARCHIVE_FILE

public static final String ARCHIVE_FILE
The filename for the archive without extension

See Also:
Constant Field Values

sampleFile

private final String sampleFile
The temporary file to store serialized samples in


deviceFile

private final String deviceFile
The file to store permanent device info in


archiveFileName

private final String archiveFileName
The file path and base name without extension for archive files


currentArchive

private String currentArchive
The file to store a new created archive in


fileCompressor

private final FileCompressor fileCompressor
The file compressor used to create archives


encryptionStrategy

private FileEncryptionStrategy encryptionStrategy
The file encryption used to create archives

Constructor Detail

FileManager

public FileManager(Context applicationContext,
                   TransmissionConfiguration config,
                   UUID uuid)
Constructor

Parameters:
applicationContext - the application context
config - the transmission configuration
uuid - the unique device identifier created by the service
Method Detail

getSampleFile

public final String getSampleFile()
Getter for the current sample file name

Returns:
the current sample file name

getCurrentArchive

public final String getCurrentArchive()
Getter for the current archive file name

Returns:
the current archive file name

getDeviceFile

public final String getDeviceFile()
Getter for the device file name

Returns:
the device file name

getFileCompressor

public final FileCompressor getFileCompressor()
Getter for the fileCompressor

Returns:
the file ompressor

createTmpDirectory

private void createTmpDirectory(String dir)
Does create the temporary directory if it does not exist

Parameters:
dir - the absolute temporary directory filename

createDeviceInformation

private void createDeviceInformation(UUID uuid)
Does create the device information file to be added to the sample collection archive file ( if it does not exist )

Parameters:
uuid - the unique device identifier created by the service

createArchive

public boolean createArchive(SampleCollection samples)
Does create a new archive containing the device description file and the XML file with the serialized sample collection

Parameters:
samples - the sample collection
Returns:
true if successful, false otherwise

encryptArchive

private String encryptArchive(String sArchive)
Method to encrypt the archive if configured

Parameters:
sArchive - the archive to encrypt
Returns:
the encrypted archive name, or null in case of errors

createArchiveWithFiles

private String createArchiveWithFiles(List<String> files)
Method to create an archive from files

Parameters:
files - the files to add
Returns:
the created archive file path

hasArchive

public boolean hasArchive()
Test method for existing archives

Returns:
true if an archive exists, false otherwise

testForExistingArchive

private void testForExistingArchive(String dir)
Does check for an existing archive file

Parameters:
dir - the absolute temporary directory filename

doCleanUp

public void doCleanUp(boolean deleteArchive)
Does cleanup any temporary files stored

Parameters:
deleteArchive - flag if archive file shall be deleted as well

deleteFile

private void deleteFile(String fileName)
Does cleanup any temporary files stored


updateConfiguration

public void updateConfiguration(Context context,
                                TransmissionConfiguration config)
Description copied from interface: UpdatableTransmissionComponent
Method to update the component by a configuration

Specified by:
updateConfiguration in interface UpdatableTransmissionComponent<TransmissionConfiguration>
Parameters:
context - the application context
config - the configuration to update from

getPubKeyFromFilesFolder

protected PublicKey getPubKeyFromFilesFolder(Context context)
Does load the public key file from the private files folder.

Parameters:
context - the context
Returns:
the public key if found, null otherwise
Throws:
IOException

getPubKeyFromAssetFolder

protected PublicKey getPubKeyFromAssetFolder(Context context)
Does load the public key file from the asset folder.

Parameters:
context - the context
Returns:
the public key if found, null otherwise
Throws:
IOException