| 
 | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectjava.io.Writer
gov.llnl.babel.backend.writers.ChangeWriter
public class ChangeWriter
This class will write a file leaving its last time modified unchanged if
 the content is unchanged. When overwriting a file, this Writer will initially write a temporary file. When close() is called, it compares the contents of the original file with the
 temporary file. If the contents have changed, it will overwrite the
 original file with the contents of the temporary file; otherwise, the
 original file is left unchanged. Thus, the last time modified of the
 original file is only changed when the contents change. The temporary
 file is deleted when close() is called.
| Field Summary | 
|---|
| Fields inherited from class java.io.Writer | 
|---|
| lock | 
| Constructor Summary | |
|---|---|
| ChangeWriter(java.io.File destination,
             java.io.File directory)Create a writer to write a new file or overwrite an old file. | |
| Method Summary | |
|---|---|
|  void | close()Complete writing to the original file if needed. | 
| static java.io.Writer | createWriter(java.lang.String filename,
             java.lang.String directory)Create a Writerfor a particular filename and directory
 combination. | 
| protected  void | finalize()Make sure to close the writer if the programmer should forget to do so. | 
|  void | flush()This will flush all the buffered output into the temporary file. | 
|  void | write(char[] cbuf)Write a character array. | 
|  void | write(char[] cbuf,
      int off,
      int len)Write part of a character array. | 
|  void | write(int c)Write a character. | 
|  void | write(java.lang.String str)Write a string. | 
|  void | write(java.lang.String str,
      int off,
      int len)Write a substring. | 
| Methods inherited from class java.io.Writer | 
|---|
| append, append, append, append, append, append | 
| Methods inherited from class java.lang.Object | 
|---|
| clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait | 
| Constructor Detail | 
|---|
public ChangeWriter(java.io.File destination,
                    java.io.File directory)
             throws java.io.IOException
createWriter(java.lang.String, java.lang.String) instead of this
 constructor; it uses the simpler FileWriter if 
 destination does not already exist.
destination - this is the location of the new filedirectory - this is the directory where the temporary
                      file will be created. If null,
                      a system dependent temporary will be
                      used (e.g., /tmp on Unix).
java.io.IOException - something went wrong creating the Writer.| Method Detail | 
|---|
public static java.io.Writer createWriter(java.lang.String filename,
                                          java.lang.String directory)
                                   throws java.io.IOException
Writer for a particular filename and directory
 combination.
filename - the filename without any leading directory information.directory - the directory name. This string will be prepended
                   to filename to get the whole path to the file.
                   If it's not an empty string, it should end with
                   the directory separator character,
                   File.separatorChar.
ChangeWriter or
                   a FileWriter. The final type
                   shouldn't really matter to the caller.
java.io.IOException - something went wrong creating the Writer.
public void write(java.lang.String str)
           throws java.io.IOException
write in class java.io.Writerstr - the string to be output.
java.io.IOException - There was a problem writing to the output device.
    Writing to a closed ChangeWriter also produces an 
    IOException.
public void write(char[] cbuf)
           throws java.io.IOException
write in class java.io.Writercbuf - the character array to be output.
java.io.IOException - There was a problem writing to the output device.
    Writing to a closed ChangeWriter also produces an 
    IOException.
public void write(java.lang.String str,
                  int off,
                  int len)
           throws java.io.IOException
write in class java.io.Writerstr - the whole stringoff - the offset of the first character to be written.len - the number of characters to write.
java.io.IOException - There was a problem writing to the output device.
    Writing to a closed ChangeWriter also produces an 
    IOException.
public void write(int c)
           throws java.io.IOException
write in class java.io.Writerc - the character to be output.
java.io.IOException - There was a problem writing to the output device.
    Writing to a closed ChangeWriter also produces an 
    IOException.
public void write(char[] cbuf,
                  int off,
                  int len)
           throws java.io.IOException
write in class java.io.Writercbuf - the character array to be output.off - the index of the first character to be written.len - the number of characters to write.
java.io.IOException - There was a problem writing to the output device.
    Writing to a closed ChangeWriter also produces an 
    IOException.
public void flush()
           throws java.io.IOException
close() is
 called.
flush in interface java.io.Flushableflush in class java.io.Writerjava.io.IOException - There was a problem flushing the output device.
    Flushing a closed ChangeWriter also produces an 
    IOException.
public void close()
           throws java.io.IOException
close in interface java.io.Closeableclose in class java.io.Writerjava.io.IOException - This method does a lot compared to many close methods. It must
    compare the temporary file, and then try to write the original
    file. There are many possible reasons for an exception.
protected void finalize()
                 throws java.lang.Throwable
finalize in class java.lang.Objectjava.lang.Throwable| 
 | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||