org.codehaus.cargo.util
Interface FileHandler

All Known Implementing Classes:
DefaultFileHandler

public interface FileHandler

File operations that are performed in Cargo. All file operations must use this interface. This interface is also useful for unit testing as it's possible to create a mock implementation of it to prevent actual file operations from happening.

Version:
$Id: FileHandler.java 1248 2006-11-29 20:20:00Z vmassol $

Method Summary
 java.lang.String append(java.lang.String path, java.lang.String suffixToAppend)
          Append a suffix path to an existing path.
 void copy(java.io.InputStream in, java.io.OutputStream out)
          Copies data from an InputStream to an OutputStream using a default buffer size.
 void copy(java.io.InputStream in, java.io.OutputStream out, int bufSize)
          Copies data from an InputStream to an OutputStream.
 void copyDirectory(java.lang.String source, java.lang.String target)
          Copy a directory from a source to a destination.
 void copyDirectory(java.lang.String source, java.lang.String target, java.util.List excludes)
          Copy a directory from a source to a destination specifying files to be excluded.
 void copyFile(java.lang.String source, java.lang.String target)
          Copy a file from a source to a destination specifying if source files may overwrite newer destination files.
 java.lang.String createDirectory(java.lang.String parentDir, java.lang.String name)
          Convenience method for creating a new directory inside another one.
 void createFile(java.lang.String file)
          Create a file.
 java.lang.String createUniqueTmpDirectory()
          Creates a unique temporary directory.
 void delete(java.lang.String path)
          Deletes a file or directory, removing any children as appropriate.
 boolean exists(java.lang.String path)
           
 java.lang.String[] getChildren(java.lang.String directory)
           
 java.io.InputStream getInputStream(java.lang.String file)
           
 java.lang.String getName(java.lang.String file)
           
 java.io.OutputStream getOutputStream(java.lang.String file)
           
 java.lang.String getParent(java.lang.String path)
           
 java.lang.String getTmpPath(java.lang.String name)
          Compute the location of a temporary directory.
 java.lang.String getURL(java.lang.String path)
           
 boolean isDirectory(java.lang.String path)
           
 boolean isDirectoryEmpty(java.lang.String dir)
           
 void mkdirs(java.lang.String path)
          Create directories for the passed path.
 

Method Detail

copyFile

void copyFile(java.lang.String source,
              java.lang.String target)
Copy a file from a source to a destination specifying if source files may overwrite newer destination files.

Parameters:
source - the file to copy from. Must not be null.
target - the file to copy to. Must not be null.

copyDirectory

void copyDirectory(java.lang.String source,
                   java.lang.String target)
Copy a directory from a source to a destination.

Parameters:
source - the directory to copy from. Must not be null.
target - the directory to copy to. Must not be null.

copyDirectory

void copyDirectory(java.lang.String source,
                   java.lang.String target,
                   java.util.List excludes)
Copy a directory from a source to a destination specifying files to be excluded.

Parameters:
source - the directory to copy from. Must not be null.
target - the directory to copy to. Must not be null.
excludes - the list of files to be excluded. Each entry in the list is an Ant file pattern.

createDirectory

java.lang.String createDirectory(java.lang.String parentDir,
                                 java.lang.String name)
Convenience method for creating a new directory inside another one.

Parameters:
parentDir - The directory in which the new directory should be created
name - The name of the directory to create
Returns:
The new directory

copy

void copy(java.io.InputStream in,
          java.io.OutputStream out,
          int bufSize)
Copies data from an InputStream to an OutputStream.

Parameters:
in - InputStream to copy data from
out - OutputStream to copy data to
bufSize - size of the copy buffer

copy

void copy(java.io.InputStream in,
          java.io.OutputStream out)
Copies data from an InputStream to an OutputStream using a default buffer size.

Parameters:
in - InputStream to copy data from
out - OutputStream to copy data to

getTmpPath

java.lang.String getTmpPath(java.lang.String name)
Compute the location of a temporary directory.

Parameters:
name - The name of the directory to compute inside the tmp directory
Returns:
the location of the computed temporary directory

createUniqueTmpDirectory

java.lang.String createUniqueTmpDirectory()
Creates a unique temporary directory.

Returns:
the newly created temporary directory

delete

void delete(java.lang.String path)
Deletes a file or directory, removing any children as appropriate.

Parameters:
path - the path to the file or directory to remove

getInputStream

java.io.InputStream getInputStream(java.lang.String file)
Parameters:
file - the file for which to get an InputStream for
Returns:
an InputStream pointing to the file

getOutputStream

java.io.OutputStream getOutputStream(java.lang.String file)
Parameters:
file - the file for which to get an OutputStream for
Returns:
an OutputStream pointing to the file

append

java.lang.String append(java.lang.String path,
                        java.lang.String suffixToAppend)
Append a suffix path to an existing path.

Parameters:
path - the path to append to
suffixToAppend - the suffix to append to the path
Returns:
the new full path

mkdirs

void mkdirs(java.lang.String path)
Create directories for the passed path.

Parameters:
path - the path for which to create all directories leading to it

getParent

java.lang.String getParent(java.lang.String path)
Parameters:
path - the path for which to return its parent
Returns:
the parent path of the passed path

exists

boolean exists(java.lang.String path)
Parameters:
path - the path to check the existence for
Returns:
true if the path exists or false otherwise

createFile

void createFile(java.lang.String file)
Create a file.

Parameters:
file - the file to create

isDirectoryEmpty

boolean isDirectoryEmpty(java.lang.String dir)
Parameters:
dir - the directory to check
Returns:
true if the passed directory is empty

isDirectory

boolean isDirectory(java.lang.String path)
Parameters:
path - the path to verify
Returns:
true if the path passed is a directory or false otherwise

getName

java.lang.String getName(java.lang.String file)
Parameters:
file - the file name for which to return the file name
Returns:
the file name (without path nor extension)

getURL

java.lang.String getURL(java.lang.String path)
Parameters:
path - the path for which to return the URL
Returns:
the URL for the passed path

getChildren

java.lang.String[] getChildren(java.lang.String directory)
Parameters:
directory - the directory for which to return all children
Returns:
the children of the passed directory


Copyright © 2004-2010 Codehaus. All Rights Reserved.