org.semanticdesktop.aperture.util
Class FileUtil

java.lang.Object
  extended by org.semanticdesktop.aperture.util.FileUtil

public class FileUtil
extends Object

Utility methods for operations on Files.


Constructor Summary
FileUtil()
           
 
Method Summary
static void copyFile(File source, File destination)
          Copies the contents of file source to file destination.
static void createDirIfNotExists(File dir)
          Creates a directory if it doesn't exist yet.
static boolean deleteChildren(File directory)
          Deletes all files and directories in the specified directory.
static boolean deltree(File directory)
          Deletes the given file and everything under it.
static String getFileExtension(String fileName)
          Gets the extension of the specified file name.
static File getRelativeFile(File subj, File relativeTo)
          Gets the relative representations of a file compared to another.
static String getRelativePath(File subj, File relativeTo)
          Gets the relative representations of a file compared to another.
static boolean isLegalFileName(String fileName)
          Checks whether the specified file name is a legal (DOS/Windows-) file name.
static boolean isLegalFileNameChar(char c)
          Checks whether the specified character is a legal (DOS/Windows-) file name character.
static boolean moveRecursive(File from, File to, Collection excludes)
          Moves the given file and all files under it (if it's a directory) to the given location, excluding the given collection of File objects!
static String readStreamAsEncoding(InputStream in, String encoding)
           
static String readStreamAsUTF8(InputStream in)
           
static String readWholeFileAsEncoding(String filename, String encoding)
           
static String readWholeFileAsUTF8(String filename)
          Read a whole file as UTF-8
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FileUtil

public FileUtil()
Method Detail

getRelativePath

public static String getRelativePath(File subj,
                                     File relativeTo)
Gets the relative representations of a file compared to another.

Parameters:
subj - The File to find the relative form for.
relativeTo - The File 'subj' should be made relative to.
Returns:
The relative representation of subj.

getRelativeFile

public static File getRelativeFile(File subj,
                                   File relativeTo)
Gets the relative representations of a file compared to another.

Parameters:
subj - The File to find the relative form for.
relativeTo - The File 'subj' should be made relative to.
Returns:
The relative representation of subj.

getFileExtension

public static String getFileExtension(String fileName)
Gets the extension of the specified file name.

Parameters:
fileName - The file name to process.
Returns:
The file name extension (e.g. "exe" or "txt"), or null if the file name does not have a (valid) extension.

isLegalFileName

public static boolean isLegalFileName(String fileName)
Checks whether the specified file name is a legal (DOS/Windows-) file name.


isLegalFileNameChar

public static boolean isLegalFileNameChar(char c)
Checks whether the specified character is a legal (DOS/Windows-) file name character.


copyFile

public static void copyFile(File source,
                            File destination)
                     throws IOException
Copies the contents of file source to file destination.

Throws:
IOException

createDirIfNotExists

public static void createDirIfNotExists(File dir)
                                 throws IOException
Creates a directory if it doesn't exist yet.

Parameters:
dir - The directory to create.
Throws:
IOException - If the creation of the directory failed.

deltree

public static boolean deltree(File directory)
Deletes the given file and everything under it.

Returns:
Whether all files were deleted succesfully.

deleteChildren

public static boolean deleteChildren(File directory)
Deletes all files and directories in the specified directory. Nothing happens when the specified File is not a directory.

Returns:
true when all children were successfully deleted, when there were no children or when the file was not a directory.

moveRecursive

public static boolean moveRecursive(File from,
                                    File to,
                                    Collection excludes)
Moves the given file and all files under it (if it's a directory) to the given location, excluding the given collection of File objects!

Parameters:
from - File or directory to be moved
to - The file or directory to rename to
excludes - The File objects to be excluded; if a directory is excluded, all files under it are excluded as well!
Returns:
Whether moving was succesfull

readWholeFileAsUTF8

public static String readWholeFileAsUTF8(String filename)
                                  throws IOException
Read a whole file as UTF-8

Parameters:
filename -
Returns:
String
Throws:
IOException - Stolen from Jena

readStreamAsUTF8

public static String readStreamAsUTF8(InputStream in)
                               throws IOException
Throws:
IOException

readStreamAsEncoding

public static String readStreamAsEncoding(InputStream in,
                                          String encoding)
                                   throws IOException
Throws:
IOException

readWholeFileAsEncoding

public static String readWholeFileAsEncoding(String filename,
                                             String encoding)
                                      throws IOException
Throws:
IOException


Copyright © 2010 Aperture Development Team. All Rights Reserved.