org.apache.avalon.composition.util
Class FileUtils

java.lang.Object
  extended byorg.apache.avalon.composition.util.FileUtils

public class FileUtils
extends Object

This class provides some common file utilities used by the composition implementation, and is borrowed from the Apache Ant development team.

Version:
$Revision: 1.1 $ $Date: 2004/04/19 18:12:12 $
Author:
Apache Ant Development Team (MacNeill, Umasankar, and Bodewig), Avalon Development Team

Constructor Summary
protected FileUtils()
          Empty constructor.
 
Method Summary
 boolean isSymbolicLink(File parent, String name)
          Checks whether a given file is a symbolic link.
static FileUtils newFileUtils()
          Factory method.
 File normalize(String path)
          "normalize" the given absolute path.
 String removeLeadingPath(File leading, File path)
          Removes a leading path from a second path.
 
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.

Returns:
a new instance of FileUtils.

isSymbolicLink

public boolean isSymbolicLink(File parent,
                              String name)
                       throws 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.
Returns:
true if the file is a symbolic link.
Throws:
IOException

removeLeadingPath

public String removeLeadingPath(File leading,
                                File path)
                         throws IOException
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.
Throws:
IOException

normalize

public File normalize(String path)
               throws IOException
"normalize" the given absolute path.

This includes:

Unlike File#getCanonicalPath() it specifically doesn't resolve symbolic links.

Parameters:
path - the path to be normalized
Returns:
the normalized version of the path.
Throws:
NullPointerException - if the file path is equal to null.
IOException


Copyright © The Apache Software Foundation. All Rights Reserved.