File Access Service Developer Documentation

In two words

A service used to provide the basic functionality required to access the underlying file system. You can live without using this service, but it’ll make your life easier.

Note: Never store unencrypted sensitive information, such as credit card numbers, passwords, etc.

Note: If you do not hold a PhD in cryptology consider all hand-made encryption schemes as insecure ;)

In four words

You can use the FileAccessService to create persistent or temporary files.

Temporary files and directories
Some of the implementations of JVM do not delete the temporary files when they are no longer used (refer to Sun bugs 4171239 and 4950148 for more details). We took an implementation that addresses those issues and we added functions that allow you to create temporary directories.
Persistent files and directories
If you need to save information that is specific to each user (like history) you can use this service. All files created with this service are going to be under the same directory (ie. /home/username/.sipcommunicator/history/filename.txt).

In Integer.MAX_VALUE words

After obtaining the FileAccessService you can do:

  • getTemporaryFile - returns a created temporary file
  • getTemporaryDirectory - returns a created temporary directory
  • getPrivatePersistentFile - returns a persistent file specific to the user. It may not exist, but it is guaranteed that you will have the sufficient rights to create it
  • getPrivatePersistentDirectory - returns a created persistent directory specific to the user

The FileAccessService uses the following properties (values taken from ConfigurationService):

  • net.java.sip.communicator.user.home - the user’s home directory. Defaults to the value of the system property user.home
  • net.java.sip.communicator.user.home.sip-communicator-home - The subdirectory of user’s home in which all user files will be stored. Defaults to sip-communicator

A short example

// Obtain the service
ServiceReference fileAccessServiceRef =
            context.getServiceReference(
                FileAccessService.class.getName());
FileAccessService fileAccessService =
    FileAccessService)context.getService(fileAccessServiceRef);


File tmpFile = fileAccessService.getTemporaryFile();
// read, write, etc..
tmpFile.close();


File dataFile = fileAccessService.getPrivatePersistentFile("data.txt");
if(!dataFile.exists()) {
    dataFile.createNewFile();
}
// read, write, etc..
dataFile.close();

Author: Alexander Pelov