Overview | Package | Class | Tree | Deprecated | Index | Help
| 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

## org.hyperic.util.file
Class FileUtil

    java.lang.Object
      org.hyperic.util.file.FileUtil

    public class FileUtil

extends java.lang.Object

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

### BUFSIZ

    public static final int BUFSIZ

  Default buffer size for copyStream method

  See Also:
    Constant Field Values

Method Detail

### findWritableFile

    public static WritableFile findWritableFile(java.io.File preferredDir,
                                                java.lang.String filename,
                                                java.lang.String[] alternateDirs,
                                                java.lang.String alternatePrefixDir)
                                         throws java.lang.IllegalArgumentException

  Try REALLY hard to find a writable place to create a file.

  Parameters:
    `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.
  Returns:
    A WritableFile object that can be written to, or null if nothing can be found. A WritableFile is identical to a regular File object, with the addition of a method "getOriginalLocationWasUsed" which can be used to determine if the original desired file location was used or if an alternate location was used.
  Throws:
    `java.lang.IllegalArgumentException` - if the preferredDir argument is not actually a directory.

### copyFile

    public static void copyFile(java.io.File inFile,
                                java.io.File outFile)
                         throws java.io.FileNotFoundException,
                                java.io.IOException

  Copy a file from one file to another

  Throws:
    `java.io.FileNotFoundException`
    `java.io.IOException`

### copyStream

    public static void copyStream(java.io.InputStream is,
                                  java.io.OutputStream os)
                           throws java.io.IOException

  Copy a stream, using a buffer

  Throws:
    `java.io.IOException`

### copyStream

    public static void copyStream(java.io.InputStream is,
                                  java.io.OutputStream os,
                                  byte[] buf)
                           throws java.io.IOException

  Throws:
    `java.io.IOException`

### findString

    public static java.lang.String findString(java.lang.String fname,
                                              java.lang.String toFind)
                                       throws java.io.IOException

  Throws:
    `java.io.IOException`

### getRelativePath

    public 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. The base must be part of the absolute path specified by the path attribute.

### escape

    public static java.lang.String escape(java.lang.String name)

  Escape invalid characters in a filename, replacing with "_"

### canWrite

    public static boolean canWrite(java.io.File dir)
                            throws java.io.IOException

  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. For example, C:\Program Files is set to read-only, however the Administrator user is able to write to that directory

  Throws:
    `java.io.IOException` - If the File is not a directory

### getParentDir

    public static java.lang.String getParentDir(java.lang.String path)

  Chop the last element off a path. For example, if you pass in /usr/local/foo then this will return /usr/local If there is not enough to chop off, this throws IllegalArgumentException

### getParentDir

    public static java.lang.String getParentDir(java.lang.String path,
                                                int levels)

  Chop the last elements off of a path.

### readLines

    public static java.util.List readLines(java.io.InputStream is)
                                    throws java.io.IOException

  Read all the lines from a stream into a list

  Throws:
    `java.io.IOException`

### makeDirs

    public static boolean makeDirs(java.io.File dir,
                                   int numTries)
                            throws java.lang.InterruptedException

  Create a directory and its parent directories if necessary. If directory creation fails, it will be retried up to the specified number of tries.

  Parameters:
    `dir` - The directory to create.
    `numTries` - The number of tries to create the directory.
  Returns:
    `true` if directory creation succeeds or the directory already exists,b`false` if it fails.
  Throws:
    `java.lang.InterruptedException` - if the operation is interrupted.
    `java.lang.IllegalArgumentException` - if the number of tries is less than one.

### deleteDir

    public static boolean deleteDir(java.io.File dir)

  Deletes all files and subdirectories under dir. Returns true if all deletions were successful. If a deletion fails, the method stops attempting to delete and returns false.

  Parameters:
    `dir` - Directory to delete recursively
  Returns:
    returns true iff directory was successfully deleted including all its children.

### decompress

    public static void decompress(java.io.File compressedFile,
                                  java.io.File destination)
                           throws java.io.IOException

  Throws:
    `java.io.IOException`

### untar

    public static void untar(java.io.File tarFile,
                             java.io.File destinationDir)
                      throws java.io.IOException

  Throws:
    `java.io.IOException`

### unzip

    public static void unzip(java.io.File tarFile,
                             java.io.File destinationDir)
                      throws java.io.IOException

  Throws:
    `java.io.IOException`

### safeCloseStream

    public static void safeCloseStream(java.io.InputStream in)

### safeCloseStream

    public static void safeCloseStream(java.io.OutputStream out)

### safeFileMove

    public static boolean safeFileMove(java.io.File moveFrom,
                                       java.io.File moveTo)

Overview | Package | Class | Tree | Deprecated | Index | Help
| 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

Copyright © 2004-2006 Hyperic, Inc. support@hyperic.net, All Rights Reserved.