org.eclipse.rse.files.ui.resources
Class SystemSafeFileOutputStream
java.lang.Object
java.io.OutputStream
org.eclipse.rse.files.ui.resources.SystemSafeFileOutputStream
-
All Implemented Interfaces:
-
Closeable,
Flushable
-
public class SystemSafeFileOutputStream
- extends
OutputStream
This class should be used when there's a file already in the
destination and we don't want to lose its contents if a
failure writing this stream happens.
Basically, the new contents are written to a temporary location.
If everything goes OK, it is moved to the right place.
The user has the option to define the temporary location or
it will be created in the default-temporary directory
Method Summary
|
void
|
close
()
Close the stream. |
protected void
|
commit
()
Commit the temporary file to the destination. |
protected void
|
copy
(
File sourceFile,
File destinationFile)
Copy contents of one file to another. |
protected void
|
createTempFile
(
String tempPath)
Create the temporary file at the given path. |
void
|
flush
()
Flush the stream. |
String
|
getTempFilePath
()
Get the temporary file path. |
protected void
|
transferData
(
InputStream source,
OutputStream destination)
Transfers data from one stream to another. |
void
|
write
(int b)
Write an integer. |
Methods inherited from class java.lang.
Object
|
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
toString,
wait,
wait,
wait
|
destination
protected
File destination
temp
protected
File temp
output
protected
OutputStream output
failed
protected boolean failed
BACKUP_EXTENSION
protected static final
String BACKUP_EXTENSION
-
See Also:
-
Constant Field Values
SystemSafeFileOutputStream
public SystemSafeFileOutputStream(
File file)
throws
IOException
- Constructor for SystemSafeFileOutputStream.
-
Parameters:
-
file
- the destination file.
-
Throws:
-
IOException
SystemSafeFileOutputStream
public SystemSafeFileOutputStream(
String destinationName)
throws
IOException
- Constructor for SystemSafeFileOutputStream.
-
Parameters:
-
destinationName
- the destination file name
-
Throws:
-
IOException
SystemSafeFileOutputStream
public SystemSafeFileOutputStream(
String destinationPath,
String tempPath)
throws
IOException
- Constructor for SystemSafeFileOutputStream.
-
Parameters:
-
destinationPath
- the destination file name -
tempPath
- the temporary file name
-
Throws:
-
IOException
close
public void close()
throws
IOException
- Close the stream.
-
-
Specified by:
-
close
in interface
Closeable
-
Overrides:
-
close
in class
OutputStream
-
-
Throws:
-
IOException
commit
protected void commit()
throws
IOException
- Commit the temporary file to the destination.
-
-
Throws:
-
IOException
copy
protected void copy(
File sourceFile,
File destinationFile)
throws
IOException
- Copy contents of one file to another.
-
-
Parameters:
-
sourceFile
- the source file -
destinationFile
- the destination file
-
Throws:
-
IOException
createTempFile
protected void createTempFile(
String tempPath)
throws
IOException
- Create the temporary file at the given path.
-
-
Parameters:
-
tempPath
- the path of the temporary file to be created
-
Throws:
-
IOException
flush
public void flush()
throws
IOException
- Flush the stream.
-
-
Specified by:
-
flush
in interface
Flushable
-
Overrides:
-
flush
in class
OutputStream
-
-
Throws:
-
IOException
getTempFilePath
public
String getTempFilePath()
- Get the temporary file path.
-
-
Returns:
- the path of the temporary file
transferData
protected void transferData(
InputStream source,
OutputStream destination)
throws
IOException
- Transfers data from one stream to another.
-
-
Parameters:
-
source
- stream -
destination
- stream
-
Throws:
-
IOException
write
public void write(int b)
throws
IOException
- Write an integer.
-
-
Specified by:
-
write
in class
OutputStream
-
-
Parameters:
-
b
- the integer to write
-
Throws:
-
IOException
Copyright (c) IBM Corporation and others 2000, 2008. All Rights Reserved.