org.eclipse.emf.test.build
Class FileTool

java.lang.Object
  extended by org.eclipse.emf.test.build.FileTool

public class FileTool
extends java.lang.Object

A tool for performing operations on files.


Nested Class Summary
static interface FileTool.IZipFilter
          A zip filter which is used to filter out unwanted entries while extracting a zip file.
 
Constructor Summary
FileTool()
           
 
Method Summary
static java.lang.String changeSeparator(java.lang.String path, char oldSeparator, char newSeparator)
          Returns the given file path with its separator character changed from the given old separator to the given new separator.
static boolean compare(java.io.File file1, java.io.File file2)
          Returns a boolean indicating whether the given files have the same content.
static void copy(java.io.File src, java.io.File dst)
          Copies the given source file to the given destination file.
static void copy(java.io.File root, java.io.File src, java.io.File dst)
          Copies the given source file to the given destination file.
static void delete(java.io.File file)
          Delete the given file or directory.
static java.io.File getFile(java.lang.String[] segments)
          Returns a new File from the given path name segments.
static java.io.File[] getFiles(java.io.File dir, java.lang.String[] include, java.lang.String[] exclude)
          Returns a list of all files below the given directory that end with a string in the given include list and do not end with a string in the given exclude list.
static java.lang.String[] getSegments(java.io.File file)
          Breaks the given file into its path name segments and returns the result.
static java.lang.String[] getSegments(java.lang.String s, char separator)
          Breaks the given string into segments and returns the result.
static java.io.File[] parsePaths(java.lang.String paths)
          Returns a vector of File paths parsed from the given paths string.
static void transferData(java.io.File source, java.io.File destination)
          Copies all bytes in the given source file to the given destination file.
static void transferData(java.io.InputStream source, java.io.OutputStream destination)
          Copies all bytes in the given source stream to the given destination stream.
static void unzip(FileTool.IZipFilter filter, java.util.zip.ZipFile zipFile, java.io.File dstDir)
          Unzips the given zip file to the given destination directory extracting only those entries the pass through the given filter.
static void zip(java.io.File dir, java.io.File zipFile)
          Zips the given directory to the given zip file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FileTool

public FileTool()
Method Detail

changeSeparator

public static java.lang.String changeSeparator(java.lang.String path,
                                               char oldSeparator,
                                               char newSeparator)
Returns the given file path with its separator character changed from the given old separator to the given new separator.

Parameters:
path - a file path
oldSeparator - a path separator character
newSeparator - a path separator character
Returns:
the file path with its separator character changed from the given old separator to the given new separator

compare

public static boolean compare(java.io.File file1,
                              java.io.File file2)
                       throws java.io.IOException
Returns a boolean indicating whether the given files have the same content.

Parameters:
file1 - the first file
file2 - the second file
Returns:
a boolean indicating whether the given files have the same content
Throws:
java.io.IOException

copy

public static void copy(java.io.File src,
                        java.io.File dst)
                 throws java.io.IOException
Copies the given source file to the given destination file.

Parameters:
src - the given source file
dst - the given destination file
Throws:
java.io.IOException

copy

public static void copy(java.io.File root,
                        java.io.File src,
                        java.io.File dst)
                 throws java.io.IOException
Copies the given source file to the given destination file.

Parameters:
root -
src - the given source file
dst - the given destination file
Throws:
java.io.IOException

delete

public static void delete(java.io.File file)
Delete the given file or directory. Directories are deleted recursively. If the file or directory can not be deleted, a warning message is written to stdout.

Parameters:
file - a file or directory

getFile

public static java.io.File getFile(java.lang.String[] segments)
Returns a new File from the given path name segments.

Parameters:
segments - the given path name segments
Returns:
a new File from the given path name segments

getFiles

public static java.io.File[] getFiles(java.io.File dir,
                                      java.lang.String[] include,
                                      java.lang.String[] exclude)
Returns a list of all files below the given directory that end with a string in the given include list and do not end with a string in the given exclude list. If include is null all files are included except those that are explicitly excluded. If exclude is null no files are excluded except those that are not included.

Parameters:
dir - the given directory
include - a list of filenames to include
exclude - a list of filenames to exclude
Returns:
a list of all files below the given directory that are included and not explicitly excluded

getSegments

public static java.lang.String[] getSegments(java.io.File file)
Breaks the given file into its path name segments and returns the result.

Parameters:
file - a file or directory
Returns:
the path name segments of the given file

getSegments

public static java.lang.String[] getSegments(java.lang.String s,
                                             char separator)
Breaks the given string into segments and returns the result.

Parameters:
s - a string
separator - the segment separator
Returns:
the segments of the given string

parsePaths

public static java.io.File[] parsePaths(java.lang.String paths)
Returns a vector of File paths parsed from the given paths string.

Parameters:
paths - a paths string
Returns:
a vector of File paths parsed from the given paths string

transferData

public static void transferData(java.io.File source,
                                java.io.File destination)
                         throws java.io.IOException
Copies all bytes in the given source file to the given destination file.

Parameters:
source - the given source file
destination - the given destination file
Throws:
java.io.IOException

transferData

public static void transferData(java.io.InputStream source,
                                java.io.OutputStream destination)
                         throws java.io.IOException
Copies all bytes in the given source stream to the given destination stream. Neither streams are closed.

Parameters:
source - the given source stream
destination - the given destination stream
Throws:
java.io.IOException

unzip

public static void unzip(FileTool.IZipFilter filter,
                         java.util.zip.ZipFile zipFile,
                         java.io.File dstDir)
                  throws java.io.IOException
Unzips the given zip file to the given destination directory extracting only those entries the pass through the given filter.

Parameters:
filter - filters out unwanted zip entries
zipFile - the zip file to unzip
dstDir - the destination directory
Throws:
java.io.IOException

zip

public static void zip(java.io.File dir,
                       java.io.File zipFile)
                throws java.io.IOException
Zips the given directory to the given zip file. Directories are zipped recursively. Inner zip files are created for directories that end with "_zip" or "_jar". If verbose is true, progress information is logged.

Parameters:
dir - the directory to zip
zipFile - the resulting zip file
Throws:
java.io.IOException

Copyright 2001-2006 IBM Corporation and others.
All Rights Reserved.