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 void
Adds a file.allocateFile
(String baseName) Allocates a new temporary file.void
close()
Closes the replicator, deleting all temporary files.protected File
createAndAddFile
(File parent, String baseName) Adds a file.protected File
createFile
(File parent, String name) Create the temporary file.protected String
createFilename
(String baseName) Create the temporary file name.protected void
deleteFile
(File file) Physically deletes the file from the file system.protected long
Gets the file count.void
init()
Initializes this component.protected Object
Removes a file from the copies list.protected void
removeFile
(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:
allocateFile
in 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:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Specified by:
close
in interfaceVfsComponent
- Overrides:
close
in 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:
init
in interfaceVfsComponent
- Overrides:
init
in 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:
replicateFile
in interfaceFileReplicator
- Parameters:
srcFile
- The file to copy.selector
- The FileSelector.- Returns:
- the created File.
- Throws:
FileSystemException
- if an error occurs copying the file.
-