de.hunsicker.io
Class IoHelper

java.lang.Object
  |
  +--de.hunsicker.io.IoHelper

public final class IoHelper
extends java.lang.Object

Some I/O helper routines.

Version:
$Revision: 1.5.2.1 $
Author:
Marco Hunsicker

Method Summary
static boolean delete(java.io.File file, boolean recursive)
          Deletes the given file or directory.
static java.lang.Object deserialize(byte[] data)
          Deserializes an object previously written using an ObjectOutputStream.
static java.lang.Object deserialize(java.io.File file)
          Deserializes the object stored in the given file.
static java.lang.Object deserialize(java.io.InputStream in)
          Deserializes the object stored in the given stream.
static boolean ensureDirectoryExists(java.io.File directory)
          Verifies the existence of the given directory and if that directory does not yet exist, tries to create it.
static java.lang.String readTextFile(java.io.File file)
          Returns the contents of the given text file.
static void serialize(java.lang.Object o, java.io.File file)
          Serializes the given object to the given file.
static void serialize(java.lang.Object o, java.io.OutputStream out)
          Serializes the given object to the given output stream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

delete

public static boolean delete(java.io.File file,
                             boolean recursive)
Deletes the given file or directory.

Parameters:
file - a file or directory.
recursive - if true directories will be deleted recursively.
Returns:
true if the file or directory could be deleted successfully.

deserialize

public static java.lang.Object deserialize(byte[] data)
                                    throws java.io.IOException
Deserializes an object previously written using an ObjectOutputStream.

Parameters:
data - binary array.
Returns:
deserialized object.
Throws:
java.io.IOException - if an I/O error occured.
See Also:
serialize(java.lang.Object, java.io.OutputStream)

deserialize

public static java.lang.Object deserialize(java.io.InputStream in)
                                    throws java.io.IOException
Deserializes the object stored in the given stream.

Parameters:
in - an input stream.
Returns:
the deserialized object.
Throws:
java.io.IOException - if an I/O exception occured.

deserialize

public static final java.lang.Object deserialize(java.io.File file)
                                          throws java.io.IOException
Deserializes the object stored in the given file.

Parameters:
file - a file.
Returns:
the deserialized object.
Throws:
java.io.IOException - if an I/O exception occured.

ensureDirectoryExists

public static boolean ensureDirectoryExists(java.io.File directory)
Verifies the existence of the given directory and if that directory does not yet exist, tries to create it.

Parameters:
directory - directory to check for existence.
Returns:
true if the directory already exists or was successfully created.
Throws:
java.lang.IllegalArgumentException - if directory does exist but does not denote a valid directory.

readTextFile

public static java.lang.String readTextFile(java.io.File file)
                                     throws java.io.IOException
Returns the contents of the given text file.

Parameters:
file - text file to be read.
Returns:
contents of the give file.
Throws:
java.io.IOException - if an I/O error occured.

serialize

public static void serialize(java.lang.Object o,
                             java.io.OutputStream out)
                      throws java.io.IOException
Serializes the given object to the given output stream.

Parameters:
o - a serializable object.
out - the stream to write the object to.
Throws:
java.io.IOException - if an I/O exception occured.

serialize

public static void serialize(java.lang.Object o,
                             java.io.File file)
                      throws java.io.IOException
Serializes the given object to the given file.

Parameters:
o - a serializable object.
file - the file to write the object to.
Throws:
java.io.IOException - if an I/O exception occured.


Copyright © 1997-2005 Jalopy. All Rights Reserved.