uk.org.retep.util.io
Class AbstractFileVisitor

java.lang.Object
  extended by uk.org.retep.util.io.AbstractFileVisitor
All Implemented Interfaces:
FileVisitor
Direct Known Subclasses:
TarCreateFileVisitor, ZipFileVisitor

public abstract class AbstractFileVisitor
extends java.lang.Object
implements FileVisitor

An abstract implementation of FileVisitor which can log a message every time a visit on a File returns true. For example, the FileVisitor returned by FileUtils.getSetExecutableVisitor() will log "Set executable on filename" whenever a file has been set executable. Note: If the supplied Log instance is null, then no logging is performed.

Author:
peter

Constructor Summary
AbstractFileVisitor()
          Create a visitor with no logging
AbstractFileVisitor(Log log)
          Equivalent to new AbstractFileVisitor( log, "Modified %s" );
AbstractFileVisitor(Log log, java.lang.String message)
          Construct a visitor with a Log and a message to log whenever an action is performed and returns true.
 
Method Summary
protected  void error(java.lang.String msg, java.lang.Object... args)
           
protected abstract  boolean execute(java.io.File file)
          Subclasses implement this method to perform an action on a File.
protected  void fatal(java.lang.String msg, java.lang.Object... args)
           
protected  void info(java.lang.String msg, java.lang.Object... args)
           
 boolean visit(java.io.File file)
          Call execute() on a file.
protected  void warn(java.lang.String msg, java.lang.Object... args)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractFileVisitor

public AbstractFileVisitor()
Create a visitor with no logging


AbstractFileVisitor

public AbstractFileVisitor(Log log)
Equivalent to new AbstractFileVisitor( log, "Modified %s" );

Parameters:
log - Log to use, ignored if null

AbstractFileVisitor

public AbstractFileVisitor(Log log,
                           java.lang.String message)
Construct a visitor with a Log and a message to log whenever an action is performed and returns true.

Parameters:
log - Log to use, ignored if null
message - The message to log when an action is performed and log is not null. One instance of %s is permitted, which is replaced by File.getPath()
Method Detail

info

protected final void info(java.lang.String msg,
                          java.lang.Object... args)

warn

protected final void warn(java.lang.String msg,
                          java.lang.Object... args)

error

protected final void error(java.lang.String msg,
                           java.lang.Object... args)

fatal

protected final void fatal(java.lang.String msg,
                           java.lang.Object... args)

visit

public final boolean visit(java.io.File file)
                    throws java.io.IOException
Call execute() on a file. If it returned true, then log a message (if a Log was provided). Nothing is logged if execute() returns false, or if no logger was provided.

Specified by:
visit in interface FileVisitor
Parameters:
file - File to visit
Returns:
true if an operation succeded, false if it did not perform
Throws:
java.io.IOException - when an error occurs

execute

protected abstract boolean execute(java.io.File file)
                            throws java.io.IOException
Subclasses implement this method to perform an action on a File.

Parameters:
file - File to visit
Returns:
true if an operation succeded, false if it did not perform
Throws:
java.io.IOException - when an error occurs


Copyright © 1998-2010 Retep Development Group. All Rights Reserved.