org.codehaus.cargo.util
Class DefaultFileHandler

java.lang.Object
  extended by org.codehaus.cargo.util.DefaultFileHandler
All Implemented Interfaces:
FileHandler

public class DefaultFileHandler
extends java.lang.Object
implements FileHandler

File operations that are performed in Cargo. All file operations must use this class.

Version:
$Id: DefaultFileHandler.java 1906 2009-02-19 16:43:11Z mwringe $

Constructor Summary
DefaultFileHandler()
          Initializations.
 
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.
 void copyFile(java.lang.String source, java.lang.String target, boolean overwrite)
          Copy a file from a source to a destination specifying if source files may overwrite newer destination files.
 void copyFile(java.lang.String source, java.lang.String target, org.apache.tools.ant.types.FilterChain filterChain)
          Copy a file from a source to a destination using a filterchain to specify token replacement.
 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 getAbsolutePath(java.lang.String path)
          gets the absolute path from a file that may be relative to the current directory.
 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.
 java.lang.String readTextFile(java.lang.String file)
          
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultFileHandler

public DefaultFileHandler()
Initializations.

Method Detail

copyFile

public 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.

Specified by:
copyFile in interface FileHandler
Parameters:
source - the file to copy from. Must not be null.
target - the file to copy to. Must not be null.
See Also:
FileHandler.copyFile(String, String)

copyFile

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

Specified by:
copyFile in interface FileHandler
Parameters:
source - the file to copy from. Must not be null.
target - the file to copy to. Must not be null.
overwrite - to overwrite the file if it already exists.
See Also:
FileHandler.copyFile(String, String)

copyFile

public void copyFile(java.lang.String source,
                     java.lang.String target,
                     org.apache.tools.ant.types.FilterChain filterChain)
Copy a file from a source to a destination using a filterchain to specify token replacement.

Specified by:
copyFile in interface FileHandler
Parameters:
source - the file to copy from. Must not be null
target - the file to copy to. Must not be null
filterChain - the filterChain to use. Must not be null
See Also:
FileHander#copyFile(String, String, FilterChain)

copyDirectory

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

Specified by:
copyDirectory in interface FileHandler
Parameters:
source - the directory to copy from. Must not be null.
target - the directory to copy to. Must not be null.
See Also:
FileHandler.copyDirectory(String, String)

copyDirectory

public 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.

Specified by:
copyDirectory in interface FileHandler
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.
See Also:
FileHandler.copyDirectory(String, String)

createDirectory

public java.lang.String createDirectory(java.lang.String parentDir,
                                        java.lang.String name)
Convenience method for creating a new directory inside another one. If the directory already exists, it will return the already created directory.

Specified by:
createDirectory in interface FileHandler
Parameters:
parentDir - The directory in which the new directory should be created
name - The name of the directory to create
Returns:
The new directory
See Also:
FileHandler.createDirectory(String, String)

copy

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

Specified by:
copy in interface FileHandler
Parameters:
in - InputStream to copy data from
out - OutputStream to copy data to
bufSize - size of the copy buffer
See Also:
FileHandler.copy(java.io.InputStream, java.io.OutputStream, int)

copy

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

Specified by:
copy in interface FileHandler
Parameters:
in - InputStream to copy data from
out - OutputStream to copy data to
See Also:
FileHandler.copy(java.io.InputStream, java.io.OutputStream, int)

getTmpPath

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

Specified by:
getTmpPath in interface FileHandler
Parameters:
name - The name of the directory to compute inside the tmp directory
Returns:
the location of the computed temporary directory
See Also:
FileHandler.getTmpPath(String)

createUniqueTmpDirectory

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

Specified by:
createUniqueTmpDirectory in interface FileHandler
Returns:
the newly created temporary directory
See Also:
FileHandler.createUniqueTmpDirectory()

delete

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

Specified by:
delete in interface FileHandler
Parameters:
path - the path to the file or directory to remove
See Also:
FileHandler.delete(String)

getInputStream

public java.io.InputStream getInputStream(java.lang.String file)

Specified by:
getInputStream in interface FileHandler
Parameters:
file - the file for which to get an InputStream for
Returns:
an InputStream pointing to the file
See Also:
FileHandler.getInputStream(String)

getOutputStream

public java.io.OutputStream getOutputStream(java.lang.String file)

Specified by:
getOutputStream in interface FileHandler
Parameters:
file - the file for which to get an OutputStream for
Returns:
an OutputStream pointing to the file
See Also:
FileHandler.getOutputStream(String)

append

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

Specified by:
append in interface FileHandler
Parameters:
path - the path to append to
suffixToAppend - the suffix to append to the path
Returns:
the new full path
See Also:
FileHandler.append(String, String)

mkdirs

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

Specified by:
mkdirs in interface FileHandler
Parameters:
path - the path for which to create all directories leading to it
See Also:
FileHandler.mkdirs(String)

getParent

public java.lang.String getParent(java.lang.String path)

Specified by:
getParent in interface FileHandler
Parameters:
path - the path for which to return its parent
Returns:
the parent path of the passed path
See Also:
FileHandler.getParent(String)

exists

public boolean exists(java.lang.String path)

Specified by:
exists in interface FileHandler
Parameters:
path - the path to check the existence for
Returns:
true if the path exists or false otherwise
See Also:
FileHandler.exists(String)

createFile

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

Specified by:
createFile in interface FileHandler
Parameters:
file - the file to create
See Also:
FileHandler.createFile(String)

isDirectoryEmpty

public boolean isDirectoryEmpty(java.lang.String dir)

Specified by:
isDirectoryEmpty in interface FileHandler
Parameters:
dir - the directory to check
Returns:
true if the passed directory is empty
See Also:
FileHandler.isDirectoryEmpty(String)

getName

public java.lang.String getName(java.lang.String file)

Specified by:
getName in interface FileHandler
Parameters:
file - the file name for which to return the file name
Returns:
the file name (without path nor extension)
See Also:
FileHandler.getName(String)

getURL

public java.lang.String getURL(java.lang.String path)

Specified by:
getURL in interface FileHandler
Parameters:
path - the path for which to return the URL
Returns:
the URL for the passed path
See Also:
FileHandler.getURL(String)

isDirectory

public boolean isDirectory(java.lang.String path)

Specified by:
isDirectory in interface FileHandler
Parameters:
path - the path to verify
Returns:
true if the path passed is a directory or false otherwise
See Also:
FileHandler.isDirectory(String)

getChildren

public java.lang.String[] getChildren(java.lang.String directory)

Specified by:
getChildren in interface FileHandler
Parameters:
directory - the directory for which to return all children
Returns:
the children of the passed directory
See Also:
FileHandler.getChildren(String)

getAbsolutePath

public java.lang.String getAbsolutePath(java.lang.String path)
gets the absolute path from a file that may be relative to the current directory.

Specified by:
getAbsolutePath in interface FileHandler
Parameters:
path - - what to extract the file path from
Returns:
- absolute path to the file
See Also:
FileHandler.getAbsolutePath(String)

readTextFile

public java.lang.String readTextFile(java.lang.String file)

Specified by:
readTextFile in interface FileHandler
Parameters:
file - the file for which to load into a String object.
Returns:
a String with the file's contents.
See Also:
FileHandler.readTextFile(String)


Copyright © 2004-2011 Codehaus. All Rights Reserved.