org.apache.commons.vfs2.impl
Class DefaultFileReplicator

java.lang.Object
  extended by org.apache.commons.vfs2.provider.AbstractVfsComponent
      extended by org.apache.commons.vfs2.impl.DefaultFileReplicator
All Implemented Interfaces:
FileReplicator, TemporaryFileStore, VfsComponent

public class DefaultFileReplicator
extends AbstractVfsComponent
implements FileReplicator, TemporaryFileStore

A simple file replicator and temporary file store.

Author:
Commons VFS team

Constructor Summary
DefaultFileReplicator()
           
DefaultFileReplicator(File tempDir)
          constructor to set the location of the temporary directory.
 
Method Summary
protected  void addFile(Object file)
           
 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)
           
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 filesystem
protected  long getFilecount()
           
 void init()
          Initialises this component.
protected  Object removeFile()
          removes a file from the copies list.
protected  void removeFile(Object file)
          removes a instance from the list of copies
 File replicateFile(FileObject srcFile, FileSelector selector)
          Creates a local copy of the file, and all its descendents.
 
Methods inherited from class org.apache.commons.vfs2.provider.AbstractVfsComponent
getContext, getLogger, setContext, setLogger
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultFileReplicator

public DefaultFileReplicator(File tempDir)
constructor to set the location of the temporary directory.

Parameters:
tempDir - The temporary directory.

DefaultFileReplicator

public DefaultFileReplicator()
Method Detail

init

public void init()
          throws FileSystemException
Initialises this component.

Specified by:
init in interface VfsComponent
Overrides:
init in class AbstractVfsComponent
Throws:
FileSystemException - if an error occurs.

close

public void close()
Closes the replicator, deleting all temporary files.

Specified by:
close in interface VfsComponent
Overrides:
close in class AbstractVfsComponent

deleteFile

protected void deleteFile(File file)
physically deletes the file from the filesystem

Parameters:
file - The File to delete.

removeFile

protected 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 java.io.File

Returns:
the File that was removed.

removeFile

protected void removeFile(Object file)
removes a instance from the list of copies

Parameters:
file - The File to remove.

allocateFile

public File allocateFile(String baseName)
                  throws FileSystemException
Allocates a new temporary file.

Specified by:
allocateFile in interface TemporaryFileStore
Parameters:
baseName - the base file name.
Returns:
The created File.
Throws:
FileSystemException - if an error occurs.

createAndAddFile

protected File createAndAddFile(File parent,
                                String basename)
                         throws FileSystemException
Throws:
FileSystemException

addFile

protected void addFile(Object file)

getFilecount

protected long getFilecount()

createFilename

protected String createFilename(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.

createFile

protected File createFile(File parent,
                          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.

replicateFile

public File replicateFile(FileObject srcFile,
                          FileSelector selector)
                   throws FileSystemException
Creates a local copy of the file, and all its descendents.

Specified by:
replicateFile in interface FileReplicator
Parameters:
srcFile - The file to copy.
selector - The FileSelector.
Returns:
the created File.
Throws:
FileSystemException - if an error occurs copying the file.


Copyright © 2002-2012 The Apache Software Foundation. All Rights Reserved.