Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.apache.tools.ant.util
Class FileUtils

    java.lang.Object
      org.apache.tools.ant.util.FileUtils

public class FileUtils
extends java.lang.Object

This class also encapsulates methods which allow Files to be refered to using abstract path names which are translated to native system file paths at runtime as well as copying files or setting there last modification time.

Version:
  $Revision: 1.25.2.8 $
Author:
  duncan@x180.com, Conor MacNeill, Stefan Bodewig, Magesh Umasankar, Jeff Tulley

Constructor Summary
`protected` | `FileUtils()` Empty constructor.

Method Summary
`boolean` | `contentEquals(java.io.File f1, java.io.File f2)` Compares the contents of two files.
`void` | `copyFile(java.io.File sourceFile, java.io.File destFile)` Convienence method to copy a file from a source to a destination.
`void` | `copyFile(java.io.File sourceFile, java.io.File destFile, FilterSetCollection filters)` Convienence method to copy a file from a source to a destination specifying if token filtering must be used.
`void` | `copyFile(java.io.File sourceFile, java.io.File destFile, FilterSetCollection filters, boolean overwrite)` Convienence method to copy a file from a source to a destination specifying if token filtering must be used and if source files may overwrite newer destination files.
`void` | `copyFile(java.io.File sourceFile, java.io.File destFile, FilterSetCollection filters, boolean overwrite, boolean preserveLastModified)` Convienence method to copy a file from a source to a destination specifying if token filtering must be used, if source files may overwrite newer destination files and the last modified time of `destFile` file should be made equal to the last modified time of `sourceFile`.
`void` | `copyFile(java.io.File sourceFile, java.io.File destFile, FilterSetCollection filters, boolean overwrite, boolean preserveLastModified, java.lang.String encoding)` Convienence method to copy a file from a source to a destination specifying if token filtering must be used, if source files may overwrite newer destination files, the last modified time of `destFile` file should be made equal to the last modified time of `sourceFile` and which character encoding to assume.
`void` | `copyFile(java.io.File sourceFile, java.io.File destFile, FilterSetCollection filters, java.util.Vector filterChains, boolean overwrite, boolean preserveLastModified, java.lang.String encoding, Project project)` Convienence method to copy a file from a source to a destination specifying if token filtering must be used, if filter chains must be used, if source files may overwrite newer destination files and the last modified time of `destFile` file should be made equal to the last modified time of `sourceFile`.
`void` | `copyFile(java.lang.String sourceFile, java.lang.String destFile)` Convienence method to copy a file from a source to a destination.
`void` | `copyFile(java.lang.String sourceFile, java.lang.String destFile, FilterSetCollection filters)` Convienence method to copy a file from a source to a destination specifying if token filtering must be used.
`void` | `copyFile(java.lang.String sourceFile, java.lang.String destFile, FilterSetCollection filters, boolean overwrite)` Convienence method to copy a file from a source to a destination specifying if token filtering must be used and if source files may overwrite newer destination files.
`void` | `copyFile(java.lang.String sourceFile, java.lang.String destFile, FilterSetCollection filters, boolean overwrite, boolean preserveLastModified)` Convienence method to copy a file from a source to a destination specifying if token filtering must be used, if source files may overwrite newer destination files and the last modified time of `destFile` file should be made equal to the last modified time of `sourceFile`.
`void` | `copyFile(java.lang.String sourceFile, java.lang.String destFile, FilterSetCollection filters, boolean overwrite, boolean preserveLastModified, java.lang.String encoding)` Convienence method to copy a file from a source to a destination specifying if token filtering must be used, if source files may overwrite newer destination files and the last modified time of `destFile` file should be made equal to the last modified time of `sourceFile`.
`void` | `copyFile(java.lang.String sourceFile, java.lang.String destFile, FilterSetCollection filters, java.util.Vector filterChains, boolean overwrite, boolean preserveLastModified, java.lang.String encoding, Project project)` Convienence method to copy a file from a source to a destination specifying if token filtering must be used, if filter chains must be used, if source files may overwrite newer destination files and the last modified time of `destFile` file should be made equal to the last modified time of `sourceFile`.
`boolean` | `createNewFile(java.io.File f)` Emulation of File.createNewFile for JDK 1.1.
`java.io.File` | `createTempFile(java.lang.String prefix, java.lang.String suffix, java.io.File parentDir)` Create a temporary file in a given directory.
`boolean` | `fileNameEquals(java.io.File f1, java.io.File f2)` Compares two filenames.
`java.net.URL` | `getFileURL(java.io.File file)` Get the URL for a file taking into account # characters
`java.io.File` | `getParentFile(java.io.File f)` Emulation of File.getParentFile for JDK 1.1
`protected java.lang.reflect.Method` | `getSetLastModified()` see whether we have a setLastModified method in File and return it.
`boolean` | `isSymbolicLink(java.io.File parent, java.lang.String name)` Checks whether a given file is a symbolic link.
`static FileUtils` | `newFileUtils()` Factory method.
`java.io.File` | `normalize(java.lang.String path)` "normalize" the given absolute path.
`static java.lang.String` | `readFully(java.io.Reader rdr)` Read from reader till EOF
`static java.lang.String` | `readFully(java.io.Reader rdr, int bufferSize)` Read from reader till EOF
`java.lang.String` | `removeLeadingPath(java.io.File leading, java.io.File path)` Removes a leading path from a second path.
`java.io.File` | `resolveFile(java.io.File file, java.lang.String filename)` Interpret the filename as a file relative to the given file - unless the filename already represents an absolute filename.
`void` | `setFileLastModified(java.io.File file, long time)` Calls File.setLastModified(long time) in a Java 1.1 compatible way.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### FileUtils

    protected FileUtils()

  Empty constructor.

Method Detail

### newFileUtils

    public static FileUtils newFileUtils()

  Factory method.

### getFileURL

    public java.net.URL getFileURL(java.io.File file)
                            throws java.net.MalformedURLException

  Get the URL for a file taking into account # characters

  Parameters:
    `file` - the file whose URL representation is required.
  Returns:
    The FileURL value
  Throws:
    `java.net.MalformedURLException` - if the URL representation cannot be formed.

### copyFile

    public void copyFile(java.lang.String sourceFile,
                         java.lang.String destFile)
                  throws java.io.IOException

  Convienence method to copy a file from a source to a destination. No filtering is performed.

  Throws:
    `java.io.IOException`

### copyFile

    public void copyFile(java.lang.String sourceFile,
                         java.lang.String destFile,
                         FilterSetCollection filters)
                  throws java.io.IOException

  Convienence method to copy a file from a source to a destination specifying if token filtering must be used.

  Throws:
    `java.io.IOException`

### copyFile

    public void copyFile(java.lang.String sourceFile,
                         java.lang.String destFile,
                         FilterSetCollection filters,
                         boolean overwrite)
                  throws java.io.IOException

  Convienence method to copy a file from a source to a destination specifying if token filtering must be used and if source files may overwrite newer destination files.

  Throws:
    `java.io.IOException`

### copyFile

    public void copyFile(java.lang.String sourceFile,
                         java.lang.String destFile,
                         FilterSetCollection filters,
                         boolean overwrite,
                         boolean preserveLastModified)
                  throws java.io.IOException

  Convienence method to copy a file from a source to a destination specifying if token filtering must be used, if source files may overwrite newer destination files and the last modified time of `destFile` file should be made equal to the last modified time of `sourceFile`.

  Throws:
    `java.io.IOException`

### copyFile

    public void copyFile(java.lang.String sourceFile,
                         java.lang.String destFile,
                         FilterSetCollection filters,
                         boolean overwrite,
                         boolean preserveLastModified,
                         java.lang.String encoding)
                  throws java.io.IOException

  Convienence method to copy a file from a source to a destination specifying if token filtering must be used, if source files may overwrite newer destination files and the last modified time of `destFile` file should be made equal to the last modified time of `sourceFile`.

  Throws:
    `java.io.IOException`
  Since:
    1.14, Ant 1.5

### copyFile

    public void copyFile(java.lang.String sourceFile,
                         java.lang.String destFile,
                         FilterSetCollection filters,
                         java.util.Vector filterChains,
                         boolean overwrite,
                         boolean preserveLastModified,
                         java.lang.String encoding,
                         Project project)
                  throws java.io.IOException

  Convienence method to copy a file from a source to a destination specifying if token filtering must be used, if filter chains must be used, if source files may overwrite newer destination files and the last modified time of `destFile` file should be made equal to the last modified time of `sourceFile`.

  Throws:
    `java.io.IOException`
  Since:
    1.15, Ant 1.5

### copyFile

    public void copyFile(java.io.File sourceFile,
                         java.io.File destFile)
                  throws java.io.IOException

  Convienence method to copy a file from a source to a destination. No filtering is performed.

  Throws:
    `java.io.IOException`

### copyFile

    public void copyFile(java.io.File sourceFile,
                         java.io.File destFile,
                         FilterSetCollection filters)
                  throws java.io.IOException

  Convienence method to copy a file from a source to a destination specifying if token filtering must be used.

  Throws:
    `java.io.IOException`

### copyFile

    public void copyFile(java.io.File sourceFile,
                         java.io.File destFile,
                         FilterSetCollection filters,
                         boolean overwrite)
                  throws java.io.IOException

  Convienence method to copy a file from a source to a destination specifying if token filtering must be used and if source files may overwrite newer destination files.

  Throws:
    `java.io.IOException`

### copyFile

    public void copyFile(java.io.File sourceFile,
                         java.io.File destFile,
                         FilterSetCollection filters,
                         boolean overwrite,
                         boolean preserveLastModified)
                  throws java.io.IOException

  Convienence method to copy a file from a source to a destination specifying if token filtering must be used, if source files may overwrite newer destination files and the last modified time of `destFile` file should be made equal to the last modified time of `sourceFile`.

  Throws:
    `java.io.IOException`

### copyFile

    public void copyFile(java.io.File sourceFile,
                         java.io.File destFile,
                         FilterSetCollection filters,
                         boolean overwrite,
                         boolean preserveLastModified,
                         java.lang.String encoding)
                  throws java.io.IOException

  Convienence method to copy a file from a source to a destination specifying if token filtering must be used, if source files may overwrite newer destination files, the last modified time of `destFile` file should be made equal to the last modified time of `sourceFile` and which character encoding to assume.

  Throws:
    `java.io.IOException`
  Since:
    1.14, Ant 1.5

### copyFile

    public void copyFile(java.io.File sourceFile,
                         java.io.File destFile,
                         FilterSetCollection filters,
                         java.util.Vector filterChains,
                         boolean overwrite,
                         boolean preserveLastModified,
                         java.lang.String encoding,
                         Project project)
                  throws java.io.IOException

  Convienence method to copy a file from a source to a destination specifying if token filtering must be used, if filter chains must be used, if source files may overwrite newer destination files and the last modified time of `destFile` file should be made equal to the last modified time of `sourceFile`.

  Throws:
    `java.io.IOException`
  Since:
    1.15, Ant 1.5

### getSetLastModified

    protected final java.lang.reflect.Method getSetLastModified()

  see whether we have a setLastModified method in File and return it.

### setFileLastModified

    public void setFileLastModified(java.io.File file,
                                    long time)
                             throws BuildException

  Calls File.setLastModified(long time) in a Java 1.1 compatible way.

  Throws:
    `BuildException`

### resolveFile

    public java.io.File resolveFile(java.io.File file,
                                    java.lang.String filename)

  Interpret the filename as a file relative to the given file - unless the filename already represents an absolute filename.

  Parameters:
    `file` - the "reference" file for relative paths. This instance must be an absolute file and must not contain "./" or "../" sequences (same for \ instead of /). If it is null, this call is equivalent to `new java.io.File(filename)`.
    `filename` - a file name
  Returns:
    an absolute file that doesn't contain "./" or "../" sequences and uses the correct separator for the current platform.

### normalize

    public java.io.File normalize(java.lang.String path)

  "normalize" the given absolute path.

  This includes:

  - Uppercase the drive letter if there is one.
  - Remove redundant slashes after the drive spec.
  - resolve all ./, .\, ../ and ..\ sequences.
  - DOS style paths that start with a drive letter will have \ as the separator.

  Throws:
    `java.lang.NullPointerException` - if the file path is equal to null.

### createTempFile

    public java.io.File createTempFile(java.lang.String prefix,
                                       java.lang.String suffix,
                                       java.io.File parentDir)

  Create a temporary file in a given directory.

  The file denoted by the returned abstract pathname did not exist before this method was invoked, any subsequent invocation of this method will yield a different file name.

  This method is different to File.createTempFile of JDK 1.2 as it doesn't create the file itself and doesn't use platform specific temporary directory when the parentDir attribute is null.

  Parameters:
    `parentDir` - Directory to create the temporary file in - current working directory will be assumed if this parameter is null.
  Since:
    1.8

### contentEquals

    public boolean contentEquals(java.io.File f1,
                                 java.io.File f2)
                          throws java.io.IOException

  Compares the contents of two files.

  simple but sub-optimal comparision algorithm. written for working rather than fast. Better would be a block read into buffers followed by long comparisions apart from the final 1-7 bytes.

  Throws:
    `java.io.IOException`
  Since:
    1.9

### getParentFile

    public java.io.File getParentFile(java.io.File f)

  Emulation of File.getParentFile for JDK 1.1

  Since:
    1.10

### readFully

    public static final java.lang.String readFully(java.io.Reader rdr)
                                            throws java.io.IOException

  Read from reader till EOF

  Throws:
    `java.io.IOException`

### readFully

    public static final java.lang.String readFully(java.io.Reader rdr,
                                                   int bufferSize)
                                            throws java.io.IOException

  Read from reader till EOF

  Throws:
    `java.io.IOException`

### createNewFile

    public boolean createNewFile(java.io.File f)
                          throws java.io.IOException

  Emulation of File.createNewFile for JDK 1.1.

  This method does not guarantee that the operation is atomic.

  Throws:
    `java.io.IOException`
  Since:
    1.21, Ant 1.5

### isSymbolicLink

    public boolean isSymbolicLink(java.io.File parent,
                                  java.lang.String name)
                           throws java.io.IOException

  Checks whether a given file is a symbolic link.

  It doesn't really test for symbolic links but whether the canonical and absolute paths of the file are identical - this may lead to false positives on some platforms.

  Parameters:
    `parent` - the parent directory of the file to test
    `name` - the name of the file to test.
  Throws:
    `java.io.IOException`
  Since:
    Ant 1.5

### removeLeadingPath

    public java.lang.String removeLeadingPath(java.io.File leading,
                                              java.io.File path)

  Removes a leading path from a second path.

  Parameters:
    `leading` - The leading path, must not be null, must be absolute.
    `path` - The path to remove from, must not be null, must be absolute.
  Returns:
    path's normalized absolute if it doesn't start with leading, path's path with leading's path removed otherwise.
  Since:
    Ant 1.5

### fileNameEquals

    public boolean fileNameEquals(java.io.File f1,
                                  java.io.File f2)

  Compares two filenames.

  Unlike java.io.File#equals this method will try to compare the absolute paths and "normalize" the filenames before comparing them.

  Since:
    Ant 1.5.3

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2000-2003 Apache Software Foundation. All Rights Reserved.