it.geosolutions.tools.io.file
Class CopyTree

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

public class CopyTree
extends org.apache.commons.io.DirectoryWalker<java.util.concurrent.Future<java.io.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(java.io.FileFilter filter, java.util.concurrent.CompletionService<java.io.File> cs, java.io.File sourceDir, java.io.File destDir)
           
CopyTree(java.io.FileFilter filter, java.util.concurrent.CompletionService<java.io.File> cs, int depth, java.io.File sourceDir, java.io.File destDir)
           
 
Method Summary
static java.util.concurrent.Future<java.io.File> asyncCopyTree(java.util.concurrent.CompletionService<java.io.File> cs, java.io.File source, java.io.File sourceDir, java.io.File destinationDir)
           
 java.util.Collection<java.util.concurrent.Future<java.io.File>> copy()
          Copy the entire tree recursively (depending from the passed filter) can be interrupted using setCancelled(true)
protected  java.io.File[] filterDirectoryContents(java.io.File directory, int depth, java.io.File[] files)
           
protected  void handleCancelled(java.io.File startDirectory, java.util.Collection<java.util.concurrent.Future<java.io.File>> results, org.apache.commons.io.DirectoryWalker.CancelException cancel)
           
protected  boolean handleDirectory(java.io.File directory, int depth, java.util.Collection<java.util.concurrent.Future<java.io.File>> results)
           
protected  void handleFile(java.io.File file, int depth, java.util.Collection<java.util.concurrent.Future<java.io.File>> results)
           
protected  boolean handleIsCancelled(java.io.File file, int depth, java.util.Collection<java.util.concurrent.Future<java.io.File>> results)
           
 boolean isCancelled()
           
 void setCancelled(boolean cancelled)
           
 
Methods inherited from class org.apache.commons.io.DirectoryWalker
checkIfCancelled, handleDirectoryEnd, handleDirectoryStart, handleEnd, handleRestricted, handleStart, walk
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CopyTree

public CopyTree(java.io.FileFilter filter,
                java.util.concurrent.CompletionService<java.io.File> cs,
                java.io.File sourceDir,
                java.io.File destDir)

CopyTree

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

isCancelled

public final boolean isCancelled()
Returns:
the cancelled

setCancelled

public final void setCancelled(boolean cancelled)
Parameters:
cancelled - the cancelled to set

copy

public java.util.Collection<java.util.concurrent.Future<java.io.File>> copy()
Copy the entire tree recursively (depending from the passed filter) can be interrupted using setCancelled(true)

Parameters:
root -
Returns:
list of file (can be null if interrupted)
Throws:
java.io.IOException

handleIsCancelled

protected boolean handleIsCancelled(java.io.File file,
                                    int depth,
                                    java.util.Collection<java.util.concurrent.Future<java.io.File>> results)
                             throws java.io.IOException
Overrides:
handleIsCancelled in class org.apache.commons.io.DirectoryWalker<java.util.concurrent.Future<java.io.File>>
Throws:
java.io.IOException

handleCancelled

protected void handleCancelled(java.io.File startDirectory,
                               java.util.Collection<java.util.concurrent.Future<java.io.File>> results,
                               org.apache.commons.io.DirectoryWalker.CancelException cancel)
                        throws java.io.IOException
Overrides:
handleCancelled in class org.apache.commons.io.DirectoryWalker<java.util.concurrent.Future<java.io.File>>
Throws:
java.io.IOException

handleDirectory

protected boolean handleDirectory(java.io.File directory,
                                  int depth,
                                  java.util.Collection<java.util.concurrent.Future<java.io.File>> results)
                           throws java.io.IOException
Overrides:
handleDirectory in class org.apache.commons.io.DirectoryWalker<java.util.concurrent.Future<java.io.File>>
Throws:
java.io.IOException

filterDirectoryContents

protected java.io.File[] filterDirectoryContents(java.io.File directory,
                                                 int depth,
                                                 java.io.File[] files)
                                          throws java.io.IOException
Overrides:
filterDirectoryContents in class org.apache.commons.io.DirectoryWalker<java.util.concurrent.Future<java.io.File>>
Throws:
java.io.IOException

handleFile

protected void handleFile(java.io.File file,
                          int depth,
                          java.util.Collection<java.util.concurrent.Future<java.io.File>> results)
                   throws java.io.IOException
Overrides:
handleFile in class org.apache.commons.io.DirectoryWalker<java.util.concurrent.Future<java.io.File>>
Throws:
java.io.IOException

asyncCopyTree

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


Copyright © 2011-2012 GeoSolutions. All Rights Reserved.