it.geosolutions.tools.io.file
Class CopyTree

java.lang.Object
  extended by org.apache.commons.io.DirectoryWalker<Future<File>>
      extended by it.geosolutions.tools.io.file.CopyTree

public class CopyTree
extends org.apache.commons.io.DirectoryWalker<Future<File>>

Copy a Tree recursively and asynchronously

Author:
Carlo Cancellieri - carlo.cancellieri@geo-solutions.it

Nested Class Summary
 
Nested classes/interfaces inherited from class org.apache.commons.io.DirectoryWalker
org.apache.commons.io.DirectoryWalker.CancelException
 
Constructor Summary
CopyTree(FileFilter filter, CompletionService<File> cs, File sourceDir, File destDir)
          CopyTree(FileFilter, CompletionService, int, File, File)
CopyTree(FileFilter filter, CompletionService<File> cs, int depth, File sourceDir, File destDir)
           
 
Method Summary
 boolean addCollectingListener(Progress<String> listener)
           
 boolean addCopyListener(Progress<String> listener)
           
static Future<File> asyncCopyTree(CompletionService<File> cs, File source, File sourceDir, File destinationDir, Progress<String> listener)
           
 int copy()
          Copy the entire tree recursively (depending from the passed filter) can be interrupted using setCancelled(true)
protected  File[] filterDirectoryContents(File directory, int depth, File[] files)
          #DirectoryWalker#filterDirectoryContents(File, int, File[])
protected  void handleCancelled(File startDirectory, Collection<Future<File>> results, org.apache.commons.io.DirectoryWalker.CancelException cancel)
          #DirectoryWalker#handleCancelled(File, Collection, org.apache.commons.io.DirectoryWalker.CancelException)
protected  boolean handleDirectory(File directory, int depth, Collection<Future<File>> results)
          #DirectoryWalker#handleDirectory(File, int, Collection)
protected  void handleEnd(Collection<Future<File>> results)
          collecting operation is concluded DirectoryWalker.handleEnd(Collection)
protected  void handleFile(File file, int depth, Collection<Future<File>> results)
          This method is called by the DirectoryWalker.walk() one.
protected  boolean handleIsCancelled(File file, int depth, Collection<Future<File>> results)
          #DirectoryWalker#handleIsCancelled(File, int, Collection)
protected  void handleStart(File startDirectory, Collection<Future<File>> results)
          collecting operation is started DirectoryWalker.handleEnd(Collection)
 boolean isCancelled()
           
 void reset(boolean force)
          Deprecated. untested method
 void setCancelled()
          set the canceled status for all pending operations
 
Methods inherited from class org.apache.commons.io.DirectoryWalker
checkIfCancelled, handleDirectoryEnd, handleDirectoryStart, handleRestricted, walk
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CopyTree

public CopyTree(FileFilter filter,
                CompletionService<File> cs,
                File sourceDir,
                File destDir)
CopyTree(FileFilter, CompletionService, int, File, File)


CopyTree

public CopyTree(FileFilter filter,
                CompletionService<File> cs,
                int depth,
                File sourceDir,
                File destDir)
Parameters:
filter - the filter to apply, null means visit all files
cs - the CompletionService to use
depth - controls how deep the hierarchy is navigated to (less than 0 means unlimited)
sourceDir -
destDir -
Method Detail

isCancelled

public final boolean isCancelled()
Returns:
check if any op. is canceled

setCancelled

public final void setCancelled()
set the canceled status for all pending operations


addCollectingListener

public boolean addCollectingListener(Progress<String> listener)
Parameters:
listener - the listener to add
Returns:
as specified Collection.add(Object)

addCopyListener

public boolean addCopyListener(Progress<String> listener)
Parameters:
listener - the listener to add
Returns:
as specified Collection.add(Object)

reset

public void reset(boolean force)
Deprecated. untested method

Call reset to clean the object state

Parameters:
force - if in progress works should be canceled

copy

public int copy()
         throws IOException,
                IllegalStateException
Copy the entire tree recursively (depending from the passed filter) can be interrupted using setCancelled(true)

Returns:
number of files scheduled for the copy
Throws:
IOException - DirectoryWalker.walk(File, Collection)
IllegalStateException - if CopyTree object is not in a legal state: call #reset()

asyncCopyTree

public static Future<File> asyncCopyTree(CompletionService<File> cs,
                                         File source,
                                         File sourceDir,
                                         File destinationDir,
                                         Progress<String> listener)
                                  throws RejectedExecutionException,
                                         IllegalArgumentException
Parameters:
cs - CompletionService
source - file to copy
sourceDir - where source is mounted
destinationDir - mount point where to copy source
Returns:
Throws:
RejectedExecutionException - - if this task cannot be accepted for execution.
IllegalArgumentException - - if executor is null or terminated.

handleIsCancelled

protected boolean handleIsCancelled(File file,
                                    int depth,
                                    Collection<Future<File>> results)
                             throws IOException
#DirectoryWalker#handleIsCancelled(File, int, Collection)

Overrides:
handleIsCancelled in class org.apache.commons.io.DirectoryWalker<Future<File>>
Throws:
IOException

handleCancelled

protected void handleCancelled(File startDirectory,
                               Collection<Future<File>> results,
                               org.apache.commons.io.DirectoryWalker.CancelException cancel)
                        throws IOException
#DirectoryWalker#handleCancelled(File, Collection, org.apache.commons.io.DirectoryWalker.CancelException)

Overrides:
handleCancelled in class org.apache.commons.io.DirectoryWalker<Future<File>>
Throws:
IOException

handleDirectory

protected boolean handleDirectory(File directory,
                                  int depth,
                                  Collection<Future<File>> results)
                           throws IOException
#DirectoryWalker#handleDirectory(File, int, Collection)

Overrides:
handleDirectory in class org.apache.commons.io.DirectoryWalker<Future<File>>
Throws:
IOException

filterDirectoryContents

protected File[] filterDirectoryContents(File directory,
                                         int depth,
                                         File[] files)
                                  throws IOException
#DirectoryWalker#filterDirectoryContents(File, int, File[])

Overrides:
filterDirectoryContents in class org.apache.commons.io.DirectoryWalker<Future<File>>
Throws:
IOException

handleFile

protected void handleFile(File file,
                          int depth,
                          Collection<Future<File>> results)
                   throws IOException,
                          SecurityException
This method is called by the DirectoryWalker.walk() one. Here we:
#DirectoryWalker#handleFile(File, int, Collection)

Overrides:
handleFile in class org.apache.commons.io.DirectoryWalker<Future<File>>
Throws:
IOException
SecurityException

handleStart

protected void handleStart(File startDirectory,
                           Collection<Future<File>> results)
                    throws IOException
collecting operation is started DirectoryWalker.handleEnd(Collection)

Overrides:
handleStart in class org.apache.commons.io.DirectoryWalker<Future<File>>
Throws:
IOException

handleEnd

protected void handleEnd(Collection<Future<File>> results)
                  throws IOException
collecting operation is concluded DirectoryWalker.handleEnd(Collection)

Overrides:
handleEnd in class org.apache.commons.io.DirectoryWalker<Future<File>>
Throws:
IOException


Copyright © 2011-2012 GeoSolutions. All Rights Reserved.