|
Hyperic HQ Plugin API v. 4.4.0.2 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.hyperic.util.file.FileUtil
public class FileUtil
Field Summary | |
---|---|
static int |
BUFSIZ
Default buffer size for copyStream method |
Method Summary | |
---|---|
static boolean |
canWrite(java.io.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 |
copyFile(java.io.File inFile,
java.io.File outFile)
Copy a file from one file to another |
static void |
copyStream(java.io.InputStream is,
java.io.OutputStream os)
Copy a stream, using a buffer |
static void |
copyStream(java.io.InputStream is,
java.io.OutputStream os,
byte[] buf)
|
static void |
decompress(java.io.File compressedFile,
java.io.File destination)
|
static boolean |
deleteDir(java.io.File dir)
Deletes all files and subdirectories under dir. |
static java.lang.String |
escape(java.lang.String name)
Escape invalid characters in a filename, replacing with "_" |
static java.lang.String |
findString(java.lang.String fname,
java.lang.String toFind)
|
static WritableFile |
findWritableFile(java.io.File preferredDir,
java.lang.String filename,
java.lang.String[] alternateDirs,
java.lang.String alternatePrefixDir)
Try REALLY hard to find a writable place to create a file. |
static java.lang.String |
getParentDir(java.lang.String path)
Chop the last element off a path. |
static java.lang.String |
getParentDir(java.lang.String path,
int levels)
Chop the last elements off of a path. |
static java.lang.String |
getRelativePath(java.io.File path,
java.io.File base)
The base attribute specifies what the directory base the relative path should be considered relative to. |
static boolean |
makeDirs(java.io.File dir,
int numTries)
Create a directory and its parent directories if necessary. |
static java.util.List |
readLines(java.io.InputStream is)
Read all the lines from a stream into a list |
static void |
safeCloseStream(java.io.InputStream in)
|
static void |
safeCloseStream(java.io.OutputStream out)
|
static boolean |
safeFileMove(java.io.File moveFrom,
java.io.File moveTo)
|
static void |
untar(java.io.File tarFile,
java.io.File destinationDir)
|
static void |
unzip(java.io.File tarFile,
java.io.File destinationDir)
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final int BUFSIZ
Method Detail |
---|
public static WritableFile findWritableFile(java.io.File preferredDir, java.lang.String filename, java.lang.String[] alternateDirs, java.lang.String alternatePrefixDir) throws java.lang.IllegalArgumentException
preferredDir
- The preferred directory. If this is not a
directory, then an IllegalArgumentException will be thrown.
If this names a directory that does not exist,
this method will still return the preferred path if it could be
created.filename
- The name of the file that should be written to
the directory. This filename may include some preceding directory
names.alternateDirs
- An array of Strings indicating paths to try
to write the file. If this is null, the default array contains the temp
directory, the user's home directory, and finally the current directory.alternatePrefixDir
- If the file can't be written to the preferred
directory and must be written to an alternate directory, this prefix
directory is created first. For example, if you wanted to write to
/some/dir/here (with a filename of logs/somefile) but /some/dir/here
was not writable, so /tmp was chosen instead, you might not want
the ultimate file location to be /tmp/logs/somefile. By specifying
an alternatePrefixDir (for example "cam"), the file would then be
written to: /tmp/cam/logs/somefile
NOTE: If this is null it will be ignored.
java.lang.IllegalArgumentException
- if the preferredDir argument
is not actually a directory.public static void copyFile(java.io.File inFile, java.io.File outFile) throws java.io.FileNotFoundException, java.io.IOException
java.io.FileNotFoundException
java.io.IOException
public static void copyStream(java.io.InputStream is, java.io.OutputStream os) throws java.io.IOException
java.io.IOException
public static void copyStream(java.io.InputStream is, java.io.OutputStream os, byte[] buf) throws java.io.IOException
java.io.IOException
public static java.lang.String findString(java.lang.String fname, java.lang.String toFind) throws java.io.IOException
java.io.IOException
public static java.lang.String getRelativePath(java.io.File path, java.io.File base)
public static java.lang.String escape(java.lang.String name)
public static boolean canWrite(java.io.File dir) throws java.io.IOException
java.io.IOException
- If the File is not a directorypublic static java.lang.String getParentDir(java.lang.String path)
public static java.lang.String getParentDir(java.lang.String path, int levels)
public static java.util.List readLines(java.io.InputStream is) throws java.io.IOException
java.io.IOException
public static boolean makeDirs(java.io.File dir, int numTries) throws java.lang.InterruptedException
dir
- The directory to create.numTries
- The number of tries to create the directory.
true
if directory creation succeeds or the directory
already exists,bfalse
if it fails.
java.lang.InterruptedException
- if the operation is interrupted.
java.lang.IllegalArgumentException
- if the number of tries is less than one.public static boolean deleteDir(java.io.File dir)
dir
- Directory to delete recursively
public static void decompress(java.io.File compressedFile, java.io.File destination) throws java.io.IOException
java.io.IOException
public static void untar(java.io.File tarFile, java.io.File destinationDir) throws java.io.IOException
java.io.IOException
public static void unzip(java.io.File tarFile, java.io.File destinationDir) throws java.io.IOException
java.io.IOException
public static void safeCloseStream(java.io.InputStream in)
public static void safeCloseStream(java.io.OutputStream out)
public static boolean safeFileMove(java.io.File moveFrom, java.io.File moveTo)
|
Hyperic HQ Plugin API v. 4.4.0.2 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |