|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.sun.enterprise.util.io.FileUtils
public class FileUtils
| Constructor Summary | |
|---|---|
FileUtils()
|
|
| Method Summary | |
|---|---|
static void |
appendText(String fileName,
String line)
Appends the given line at the end of given text file. |
static void |
appendText(String fileName,
StringBuffer buffer)
|
static void |
copy(File fin,
File fout)
Copies a file. |
static void |
copy(InputStream in,
FileOutputStream out,
long size)
|
static void |
copy(InputStream in,
OutputStream os,
long size)
|
static void |
copy(String from,
String to)
Copies a file. |
static void |
copyFile(File fin,
File fout)
This method is used to copy a given file to another file using the buffer sixe specified |
static void |
copyTree(File din,
File dout)
Copies the entire tree to a new location. |
static void |
copyWithoutClose(InputStream in,
FileOutputStream out,
long size)
|
static File |
createTempFile(File directory)
|
static boolean |
deleteFile(File f)
Delete a file. |
static File[] |
findFilesInDir(File dir,
String regexp)
Find files matching the regular expression in the given directory |
static String |
formatFileCollection(Collection<File> files)
Creates a String listing the absolute paths of files, separated by the platform's line separator. |
static Set |
getAllFilesAndDirectoriesUnder(File directory)
|
static Set |
getAllFilesUnder(File directory,
FilenameFilter filenameFilter)
Return a set of all the files (File objects) under the directory specified, with relative pathnames filtered with the filename filter (can be null for all files). |
static Set |
getAllFilesUnder(File directory,
FilenameFilter filenameFilter,
boolean relativize)
|
static File |
getDirectory(File f)
|
static String |
getIllegalFilenameCharacters()
|
static File |
getManagedFile(String file,
File dir)
If the path dir/file does not exist, look for it in the classpath. |
static boolean |
hasExtension(File f,
String ext)
|
static boolean |
hasExtension(String filename,
String ext)
|
static boolean |
hasExtensionIgnoreCase(File f,
String ext)
|
static boolean |
hasExtensionIgnoreCase(String filename,
String ext)
|
static boolean |
isFriendlyFilename(String filename)
|
static boolean |
isJar(File f)
|
static boolean |
isJar(String filename)
|
static boolean |
isLegalFilename(String filename)
|
static boolean |
isZip(File f)
|
static boolean |
isZip(String filename)
|
static void |
liquidate(File parent)
|
static File[] |
listAllFiles(File dirName,
String ext)
Returns an array of abstract pathnames that matches with the given file extension. |
static File[] |
listFiles(File f)
|
static File[] |
listFiles(File f,
FileFilter ff)
|
static File[] |
listFiles(File f,
FilenameFilter fnf)
|
static String |
makeForwardSlashes(String inputStr)
Returns a String with uniform slashes such that all the occurances of '\\' are replaced with '/'. |
static String |
makeFriendlyFilename(String filename)
|
static String |
makeFriendlyFilenameExtension(String filename)
|
static String |
makeFriendlyFilenameNoExtension(String filename)
|
static String |
makeLegalFilename(String filename)
|
static String |
makeLegalNoBlankFileName(String filename)
|
static FileOutputStream |
openFileOutputStream(File out)
Opens a stream to the specified output file, retrying if necessary. |
static String |
quoteString(String s)
Given a string (typically a path), quote the string such that spaces are protected from interpretation by a Unix or Windows command shell. |
static String |
readSmallFile(File file)
|
static String |
readSmallFile(String fileName)
A utility routine to read a text file efficiently and return the contents as a String. |
static File |
relativize(File parent,
File child)
Given a directory and a fully-qualified file somewhere under that directory, return the portion of the child that is relative to the parent. |
static boolean |
renameFile(File fromFile,
File toFile)
Rename, running gc on Windows if needed to try to force open streams to close. |
static String |
revertFriendlyFilename(String filename)
|
static String |
revertFriendlyFilenameExtension(String filename)
|
static File |
safeGetCanonicalFile(File f)
|
static String |
safeGetCanonicalPath(File f)
|
static boolean |
safeIsDirectory(File f)
|
static boolean |
safeIsDirectory(String s)
|
static boolean |
safeIsRealDirectory(File f)
|
static boolean |
safeIsRealDirectory(String s)
|
static List |
searchDir(File dirName,
String ext)
Returns a list of abstract pathnames that matches with the given file extension. |
static boolean |
whack(File parent)
Deletes a directory and its contents. |
static boolean |
whack(File parent,
Collection<File> undeletedFiles)
Deletes a directory and its contents. |
static void |
writeStringToFile(String s,
File f)
Write the String to a file. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public FileUtils()
| Method Detail |
|---|
public static File[] listFiles(File f)
public static File[] listFiles(File f,
FileFilter ff)
public static File[] listFiles(File f,
FilenameFilter fnf)
public static boolean safeIsDirectory(File f)
public static boolean safeIsRealDirectory(String s)
public static boolean safeIsRealDirectory(File f)
public static boolean safeIsDirectory(String s)
public static String safeGetCanonicalPath(File f)
public static File safeGetCanonicalFile(File f)
public static boolean hasExtension(String filename,
String ext)
public static boolean hasExtension(File f,
String ext)
public static boolean hasExtensionIgnoreCase(String filename,
String ext)
public static boolean hasExtensionIgnoreCase(File f,
String ext)
public static boolean isLegalFilename(String filename)
public static boolean isFriendlyFilename(String filename)
public static String makeLegalFilename(String filename)
public static String makeLegalNoBlankFileName(String filename)
public static String makeFriendlyFilename(String filename)
public static String makeFriendlyFilenameNoExtension(String filename)
public static String makeFriendlyFilenameExtension(String filename)
public static String revertFriendlyFilenameExtension(String filename)
public static String revertFriendlyFilename(String filename)
public static void liquidate(File parent)
public static boolean isJar(String filename)
public static boolean isZip(String filename)
public static boolean isJar(File f)
public static boolean isZip(File f)
public static boolean whack(File parent)
parent - the File at the top of the subtree to delete
public static boolean whack(File parent,
Collection<File> undeletedFiles)
parent - the File at the top of the subtree to delete
public static boolean deleteFile(File f)
f - file to delete
public static FileOutputStream openFileOutputStream(File out)
throws IOException
out - the output File for which a stream is needed
IOException - for any errors opening the stream
public static Set getAllFilesUnder(File directory,
FilenameFilter filenameFilter)
throws IOException
IOException
public static Set getAllFilesUnder(File directory,
FilenameFilter filenameFilter,
boolean relativize)
throws IOException
IOException
public static Set getAllFilesAndDirectoriesUnder(File directory)
throws IOException
IOException
public static File relativize(File parent,
File child)
public static String formatFileCollection(Collection<File> files)
files - the Collection of File objects to be listed
public static File getDirectory(File f)
public static File createTempFile(File directory)
public static File[] listAllFiles(File dirName,
String ext)
dirName - dir name under which search will beginext - file extension to look for
public static List searchDir(File dirName,
String ext)
dirName - dir name under which search will beginext - file extension to look for
public static void copy(String from,
String to)
throws IOException
from - Name of file to copyto - Name of new file
IOException - if an error while copying the content
public static void copy(File fin,
File fout)
throws IOException
fin - File to copyfout - New file
IOException - if an error while copying the content
public static void copyTree(File din,
File dout)
throws IOException
din - File pointing at root of tree to copydout - File pointing at root of new tree
IOException - if an error while copying the contentpublic static String makeForwardSlashes(String inputStr)
inputStr - non null String
does not contain `\\` character public static String quoteString(String s)
s - input string
public static String getIllegalFilenameCharacters()
public static void copyFile(File fin,
File fout)
throws IOException
fin - the source filefout - the destination file
IOException
public static void copy(InputStream in,
FileOutputStream out,
long size)
throws IOException
IOException
public static void copyWithoutClose(InputStream in,
FileOutputStream out,
long size)
throws IOException
IOException
public static void copy(InputStream in,
OutputStream os,
long size)
throws IOException
IOException
public static boolean renameFile(File fromFile,
File toFile)
fromFile - to be renamedtoFile - name for the renamed file
public static void appendText(String fileName,
String line)
throws RuntimeException
fileName - name of the text file that needs to be appended toline - the line to append to
RuntimeException - in case of any error - that makes it callable
from a code not within try-catch. Note that NPE will be thrown if either
argument is null.
Note that this method is not tested with String containing characters
with 2 bytes.
public static void appendText(String fileName,
StringBuffer buffer)
throws IOException,
FileNotFoundException
IOException
FileNotFoundException
public static String readSmallFile(String fileName)
throws IOException,
FileNotFoundException
small .
fileName - String representing absolute path of the file
IOException - if there is an i/o error.
FileNotFoundException - if the file could not be found
public static String readSmallFile(File file)
throws IOException
IOException
public static File getManagedFile(String file,
File dir)
throws IOException
file - - path to look fordir - - directory where the path file should exist
IOException
public static void writeStringToFile(String s,
File f)
throws IOException
s - The String to write to the filef - The file to write the String to
IOException - if any errors
public static File[] findFilesInDir(File dir,
String regexp)
dir - the directory to searchregexp - the regular expression pattern
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||