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.
  • Field Details

    • log

      private static final org.apache.commons.logging.Log log
    • MASK

      private static final int MASK
      See Also:
    • random

      private static final Random random
    • TMP_RESERVED_CHARS

      private static final char[] TMP_RESERVED_CHARS
    • copies

      private final ArrayList<Object> copies
    • filecount

      private long filecount
    • tempDir

      private File tempDir
    • tempDirMessageLogged

      private boolean tempDirMessageLogged
  • Constructor Details

    • DefaultFileReplicator

      public DefaultFileReplicator()
    • DefaultFileReplicator

      public DefaultFileReplicator(File tempDir)
      Constructor to set the location of the temporary directory.
      Parameters:
      tempDir - The temporary directory.
  • Method Details

    • addFile

      protected void addFile(Object file)
    • 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.
    • close

      public void close()
      Closes the replicator, deleting all temporary files.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Specified by:
      close in interface VfsComponent
      Overrides:
      close in class AbstractVfsComponent
    • createAndAddFile

      protected File createAndAddFile(File parent, String basename) throws FileSystemException
      Throws:
      FileSystemException
    • 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.
    • 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.
    • deleteFile

      protected void deleteFile(File file)
      Physically deletes the file from the file system.
      Parameters:
      file - The File to delete.
    • getFilecount

      protected long getFilecount()
    • init

      public void init() throws FileSystemException
      Initializes this component.
      Specified by:
      init in interface VfsComponent
      Overrides:
      init in class AbstractVfsComponent
      Throws:
      FileSystemException - if an error occurs.
    • 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 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.
    • replicateFile

      public File replicateFile(FileObject srcFile, FileSelector selector) throws FileSystemException
      Creates a local copy of the file, and all its descendants.
      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.