ostore.util
Class QSIO

java.lang.Object
  |
  +--ostore.util.QSIO

public abstract class QSIO
extends Object

The QSIO class contains general utility methods for writing/reading QuickSerializable object to/from files.

Version:
$Id: QSIO.java,v 1.37 2003/11/17 23:52:43 emilong Exp $
Author:
Dennis Geels, Larry Tung

Constructor Summary
QSIO()
           
 
Method Summary
static QuickSerializable bytesToQS(byte[] bytes)
          The inverse of qsToBytes, above.
static void delete(RandomAccessFile file, long pos)
          delete the contents of a QuickSerializable by filling where the object was with 0's
static byte[] qsToBytes(QuickSerializable object)
           
static QuickSerializable read(InputStream in)
          Read in the QuickSerializable stored in the specified InputStream.
static QuickSerializable read(RandomAccessFile file, long pos)
          Read in the QuickSerializable stored in the specified RandomAccessFile.
static QuickSerializable read(String filename)
          Read in the QuickSerializable stored in the named file.
static void write(QuickSerializable object, OutputStream out)
          Write a QuickSerializable object to the specified OutputStream.
static void write(QuickSerializable object, RandomAccessFile file, long pos)
           
static void write(QuickSerializable object, String filename)
          Write a QuickSerializable to the named file The file will be overwritten unless an IOException is thrown, in which case the file will remain unmodified.
static void write(QuickSerializable object, String filename, boolean append)
          Write a QuickSerializable to the named file This method provides no guarantees against file corruption if an IOException is thrown during the write.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

QSIO

public QSIO()
Method Detail

write

public static void write(QuickSerializable object,
                         OutputStream out)
                  throws IOException
Write a QuickSerializable object to the specified OutputStream. An 8B header is written first, containing the size of the object in bytes, followed by its type code.

Parameters:
object - The QuickSerializable object to write.
out - The OutputStream into which to write.
Throws:
IOException - if an I/O error occurs.

qsToBytes

public static byte[] qsToBytes(QuickSerializable object)

bytesToQS

public static QuickSerializable bytesToQS(byte[] bytes)
                                   throws QSException
The inverse of qsToBytes, above.

QSException

write

public static void write(QuickSerializable object,
                         String filename)
                  throws IOException
Write a QuickSerializable to the named file The file will be overwritten unless an IOException is thrown, in which case the file will remain unmodified.

Parameters:
object - The QuickSerializable object to write.
filename - The name of the file into which to write.
Throws:
IOException - if an I/O error occurs.

write

public static void write(QuickSerializable object,
                         String filename,
                         boolean append)
                  throws IOException
Write a QuickSerializable to the named file This method provides no guarantees against file corruption if an IOException is thrown during the write.

Parameters:
object - The QuickSerializable object to write.
filename - The name of the file into which to write.
append - Whether to write the object to the end of the file
Throws:
IOException - if an I/O error occurs.

write

public static void write(QuickSerializable object,
                         RandomAccessFile file,
                         long pos)
                  throws IOException
IOException

read

public static QuickSerializable read(InputStream in)
                              throws IOException,
                                     QSException
Read in the QuickSerializable stored in the specified InputStream.

Parameters:
in - The InputStream from which to read.
Returns:
the QuickSerializable read.
Throws:
IOException - if an I/O error occurs.
QSException - if in did not contain a valid QuickSerializable object.

read

public static QuickSerializable read(RandomAccessFile file,
                                     long pos)
                              throws IOException,
                                     QSException
Read in the QuickSerializable stored in the specified RandomAccessFile.

Parameters:
file - The RandomAccessFile from which to read.
pos - amount to seek to
Returns:
the QuickSerializable read.
Throws:
IOException - if an I/O error occurs.
QSException - if in did not contain a valid QuickSerializable object.

delete

public static void delete(RandomAccessFile file,
                          long pos)
                   throws IOException
delete the contents of a QuickSerializable by filling where the object was with 0's

Parameters:
pos - amount to seek to
IOException

read

public static QuickSerializable read(String filename)
                              throws IOException,
                                     QSException
Read in the QuickSerializable stored in the named file.

Parameters:
filename - The name of the file from which to read.
Returns:
the QuickSerializable read.
Throws:
IOException - if an I/O error occurs.
QSException - if in did not contain a valid QuickSerializable object.