org.openorb.util
Class DiffFileOutputStream

java.lang.Object
  |
  +--java.io.OutputStream
        |
        +--org.openorb.util.DiffFileOutputStream

public class DiffFileOutputStream
extends OutputStream

Non-clobbering file output stream. This behaves similarly to the standard java.io.FileOutputStream, however if the file already exists it will not touch the file unless the data being written is different to the current file contents. Note that care must be taken to always close the output stream, if this does not occour and the class is not garbage collected it can leave data from the old file at the end of the new file.

Version:
$Revision: 1.8 $ $Date: 2004/02/10 22:11:50 $
Author:
Chris Wood

Constructor Summary
DiffFileOutputStream(File file)
          Construct a new diff output stream
DiffFileOutputStream(String filename)
          Construct a new diff output stream
 
Method Summary
 void close()
          Closes the output stream and releases any system resources associated with this stream.
static boolean copyFileNoClobber(File src, File dest)
          Perform a non-clobbering copy.
static boolean copyFileNoClobber(String src, String dest)
          Perform a non-clobbering copy.
 boolean isWriting()
          Returns true if the output stream is now in write mode, and the file is being overwritten.
static void main(String[] args)
           
 void write(byte[] b, int off, int len)
          Writes len bytes from the specified byte array starting at offset off to this file output stream.
 void write(int b)
          Writes the specified byte to this output stream.
 
Methods inherited from class java.io.OutputStream
flush, write
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DiffFileOutputStream

public DiffFileOutputStream(File file)
                     throws FileNotFoundException
Construct a new diff output stream
Parameters:
file - the file to be written to.
Throws:
FileNotFoundException - if the file exists but is a directory rather than a regular file, does not exist but cannot be created, or cannot be opened for any other reason.

DiffFileOutputStream

public DiffFileOutputStream(String filename)
                     throws FileNotFoundException
Construct a new diff output stream
Parameters:
filename - the name of the file.
Throws:
FileNotFoundException - if the file exists but is a directory rather than a regular file, does not exist but cannot be created, or cannot be opened for any other reason.
Method Detail

copyFileNoClobber

public static boolean copyFileNoClobber(File src,
                                        File dest)
                                 throws IOException
Perform a non-clobbering copy. This will copy the contents of one file into the other, but only if the two files differ.
Parameters:
src - the source file.
dest - the destination file.
Returns:
true if the file was clobbered.
Throws:
IOException - if an IOException occours.

copyFileNoClobber

public static boolean copyFileNoClobber(String src,
                                        String dest)
                                 throws IOException
Perform a non-clobbering copy. This will copy the contents of one file into the other, but only if the two files differ.
Parameters:
src - the source file.
dest - the destination file.
Returns:
true if the file was clobbered.
Throws:
IOException - if an IOException occours.

isWriting

public boolean isWriting()
Returns true if the output stream is now in write mode, and the file is being overwritten.

write

public void write(int b)
           throws IOException
Writes the specified byte to this output stream. The general contract for write is that one byte is written to the output stream. The byte to be written is the eight low-order bits of the argument b. The 24 high-order bits of b are ignored.

Subclasses of OutputStream must provide an implementation for this method.

Overrides:
write in class OutputStream
Parameters:
b - the byte.
Throws:
IOException - if an I/O error occurs. In particular, an IOException may be thrown if the output stream has been closed.

write

public void write(byte[] b,
                  int off,
                  int len)
           throws IOException
Writes len bytes from the specified byte array starting at offset off to this file output stream.
Overrides:
write in class OutputStream
Parameters:
b - the data.
off - the start offset in the data.
len - the number of bytes to write.
Throws:
IOException - if an I/O error occurs.

close

public void close()
           throws IOException
Closes the output stream and releases any system resources associated with this stream. This file output stream may no longer be used for writing bytes.
Overrides:
close in class OutputStream
Throws:
IOException - if an I/O error occurs.

main

public static void main(String[] args)
                 throws IOException