Java Reference
In-Depth Information
/** Return an output file that the client should use to
* write the client's data to.
* @return An OutputStream, which should be wrapped in a
* buffered OutputStream to ensure reasonable performance.
* @throws IOException if the temporary file cannot be written
*/
public
public OutputStream getOutputStream () throws
throws IOException {
iif ( state != State . AVAILABLE ) {
throw
throw new
new IllegalStateException ( "FileSaver not opened" );
}
OutputStream out = new
new FileOutputStream ( tmpFile );
state = State . INUSE ;
return
return out ;
}
/** Return an output file that the client should use to
* write the client's data to.
* @return A Writer, which should be wrapped in a
* buffered Writer to ensure reasonable performance.
* @throws IOException if the temporary file cannot be written
*/
public
public Writer getWriter () throws
throws IOException {
iif ( state != State . AVAILABLE ) {
throw
throw new
new IllegalStateException ( "FileSaver not opened" );
}
Writer out = new
new FileWriter ( tmpFile );
state = State . INUSE ;
return
return out ;
}
/** Close the output file and rename the temp file to the original name.
* @throws IOException If anything goes wrong
*/
public
public void
void finish () throws
throws IOException {
iif ( state != State . INUSE ) {
throw
throw new
new IllegalStateException ( "FileSaver not in use" );
}
// Delete the previous backup file if it exists;
backupFile . delete ();
// Rename the user's previous file to itsName.bak,
// UNLESS this is a new file ;
Search WWH ::




Custom Search