RSE
Release 3.2

org.eclipse.rse.files.ui.resources
Class SystemSafeFileOutputStream

java.lang.Object
  extended by java.io.OutputStream
      extended by org.eclipse.rse.files.ui.resources.SystemSafeFileOutputStream

public class SystemSafeFileOutputStream
extends java.io.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


Field Summary
protected static java.lang.String BACKUP_EXTENSION
           
protected  java.io.File destination
           
protected  boolean failed
           
protected  java.io.OutputStream output
           
protected  java.io.File temp
           
 
Constructor Summary
SystemSafeFileOutputStream(java.io.File file)
          Constructor for SystemSafeFileOutputStream.
SystemSafeFileOutputStream(java.lang.String destinationName)
          Constructor for SystemSafeFileOutputStream.
SystemSafeFileOutputStream(java.lang.String destinationPath, java.lang.String tempPath)
          Constructor for SystemSafeFileOutputStream.
 
Method Summary
 void close()
          Close the stream.
protected  void commit()
          Commit the temporary file to the destination.
protected  void copy(java.io.File sourceFile, java.io.File destinationFile)
          Copy contents of one file to another.
protected  void createTempFile(java.lang.String tempPath)
          Create the temporary file at the given path.
 void flush()
          Flush the stream.
 java.lang.String getTempFilePath()
          Get the temporary file path.
protected  void transferData(java.io.InputStream source, java.io.OutputStream destination)
          Transfers data from one stream to another.
 void write(int b)
          Write an integer.
 
Methods inherited from class java.io.OutputStream
write, write
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

destination

protected java.io.File destination

temp

protected java.io.File temp

output

protected java.io.OutputStream output

failed

protected boolean failed

BACKUP_EXTENSION

protected static final java.lang.String BACKUP_EXTENSION
See Also:
Constant Field Values
Constructor Detail

SystemSafeFileOutputStream

public SystemSafeFileOutputStream(java.io.File file)
                           throws java.io.IOException
Constructor for SystemSafeFileOutputStream.

Parameters:
file - the destination file.
Throws:
java.io.IOException

SystemSafeFileOutputStream

public SystemSafeFileOutputStream(java.lang.String destinationName)
                           throws java.io.IOException
Constructor for SystemSafeFileOutputStream.

Parameters:
destinationName - the destination file name
Throws:
java.io.IOException

SystemSafeFileOutputStream

public SystemSafeFileOutputStream(java.lang.String destinationPath,
                                  java.lang.String tempPath)
                           throws java.io.IOException
Constructor for SystemSafeFileOutputStream.

Parameters:
destinationPath - the destination file name
tempPath - the temporary file name
Throws:
java.io.IOException
Method Detail

close

public void close()
           throws java.io.IOException
Close the stream.

Overrides:
close in class java.io.OutputStream
Throws:
java.io.IOException

commit

protected void commit()
               throws java.io.IOException
Commit the temporary file to the destination.

Throws:
java.io.IOException

copy

protected void copy(java.io.File sourceFile,
                    java.io.File destinationFile)
             throws java.io.IOException
Copy contents of one file to another.

Parameters:
sourceFile - the source file
destinationFile - the destination file
Throws:
java.io.IOException

createTempFile

protected void createTempFile(java.lang.String tempPath)
                       throws java.io.IOException
Create the temporary file at the given path.

Parameters:
tempPath - the path of the temporary file to be created
Throws:
java.io.IOException

flush

public void flush()
           throws java.io.IOException
Flush the stream.

Overrides:
flush in class java.io.OutputStream
Throws:
java.io.IOException

getTempFilePath

public java.lang.String getTempFilePath()
Get the temporary file path.

Returns:
the path of the temporary file

transferData

protected void transferData(java.io.InputStream source,
                            java.io.OutputStream destination)
                     throws java.io.IOException
Transfers data from one stream to another.

Parameters:
source - stream
destination - stream
Throws:
java.io.IOException

write

public void write(int b)
           throws java.io.IOException
Write an integer.

Specified by:
write in class java.io.OutputStream
Parameters:
b - the integer to write
Throws:
java.io.IOException

RSE
Release 3.2

Copyright (c) IBM Corporation and others 2000, 2010. All Rights Reserved.