Package org.apache.commons.vfs2.impl
Class DefaultFileReplicator
java.lang.Object
org.apache.commons.vfs2.provider.AbstractVfsComponent
org.apache.commons.vfs2.impl.DefaultFileReplicator
- All Implemented Interfaces:
Closeable,AutoCloseable,FileReplicator,TemporaryFileStore,VfsComponent
public class DefaultFileReplicator
extends AbstractVfsComponent
implements FileReplicator, TemporaryFileStore
A simple file replicator and temporary file store.
-
Constructor Summary
ConstructorsConstructorDescriptionConstructs a new instance.DefaultFileReplicator(File tempDir) Constructor to set the location of the temporary directory. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidAdds a file.allocateFile(String baseName) Allocates a new temporary file.voidclose()Closes the replicator, deleting all temporary files.protected FilecreateAndAddFile(File parent, String baseName) Adds a file.protected FilecreateFile(File parent, String name) Create the temporary file.protected StringcreateFilename(String baseName) Create the temporary file name.protected voiddeleteFile(File file) Physically deletes the file from the file system.protected longGets the file count.voidinit()Initializes this component.protected ObjectRemoves a file from the copies list.protected voidremoveFile(Object file) Removes an instance from the list of copies.replicateFile(FileObject srcFile, FileSelector selector) Creates a local copy of the file, and all its descendants.Methods inherited from class org.apache.commons.vfs2.provider.AbstractVfsComponent
getContext, getLogger, setContext, setLogger
-
Constructor Details
-
DefaultFileReplicator
public DefaultFileReplicator()Constructs a new instance. -
DefaultFileReplicator
Constructor to set the location of the temporary directory.- Parameters:
tempDir- The temporary directory.
-
-
Method Details
-
addFile
Adds a file.- Parameters:
file- the file to add.
-
allocateFile
Allocates a new temporary file.- Specified by:
allocateFilein interfaceTemporaryFileStore- Parameters:
baseName- the base file name.- Returns:
- The created File.
- Throws:
FileSystemException- if an error occurs.
-
close
Closes the replicator, deleting all temporary files.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Specified by:
closein interfaceVfsComponent- Overrides:
closein classAbstractVfsComponent
-
createAndAddFile
Adds a file.- Parameters:
parent- ignored.baseName- the base file name.- Returns:
- a File.
- Throws:
FileSystemException- if a file system error occurs.
-
createFile
Create the temporary file.- Parameters:
parent- The file to use as the parent of the file being created.name- The name of the file to create.- Returns:
- The File that was created.
- Throws:
FileSystemException- if an error occurs creating the file.
-
createFilename
Create the temporary file name.- Parameters:
baseName- The base to prepend to the file name being created.- Returns:
- the name of the File.
-
deleteFile
Physically deletes the file from the file system.- Parameters:
file- The File to delete.
-
getFilecount
Gets the file count.- Returns:
- the file count.
-
init
Initializes this component.- Specified by:
initin interfaceVfsComponent- Overrides:
initin classAbstractVfsComponent- Throws:
FileSystemException- if an error occurs.
-
removeFile
Removes a file from the copies list. Will be used for cleanup.Notice: The system awaits that the returning object can be cast to a
File.- Returns:
- the File that was removed.
-
removeFile
Removes an instance from the list of copies.- Parameters:
file- The File to remove.
-
replicateFile
Creates a local copy of the file, and all its descendants.- Specified by:
replicateFilein interfaceFileReplicator- Parameters:
srcFile- The file to copy.selector- The FileSelector.- Returns:
- the created File.
- Throws:
FileSystemException- if an error occurs copying the file.
-