org.jfox.util
Class FileUtils

java.lang.Object
  extended by org.jfox.util.FileUtils

public class FileUtils
extends java.lang.Object


Constructor Summary
FileUtils()
           
 
Method Summary
static boolean cleanDirectory(java.io.File directory)
          Clean a directory without deleting it.
static java.lang.String content(java.io.File file)
          get file content
static java.io.File copy(java.io.File source, java.io.File dir)
          Copy a file.
static boolean delete(java.io.File file)
          

Delete a file.

static boolean deleteDirectory(java.io.File dir)
          Delete a file, or a directory and all of its contents.
static void deleteOnExit(java.io.File file)
          Schedule a file to be deleted when JVM exits.
static void extractJar(java.io.File jarFile, java.io.File dest)
          Dump the contents of a JarArchive to the dpecified destination.
static java.util.Map<java.lang.String,byte[]> getClassBytesMap(java.io.File file)
          从文件或目录中搜索所有的 class 文件
static java.util.Map<java.lang.String,byte[]> getClassBytesMap(java.net.URL location)
          获得一个 URL 中所有的Class Name
static java.net.URL getDescriptor(java.net.URLClassLoader loader, java.lang.String descriptorName)
          use URLClassLoader.findResource, this method will not find resource use parent
static java.util.jar.Manifest getManifest(java.io.File jarFile)
           
static java.util.List<java.io.File> listFiles(java.io.File dir, java.io.FileFilter filter)
          list Files recursively
static void main(java.lang.String[] args)
           
static java.io.File move(java.io.File source, java.io.File dir)
          move the source file to the targe directory
static java.io.File toFile(java.net.URL url)
          Convert from a URL to a File.
static void touch(java.io.File file)
          Implements the same behaviour as the "touch" utility on Unix.
static java.net.URL[] toURLs(java.io.File[] files)
          Convert the array of Files into a list of URLs.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FileUtils

public FileUtils()
Method Detail

delete

public static boolean delete(java.io.File file)

Delete a file. If file is a directory, delete it and all sub-directories.

The difference between File.delete() and this method are:

Parameters:
file - file or directory to delete.

deleteDirectory

public static boolean deleteDirectory(java.io.File dir)
Delete a file, or a directory and all of its contents.

Parameters:
dir - The directory or file to delete.
Returns:
True if all delete operations were successfull.

cleanDirectory

public static boolean cleanDirectory(java.io.File directory)
Clean a directory without deleting it.

Parameters:
directory - directory to clean

deleteOnExit

public static void deleteOnExit(java.io.File file)
                         throws java.io.IOException
Schedule a file to be deleted when JVM exits. If file is directory delete it and all sub-directories.

Parameters:
file - file or directory to delete.
Throws:
java.io.IOException - in case deletion is unsuccessful

copy

public static java.io.File copy(java.io.File source,
                                java.io.File dir)
                         throws java.io.IOException
Copy a file.

Parameters:
source - Source file to copy.
dir - Destination target dir.
Throws:
java.io.IOException - Failed to copy file.

move

public static java.io.File move(java.io.File source,
                                java.io.File dir)
                         throws java.io.IOException
move the source file to the targe directory

Parameters:
source -
dir -
Throws:
java.io.IOException

touch

public static void touch(java.io.File file)
                  throws java.io.IOException
Implements the same behaviour as the "touch" utility on Unix. It creates a new file with size 0 or, if the file exists already, it is opened and closed without modifying it, but updating the file date and time.

Parameters:
file - the File to touch
Throws:
java.io.IOException - If an I/O problem occurs

toURLs

public static java.net.URL[] toURLs(java.io.File[] files)
                             throws java.io.IOException
Convert the array of Files into a list of URLs.

Parameters:
files - the array of files
Returns:
the array of URLs
Throws:
java.io.IOException - if an error occurs

toFile

public static java.io.File toFile(java.net.URL url)
Convert from a URL to a File.

Parameters:
url - File URL.
Returns:
The equivalent File object, or null if the URL's protocol is not file

content

public static java.lang.String content(java.io.File file)
                                throws java.io.IOException
get file content

Throws:
java.io.IOException

listFiles

public static java.util.List<java.io.File> listFiles(java.io.File dir,
                                                     java.io.FileFilter filter)
list Files recursively

Parameters:
dir - directory
filter - file filter
Returns:
File list

extractJar

public static void extractJar(java.io.File jarFile,
                              java.io.File dest)
                       throws java.io.IOException
Dump the contents of a JarArchive to the dpecified destination.

Throws:
java.io.IOException

getDescriptor

public static java.net.URL getDescriptor(java.net.URLClassLoader loader,
                                         java.lang.String descriptorName)
use URLClassLoader.findResource, this method will not find resource use parent

Parameters:
loader -
descriptorName -
Returns:
null if no such descriptor

getManifest

public static java.util.jar.Manifest getManifest(java.io.File jarFile)
                                          throws java.io.IOException
Throws:
java.io.IOException

getClassBytesMap

public static java.util.Map<java.lang.String,byte[]> getClassBytesMap(java.net.URL location)
                                                               throws java.io.IOException
获得一个 URL 中所有的Class Name

Parameters:
location - url location
Throws:
java.io.IOException - ioexception

getClassBytesMap

public static java.util.Map<java.lang.String,byte[]> getClassBytesMap(java.io.File file)
                                                               throws java.io.IOException
从文件或目录中搜索所有的 class 文件

Parameters:
file - file
Returns:
classname=>class bytes
Throws:
java.io.IOException - ioexception

main

public static void main(java.lang.String[] args)
                 throws java.lang.Exception
Throws:
java.lang.Exception