Purple Code

com.purpletech.util
Class IOUtils

java.lang.Object
  |
  +--com.purpletech.util.IOUtils

public class IOUtils
extends java.lang.Object

Miscellaneous file- and IO-related utility methods

Version:
$Id: IOUtils.java,v 1.6 2002/03/13 22:13:50 alex Exp $

Constructor Summary
IOUtils()
           
 
Method Summary
static void chmod(java.io.File file, java.lang.String mode)
           
static void copyFile(java.io.File source, java.io.File target)
          Copies one file to another.
static java.lang.String fixPath(java.lang.String path)
          Removes "./" and "foo/../" and trailing "/" from pathname turns \ (backslash) into / (forward slash)
static java.util.Stack getPathStack(java.lang.String path)
          Given a filesystem path with slashes, turns it into a stack, where each entry on the stack is a directory in the path.
static boolean isDiff(java.io.File a, java.io.File b)
          compares the contents of two files
static boolean isDiff(java.io.InputStream a, java.io.InputStream b)
          compares the contents of two streams
static java.lang.String loadFile(java.io.File file)
          Deprecated. readFile
static java.util.Properties loadProperties(java.io.File file)
           
static java.util.Properties loadProperties(java.lang.String filename)
           
static void lock(java.io.File f)
          Place a ".lock" file next to the given file.
static void log(java.lang.String s)
          Prints a very simple log message to System.err
static java.lang.String readFile(java.io.File file)
           
static java.lang.String readReader(java.io.Reader input)
           
static java.lang.String readStream(java.io.InputStream input)
           
static void unlock(java.io.File f)
          Removes the ".lock" file
static void writeFile(java.io.File dir, java.lang.String name, java.io.InputStream data)
          Write the input stream to the file as raw data
static void writeProperties(java.io.File dir, java.lang.String name, java.util.Properties prop)
          Write the properties parameter to the file as raw data
static void writeString(java.io.File file, java.lang.String data)
          Write the input string to the file as raw data
static void writeString(java.io.File dir, java.lang.String name, java.lang.String data)
          Write the input string to the file as raw data
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

IOUtils

public IOUtils()
Method Detail

readFile

public static java.lang.String readFile(java.io.File file)
                                 throws java.io.IOException
Parameters:
file - file to read
java.io.IOException

readStream

public static java.lang.String readStream(java.io.InputStream input)
                                   throws java.io.IOException
Parameters:
input - stream to read
java.io.IOException

readReader

public static java.lang.String readReader(java.io.Reader input)
                                   throws java.io.IOException
Parameters:
input - stream to read
java.io.IOException

lock

public static void lock(java.io.File f)
                 throws java.io.IOException
Place a ".lock" file next to the given file. If one exists, block (polling every second) until the existing lock expires. If it's still there after 60 seconds, steal the lock.

java.io.IOException
See Also:
unlock(File)

unlock

public static void unlock(java.io.File f)
                   throws java.io.IOException
Removes the ".lock" file

java.io.IOException
See Also:
lock(File)

log

public static void log(java.lang.String s)
Prints a very simple log message to System.err


loadFile

public static java.lang.String loadFile(java.io.File file)
                                 throws java.io.IOException
Deprecated. readFile

OBSOLETE

java.io.IOException

loadProperties

public static java.util.Properties loadProperties(java.lang.String filename)
                                           throws java.io.IOException
java.io.IOException

loadProperties

public static java.util.Properties loadProperties(java.io.File file)
                                           throws java.io.IOException
java.io.IOException

writeFile

public static void writeFile(java.io.File dir,
                             java.lang.String name,
                             java.io.InputStream data)
                      throws java.io.IOException
Write the input stream to the file as raw data

Parameters:
dir - directory to put the file in
name - name of new file
data - the data to write in the file
java.io.IOException

writeString

public static void writeString(java.io.File dir,
                               java.lang.String name,
                               java.lang.String data)
                        throws java.io.IOException
Write the input string to the file as raw data

Parameters:
dir - directory to put the file in
name - name of new file
data - the data to write in the file
java.io.IOException

writeString

public static void writeString(java.io.File file,
                               java.lang.String data)
                        throws java.io.IOException
Write the input string to the file as raw data

Parameters:
data - the data to write in the file
java.io.IOException

writeProperties

public static void writeProperties(java.io.File dir,
                                   java.lang.String name,
                                   java.util.Properties prop)
                            throws java.io.IOException
Write the properties parameter to the file as raw data

Parameters:
dir - directory to put the file in
name - name of new file
java.io.IOException

fixPath

public static java.lang.String fixPath(java.lang.String path)
                                throws java.io.IOException
Removes "./" and "foo/../" and trailing "/" from pathname turns \ (backslash) into / (forward slash)

java.io.IOException

getPathStack

public static java.util.Stack getPathStack(java.lang.String path)
                                    throws java.io.IOException
Given a filesystem path with slashes, turns it into a stack, where each entry on the stack is a directory in the path. Deals properly with "./" and "../" (in the former case, it ignores it; in the latter case, it pops the previous entry) so all you're left with is valid directories. Does not deal with symlinks etc.

java.io.IOException

isDiff

public static boolean isDiff(java.io.File a,
                             java.io.File b)
                      throws java.io.IOException
compares the contents of two files

Returns:
true if the two files differ at any point
java.io.IOException

isDiff

public static boolean isDiff(java.io.InputStream a,
                             java.io.InputStream b)
                      throws java.io.IOException
compares the contents of two streams

Returns:
true if the two streams differ at any point
java.io.IOException

copyFile

public static void copyFile(java.io.File source,
                            java.io.File target)
                     throws java.io.IOException
Copies one file to another. NEW CODE -- NOT YET TESTED

java.io.IOException

chmod

public static void chmod(java.io.File file,
                         java.lang.String mode)
                  throws java.io.IOException
java.io.IOException

Documentation generated March 5 2003