|
Sharkysoft home | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--java.io.Writer | +--java.io.OutputStreamWriter | +--java.io.FileWriter | +--lava.io.TemporaryFileWriter
Writes data to temporary file.
Details: A TemporaryFileWriter
is a specialized FileWriter
that automatically stores its output in a temporary file. This class is useful for situation where data must be saved, but the choice of filename is inconsequential. TemporaryFileWriter
always attempts to use a filename that is not already in use.
After a TemporaryFileWriter
has been closed, the temporary file can be renamed, possibly overwriting the contents of a destination file. Thus, this class is ideal for applications which must read and rewrite files.
Note: Don't forget that because this class is a subclass of FileWriter
, all of the superclass' methods are available in this class.
Note: It appears the people at Javasoft liked this idea. Similar features have now been incorporated into the 1.2 release of Java. (Just remember where it appeared first! :-) This class remains a part of Lava, however, for backword compatibility with existing programs and also to provide continued support for JDK 1.1. Even 1.2 users may find this class to be a more flexible solution.
Fields inherited from class java.io.Writer |
lock |
Constructor Summary | |
TemporaryFileWriter()
Creates an instance that writes to a randomly chosen temporary file. |
|
TemporaryFileWriter(java.io.File rename_dest)
Creates an instance that writes to a randomly chosen temporary file in the same directory as the given file. |
Method Summary | |
void |
close()
Closes the temporary file and, if a rename destination was specified when this instance was constructed, attempts to rename it. |
java.io.File |
closeAndRename(java.io.File new_file)
Closes the output stream and optionally renames the temporary file. |
java.io.File |
getFile()
Returns a File object representing this stream's temporary file. |
Methods inherited from class java.io.OutputStreamWriter |
flush, getEncoding, write, write, write |
Methods inherited from class java.io.Writer |
write, write |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public TemporaryFileWriter() throws java.io.IOException
public TemporaryFileWriter(java.io.File rename_dest) throws java.io.IOException
rename_dest
will only be used to determine which directory to store the temporary file in, and the caller will be responsible for eventually renaming (or deleting) the file on his own.Method Detail |
public java.io.File closeAndRename(java.io.File new_file) throws java.io.IOException
File
object representing the completed temporary file will be returned. It is OK to call this method after the close
method, but it is not necessary.
Tip: It may not be possible to rename the temporary file if the destination file is in use. If you are using this class to rewrite a file, make sure you close the source before you close this destination, so that the source file will not be considered "in use."
new_file
- a File object representing the new filename for the completed temporary file, or null if the file should not be renamedpublic void close() throws java.io.IOException
close
in class java.io.OutputStreamWriter
java.io.IOException
- if an I/O error occurspublic final java.io.File getFile() throws java.io.IOException
File
object representing this stream's temporary file. This method can only be called after the close or closeAndRename method has been called.
|
Sharkysoft home | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |