com.webstersmalley.picweb.utils
Class IOUtils

java.lang.Object
  extended by com.webstersmalley.picweb.utils.IOUtils

public class IOUtils
extends java.lang.Object

Utility class for the basic file/IO related functions (eg write out an Document as an XML file)

Author:
Matthew Smalley

Field Summary
private static org.apache.commons.logging.Log log
          Logger for the class.
 
Constructor Summary
private IOUtils()
          Private constructor - should only used via static utilities methods
 
Method Summary
static void copyFile(java.io.File src, java.io.File dest)
          Copies the contents of a file to a new one, creating subdirectories as necessary.
static void copyFolderContents(java.lang.String src, java.lang.String dest)
          Copies the contents of one folder into another.
static void purgeFolder(java.io.File folder)
          Deletes the contents of a folder, leaving that folder intact.
static void touch(java.io.File file)
          Creates a blank (0-byte) file, creating folders as necessary.
static void writeFile(java.lang.String filename, java.lang.String contents)
          Writes out a string as a file.
static void writeXmlFile(java.lang.String filename, org.w3c.dom.Document doc)
          Writes out a Document as an XML file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

private static org.apache.commons.logging.Log log
Logger for the class.

Constructor Detail

IOUtils

private IOUtils()
Private constructor - should only used via static utilities methods

Method Detail

writeFile

public static void writeFile(java.lang.String filename,
                             java.lang.String contents)
                      throws java.io.FileNotFoundException
Writes out a string as a file. Will create parent directories in order to succeed.

Parameters:
filename - the name of the new file
contents - the contents of the new file
Throws:
java.io.FileNotFoundException - File wasn't found

writeXmlFile

public static void writeXmlFile(java.lang.String filename,
                                org.w3c.dom.Document doc)
                         throws java.lang.Exception
Writes out a Document as an XML file.

Parameters:
filename - the filename of the new XML file
doc - the document to write
Throws:
java.lang.Exception - wraps up exceptions from the IO and the transformation

copyFolderContents

public static void copyFolderContents(java.lang.String src,
                                      java.lang.String dest)
                               throws java.io.IOException
Copies the contents of one folder into another. e.g. consider the following tree: src\file1 src\dir1\file2 src\dir1\file3 If we called copyFolderContents("src", "dest") we'd end up with: dest\file1 dest\dir1\file2 dest\dir2\file3

Parameters:
src - Source folder
dest - Destination folder
Throws:
java.io.IOException

copyFile

public static void copyFile(java.io.File src,
                            java.io.File dest)
                     throws java.io.IOException
Copies the contents of a file to a new one, creating subdirectories as necessary.

Parameters:
src - Source file
dest - Destination file
Throws:
java.io.IOException

purgeFolder

public static void purgeFolder(java.io.File folder)
                        throws java.io.IOException
Deletes the contents of a folder, leaving that folder intact.

Parameters:
folder - the folder to purge
Throws:
java.io.IOException

touch

public static void touch(java.io.File file)
                  throws java.io.IOException
Creates a blank (0-byte) file, creating folders as necessary. If the file already exists, updates the lastModified time. If the file exists but is not a regular file, throws an IOException.

Parameters:
file - the file to create
Throws:
java.io.IOException


Copyright © 2004-2005-2005 Webster Smalley. All Rights Reserved.