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:
java.io.Closeable,java.lang.AutoCloseable,FileReplicator,TemporaryFileStore,VfsComponent
public class DefaultFileReplicator extends AbstractVfsComponent implements FileReplicator, TemporaryFileStore
A simple file replicator and temporary file store.
-
-
Constructor Summary
Constructors Constructor Description DefaultFileReplicator()Constructs a new instance.DefaultFileReplicator(java.io.File tempDir)Constructor to set the location of the temporary directory.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidaddFile(java.lang.Object file)Adds a file.java.io.FileallocateFile(java.lang.String baseName)Allocates a new temporary file.voidclose()Closes the replicator, deleting all temporary files.protected java.io.FilecreateAndAddFile(java.io.File parent, java.lang.String baseName)Adds a file.protected java.io.FilecreateFile(java.io.File parent, java.lang.String name)Create the temporary file.protected java.lang.StringcreateFilename(java.lang.String baseName)Create the temporary file name.protected voiddeleteFile(java.io.File file)Physically deletes the file from the file system.protected longgetFilecount()Gets the file count.voidinit()Initializes this component.protected java.lang.ObjectremoveFile()Removes a file from the copies list.protected voidremoveFile(java.lang.Object file)Removes an instance from the list of copies.java.io.FilereplicateFile(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 Detail
-
DefaultFileReplicator
public DefaultFileReplicator()
Constructs a new instance.
-
DefaultFileReplicator
public DefaultFileReplicator(java.io.File tempDir)
Constructor to set the location of the temporary directory.- Parameters:
tempDir- The temporary directory.
-
-
Method Detail
-
addFile
protected void addFile(java.lang.Object file)
Adds a file.- Parameters:
file- the file to add.
-
allocateFile
public java.io.File allocateFile(java.lang.String baseName) throws FileSystemException
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
public void close()
Closes the replicator, deleting all temporary files.- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Specified by:
closein interfaceVfsComponent- Overrides:
closein classAbstractVfsComponent
-
createAndAddFile
protected java.io.File createAndAddFile(java.io.File parent, java.lang.String baseName) throws FileSystemException
Adds a file.- Parameters:
parent- ignored.baseName- the base file name.- Returns:
- a File.
- Throws:
FileSystemException- if a file system error occurs.
-
createFile
protected java.io.File createFile(java.io.File parent, java.lang.String name) throws FileSystemException
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
protected java.lang.String createFilename(java.lang.String baseName)
Create the temporary file name.- Parameters:
baseName- The base to prepend to the file name being created.- Returns:
- the name of the File.
-
deleteFile
protected void deleteFile(java.io.File file)
Physically deletes the file from the file system.- Parameters:
file- The File to delete.
-
getFilecount
protected long getFilecount()
Gets the file count.- Returns:
- the file count.
-
init
public void init() throws FileSystemException
Initializes this component.- Specified by:
initin interfaceVfsComponent- Overrides:
initin classAbstractVfsComponent- Throws:
FileSystemException- if an error occurs.
-
removeFile
protected java.lang.Object 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
protected void removeFile(java.lang.Object file)
Removes an instance from the list of copies.- Parameters:
file- The File to remove.
-
replicateFile
public java.io.File replicateFile(FileObject srcFile, FileSelector selector) throws FileSystemException
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.
-
-