All Methods
zio package

context

zio
Class InOut


java.lang.Object

  extended byzio.InOut


public class InOut
extends java.lang.Object

This class contains methods for reading and writing entire files: either text files or image files. If image files, the image type must be jpg or png. Here is an example that reads in the contents of the file source.txt and then copies that contents to the file target.txt:

String contents = InOut.readText("source.txt");
InOut.writeText("target.txt",contents);

The read and write methods in this class were written to be thread safe but this feature has not been tested.

The image reading and writing methods can be used to convert from one image type to another.

Error handling can be overridden by subclassing the Zio class.

Version:
Jul 22, 2005
Author:
copyright 2005 by J Adrian Zimmer
Licensed under the Open Software License version 2.1

Constructor Summary
InOut()
           
 
Method Summary
static boolean canRead(java.io.File file)
          Tests whether file can be read.
static boolean canRead(java.lang.String fileName)
          Tests whether file can be read.
static boolean canReadImage(java.io.File file)
          Tests whether file can be read.
static boolean canReadImage(java.lang.String fileName)
          Tests whether file can be read.
static boolean canWrite(java.io.File file)
          Tests whether file can be written.
static boolean canWrite(java.lang.String fileName)
          Tests whether file can be written.
static boolean canWriteImage(java.io.File file)
          Tests whether file can be written.
static boolean canWriteImage(java.lang.String fileName)
          Tests whether file can be written.
static void main(java.lang.String[] files)
          used for testing, may be arbitrarily changed
static java.awt.image.BufferedImage readImage(java.io.File file)
          Reads a gif, jpg or png image.
static java.awt.image.BufferedImage readImage(java.lang.String fileName)
          Reads a gif, jpg or png image.
static java.lang.String readText(java.io.File file)
          Read a text file into a String.
static java.lang.String readText(java.lang.String fileName)
          Read a text file into a String.
static void writeImage(java.io.File file, java.awt.image.BufferedImage content)
          Writes a jpg or png image.
static void writeImage(java.lang.String fileName, java.awt.image.BufferedImage content)
          Writes a jpg or png image.
static void writeText(java.io.File file, java.lang.String content)
          Writes a String to a file.
static void writeText(java.lang.String fileName, java.lang.String content)
          Writes a String to a file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

InOut


public InOut()
Method Detail

canWrite


public static final boolean canWrite(java.lang.String fileName)
Tests whether file can be written. Note this is not the same test as performed by the canWrite() method in Java's File class.

Parameters:
fileName - a file name
Returns:
true iff named file can be written

canWrite


public static final boolean canWrite(java.io.File file)
Tests whether file can be written. Note this is not the same test as performed by the canWrite() method in Java's File class.

Parameters:
file - a File object
Returns:
true iff indicated file can be written

canWriteImage


public static final boolean canWriteImage(java.lang.String fileName)
Tests whether file can be written. Checks two things: Can the file be written? And, is the image format indicated by the extension supported?

Parameters:
fileName - a file name
Returns:
true iff named file can be written

canWriteImage


public static final boolean canWriteImage(java.io.File file)
Tests whether file can be written. Checks two things: Can the file be written? And, is the image format indicated by the extension supported?

Parameters:
file - a File object
Returns:
true iff indicated file can be written

canRead


public static final boolean canRead(java.lang.String fileName)
Tests whether file can be read.

Parameters:
fileName - a file name
Returns:
true iff named file can be read

canRead


public static final boolean canRead(java.io.File file)
Tests whether file can be read.

Parameters:
file - a File object
Returns:
true iff indicated file can be read

canReadImage


public static final boolean canReadImage(java.lang.String fileName)
Tests whether file can be read. Checks two things: Can the file be read? And, is the image format indicated by the extension supported?

Parameters:
fileName - a file name
Returns:
true iff named file can be read

canReadImage


public static final boolean canReadImage(java.io.File file)
Tests whether file can be read. Checks two things: Can the file be read? And, is the image format indicated by the extension supported?

Parameters:
file - a File object
Returns:
true iff indicated file can be read

readText


public static final java.lang.String readText(java.lang.String fileName)
Read a text file into a String. Reads an entire file. Meant to use for short text files.

Parameters:
fileName - the name of the file to be read
Returns:
a String containing the entire contents of the file

readText


public static final java.lang.String readText(java.io.File file)
Read a text file into a String. Reads an entire file. Meant to use for short text files.

Parameters:
file - a file object identifying the file to be read
Returns:
a String representing the entire contents of the file

writeText


public static final void writeText(java.lang.String fileName,
                                   java.lang.String content)
Writes a String to a file. Meant to be used for short text files. The string will become the entire contents of the file.

Parameters:
fileName - the name of the file to be written
content - the new contents of the named file

writeText


public static final void writeText(java.io.File file,
                                   java.lang.String content)
Writes a String to a file. Meant to be used for short text files. The string will become the entire contents of the file.

Parameters:
file - a file object identifying the file to be written on
content - the new contents of the named file

readImage


public static final java.awt.image.BufferedImage readImage(java.lang.String fileName)
Reads a gif, jpg or png image.
You must import java.awt.image.BufferedImage to use this.

Parameters:
fileName - the name of the image file to be read, must end with .jpg or .png
Returns:
the image in BufferedImage form

readImage


public static final java.awt.image.BufferedImage readImage(java.io.File file)
Reads a gif, jpg or png image.
You must import java.awt.image.BufferedImage to use this.

Parameters:
file - a file object referencing the file to be read; file name must end with .jpg or .png.
Returns:
the image in BufferedImage form

writeImage


public static final void writeImage(java.lang.String fileName,
                                    java.awt.image.BufferedImage content)
Writes a jpg or png image.
You must import java.awt.image.BufferedImage to use this.

Parameters:
fileName - the name of the file to be written; must end with .jpg or .png
content - the image in BufferedImage form

writeImage


public static final void writeImage(java.io.File file,
                                    java.awt.image.BufferedImage content)
Writes a jpg or png image.
You must import java.awt.image.BufferedImage to use this.

Parameters:
file - a file object referencing the file to be written; file name must end with .jpg or .png
content - the image in BufferedImage form

main


public static void main(java.lang.String[] files)
used for testing, may be arbitrarily changed


author
context