org.eclipse.emf.emfstore.internal.client.model.filetransfer
Class FileTransferCacheManager

java.lang.Object
  extended by org.eclipse.emf.emfstore.internal.client.model.filetransfer.FileTransferCacheManager

public class FileTransferCacheManager
extends Object

This class manages the locally cached files for file transfers. A cache manager instance is contained in every FileTransferManager. No other cache managers should be created.

Author:
jfinis

Field Summary
static String ATTACHMENT_FOLDER
          Attachment folder for uploads and downloads.
static String FILE_NAME_DELIMITER
          The delimiter that separates file attachment id, file version and file name in an uploaded file.
static String PROJECT_FOLDER_PREFIX
          project folder prefix.
static String TEMP_FOLDER
          Temporary folder for file uploads to server.
 
Constructor Summary
FileTransferCacheManager(ProjectSpace projectSpaceImpl)
          Default constructor for a specific project space.
 
Method Summary
 File cacheFile(File input, FileIdentifier id)
          Adds a file to the cache using a given id.
 File createTempFile(FileIdentifier id)
          Creates a file in the temporary cache folder for a specified file id and returns it.
 File getCachedFile(FileIdentifier identifier)
          Returns a cached file with a given identifier.
static String getCacheFolder(ProjectSpace projectSpace)
          Returns the default file cache folder of a given projectspace.
 boolean hasCachedFile(FileIdentifier identifier)
          Returns true iff a file with this identifier is present in the cache.
 File moveTempFileToCache(FileIdentifier id)
          This method moves a file from the temporary folder into the cache.
 File moveTempFileToCache(FileIdentifier id, boolean overwrite)
          This method moves a file from the temporary folder into the cache.
 boolean removeCachedFile(FileIdentifier fileIdentifier)
          Removes a file from the cache.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TEMP_FOLDER

public static final String TEMP_FOLDER
Temporary folder for file uploads to server.

See Also:
Constant Field Values

PROJECT_FOLDER_PREFIX

public static final String PROJECT_FOLDER_PREFIX
project folder prefix.

See Also:
Constant Field Values

ATTACHMENT_FOLDER

public static final String ATTACHMENT_FOLDER
Attachment folder for uploads and downloads.

See Also:
Constant Field Values

FILE_NAME_DELIMITER

public static final String FILE_NAME_DELIMITER
The delimiter that separates file attachment id, file version and file name in an uploaded file.

See Also:
Constant Field Values
Constructor Detail

FileTransferCacheManager

public FileTransferCacheManager(ProjectSpace projectSpaceImpl)
Default constructor for a specific project space.

Parameters:
projectSpaceImpl - the project space to which this cache belongs.
Method Detail

getCacheFolder

public static String getCacheFolder(ProjectSpace projectSpace)
Returns the default file cache folder of a given projectspace.

Parameters:
projectSpace - the projectSpace
Returns:
the name of the cache folder

hasCachedFile

public boolean hasCachedFile(FileIdentifier identifier)
Returns true iff a file with this identifier is present in the cache. After this method has returned true, it is guaranteed that the getCachedFile method finds the file and does not throw an exception.

Parameters:
identifier - the identifier of the file
Returns:
if the file is present in the cache

getCachedFile

public File getCachedFile(FileIdentifier identifier)
                   throws FileTransferException
Returns a cached file with a given identifier. If the file does not exist, a FileTransferException is thrown.

Parameters:
identifier - the identifier of the file
Returns:
the file
Throws:
FileTransferException - if the file is not present in the cache

cacheFile

public File cacheFile(File input,
                      FileIdentifier id)
               throws IOException
Adds a file to the cache using a given id. If a file with the given id is already in the cache, it is overwritten.

Parameters:
input - the file to be cached
id - the id to be used for the file.
Returns:
the file in the cache folder
Throws:
IOException - any IO Exception that can occur during copying a file

createTempFile

public File createTempFile(FileIdentifier id)
                    throws FileTransferException
Creates a file in the temporary cache folder for a specified file id and returns it. If the file already exists, it is deleted and newly created.

Parameters:
id - the file id for which to create a temporary file
Returns:
the temporary file
Throws:
FileTransferException - if an IO exception occurred during the creation of a new file

moveTempFileToCache

public File moveTempFileToCache(FileIdentifier id)
                         throws FileTransferException
This method moves a file from the temporary folder into the cache. It should be called after a temporary file was written successfully. A file transfer exception is thrown in the following cases: - The file does not exist in the temporary folder - The file already exists in the cache folder - The file cannot be moved to the cache folder (the rename operation fails)

Parameters:
id - the id of the file which is to be moved
Returns:
the new location of the file after moving it
Throws:
FileTransferException - thrown if the temporary file does not exist, the final file already exists, or if the rename operation which moves the file fails

moveTempFileToCache

public File moveTempFileToCache(FileIdentifier id,
                                boolean overwrite)
                         throws FileTransferException
This method moves a file from the temporary folder into the cache. It should be called after a temporary file was written successfully. A file transfer exception is thrown in the following cases: - The file does not exist in the temporary folder - The file already exists in the cache folder - The file cannot be moved to the cache folder (the rename operation fails)

Parameters:
id - the id of the file which is to be moved
overwrite - whether to overwrite an existing file, if one with the given id is found
Returns:
the new location of the file after moving it
Throws:
FileTransferException - thrown if the temporary file does not exist, the final file already exists, or if the rename operation which moves the file fails

removeCachedFile

public boolean removeCachedFile(FileIdentifier fileIdentifier)
Removes a file from the cache. Does nothing if no such file is cached. Returns true if the file was successfully deleted from cache, otherwise false.

Parameters:
fileIdentifier - the identifier of the file to be removed
Returns:
true iff the file was deleted successfully


Copyright © 2015. All Rights Reserved.