uk.co.petertribble.jumble
Class JumbleFile

java.lang.Object
  extended by uk.co.petertribble.jumble.JumbleFile

public class JumbleFile
extends java.lang.Object

Convenience routines for accessing files. Allows for reading a file into a String or arrays of bytes


Constructor Summary
JumbleFile(java.io.File file)
          Read a file, specified by a File object
JumbleFile(java.lang.String filename)
          Read a file, specified by name
 
Method Summary
 java.lang.Object contents()
          Gets the contents of the file.
static java.lang.Object contents(java.io.File f)
          Static utility method to read a file.
 byte[] getByteContents()
          Gets the contents of the file, explicitly as a byte array
static byte[] getByteContents(java.io.File f)
          Static utility method to read a file into a byte array
 java.lang.String getMessage()
          Get a status message, if any.
 java.lang.String getStringContents()
          Gets the contents of the file as a String
static java.lang.String getStringContents(java.io.File f)
          Static utility method to read a file into a String
static boolean put(java.io.File f, java.lang.Object data)
          Static utility method to write to a file.
 boolean put(java.lang.Object data)
          Write to a file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JumbleFile

public JumbleFile(java.lang.String filename)
Read a file, specified by name

Parameters:
filename - The name of the file to be read

JumbleFile

public JumbleFile(java.io.File file)
Read a file, specified by a File object

Parameters:
file - The File to be read
Method Detail

contents

public java.lang.Object contents()
Gets the contents of the file. This returns an Object which is exactly the byte array returned by the getByteContents() method

Returns:
The contents of a file as an Object

getByteContents

public byte[] getByteContents()
Gets the contents of the file, explicitly as a byte array

Returns:
The contents of a file as an array of bytes

getStringContents

public java.lang.String getStringContents()
Gets the contents of the file as a String

Returns:
The contents of the file as a String

put

public boolean put(java.lang.Object data)
Write to a file.

Parameters:
data - The data to be written, which must either be a String or an array of bytes
Returns:
A boolean value indicating whether the write succeeded. Use getMessage() to determine why the write failed.

getMessage

public java.lang.String getMessage()
Get a status message, if any.

Returns:
A message associated with the last file operation

contents

public static java.lang.Object contents(java.io.File f)
Static utility method to read a file.

Parameters:
f - A File to be read.
Returns:
The contents of a file as an Object

getByteContents

public static byte[] getByteContents(java.io.File f)
Static utility method to read a file into a byte array

Parameters:
f - A File to be read.
Returns:
The contents of a file as an array of bytes

getStringContents

public static java.lang.String getStringContents(java.io.File f)
Static utility method to read a file into a String

Parameters:
f - A File to be read.
Returns:
The contents of a file as a String

put

public static boolean put(java.io.File f,
                          java.lang.Object data)
Static utility method to write to a file.

Parameters:
f - A File to be written to.
data - The data to be written, which must either be a String or an array of bytes
Returns:
A boolean value indicating whether the write succeeded.