|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.rhq.core.util.file.FileUtil
public class FileUtil
| Constructor Summary | |
|---|---|
FileUtil()
|
|
| Method Summary | |
|---|---|
static boolean |
canWrite(File dir)
Test if a directory is writable java.io.File#canWrite() has problems on windows for properly detecting if a directory is writable by the current user. |
static void |
copyDirectory(File inDir,
File outDir)
|
static void |
copyFile(File inFile,
File outFile)
Copy a file from one file to another |
static void |
copyStream(InputStream is,
OutputStream os)
Deprecated. use StreamUtil for more methods like this - those are unit tested and used more |
static void |
copyStream(InputStream is,
OutputStream os,
byte[] buf)
Deprecated. use StreamUtil for more methods like this - those are unit tested and used more |
static File |
createTempDirectory(String prefix,
String suffix,
File parentDirectory)
Creates a temporary directory using the same algorithm as JDK's File.createTempFile. |
static String |
escape(String name)
Escape invalid characters in a filename, replacing with "_" |
static String |
findString(String fname,
String toFind)
|
static void |
forEachFile(File directory,
FileVisitor visitor)
Performs a breadth-first scan, calling visitor for each file in
directory. |
static Pattern |
generateRegex(List<PathFilter> filters)
Takes a list of filters and compiles them into a regular expression that can be used for matching or filtering paths. |
static List<File> |
getDirectoryFiles(File directory)
Obtains the list of all files in the given directory and, recursively, all its subdirectories. |
static String |
getFileName(String path,
String separator)
Return just the filename portion (the portion right of the last path separator string) |
static String |
getRelativePath(File path,
File base)
The base attribute specifies what the directory base the relative path should be considered relative to. |
static void |
purge(File dir,
boolean deleteIt)
Given a directory, this will recursively purge all child directories and files. |
static String |
stripDriveLetter(StringBuilder path)
Strips the drive letter from the given Windows path. |
static String |
useForwardSlash(String path)
Ensure that the path uses only forward slash. |
static void |
writeFile(InputStream inputStream,
File outputFile)
Writes the content in the input stream to the specified file. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public FileUtil()
| Method Detail |
|---|
public static File createTempDirectory(String prefix,
String suffix,
File parentDirectory)
throws IOException
IOException
public static void purge(File dir,
boolean deleteIt)
dir - the directory to purge (if null, this method does nothing and returns normally)deleteIt - if true delete the directory itself, otherwise leave it but purge its children
public static void copyFile(File inFile,
File outFile)
throws FileNotFoundException,
IOException
FileNotFoundException
IOException
public static void copyDirectory(File inDir,
File outDir)
throws IOException
IOException
public static List<File> getDirectoryFiles(File directory)
throws IOException
directory - the directory whose files are to be returned
IOException - if directory does not exist or is not a directory
public static void copyStream(InputStream is,
OutputStream os)
throws IOException
StreamUtil for more methods like this - those are unit tested and used more
IOException
public static void copyStream(InputStream is,
OutputStream os,
byte[] buf)
throws IOException
StreamUtil for more methods like this - those are unit tested and used more
IOException
public static void writeFile(InputStream inputStream,
File outputFile)
throws IOException
inputStream - stream containing the content to writeoutputFile - file to which the content will be written
IOException - if any errors occur during the reading or writing
public static String findString(String fname,
String toFind)
throws IOException
IOException
public static String getRelativePath(File path,
File base)
public static String escape(String name)
public static boolean canWrite(File dir)
throws IOException
IOException - If the File is not a directorypublic static String stripDriveLetter(StringBuilder path)
null is returned if there was no drive letter in the path.
path - the path string that will be altered to have its drive letter stripped.
public static String useForwardSlash(String path)
path -
public static String getFileName(String path,
String separator)
path - separator -
public static void forEachFile(File directory,
FileVisitor visitor)
visitor for each file in
directory. Sub directories are scanned as well. Note that if
visitor throws a RuntimeException it will not be called again as this
method does not provide any exception handling.
directory - The directory over which to iteratevisitor - The callback to invoke for each filepublic static Pattern generateRegex(List<PathFilter> filters)
| Pattern | Description |
| /etc/yum.conf | exact match of the path |
| /etc/*.conf | match any file /etc that has a .conf suffix |
| deploy/myapp-?.war | Match any file in the deploy directory that starts with myapp- followed any one character and ending with a suffix of .war |
| jboss/server/**/*.war | Matches all .war files under the server directory. Sub directories are included as well such that jboss/server/default/myapp.war jboss/server/production/myapp.war and jboss/server/default/myapp.ear/myapp.war all match |
filters - Compiled into a regular expression
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||