org.apache.excalibur.source.impl
Class HTTPClientSource.WrappedFileOutputStream

java.lang.Object
  extended by java.io.OutputStream
      extended by java.io.FileOutputStream
          extended by org.apache.excalibur.source.impl.HTTPClientSource.WrappedFileOutputStream
All Implemented Interfaces:
java.io.Closeable, java.io.Flushable
Enclosing class:
HTTPClientSource

private class HTTPClientSource.WrappedFileOutputStream
extends java.io.FileOutputStream

Internal class which extends FileOutputStream to automatically upload the data written to it, upon a close() operation.


Field Summary
private  java.io.File m_file
          Reference to the File being written itself.
private  org.apache.avalon.framework.logger.Logger m_logger
          Reference to a Logger.
 
Constructor Summary
HTTPClientSource.WrappedFileOutputStream(java.io.File file, org.apache.avalon.framework.logger.Logger logger)
          Constructor, creates a new HTTPClientSource.WrappedFileOutputStream instance.
 
Method Summary
 boolean canCancel()
          Method to test whether this stream can be closed.
 void cancel()
          Cancels this stream.
 void close()
          Closes the stream, and uploads the file written to the server.
private  boolean successfulUpload(int response)
          According to RFC2616 (HTTP 1.1) valid responses for a HTTP PUT are 201 (Created), 200 (OK), and 204 (No Content).
private  void upload()
          Helper method to attempt uploading of the local data file to the remove server via a HTTP PUT.
 
Methods inherited from class java.io.FileOutputStream
finalize, getChannel, getFD, write, write, write
 
Methods inherited from class java.io.OutputStream
flush
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

m_file

private java.io.File m_file
Reference to the File being written itself.


m_logger

private final org.apache.avalon.framework.logger.Logger m_logger
Reference to a Logger.

Constructor Detail

HTTPClientSource.WrappedFileOutputStream

public HTTPClientSource.WrappedFileOutputStream(java.io.File file,
                                                org.apache.avalon.framework.logger.Logger logger)
                                         throws java.io.IOException
Constructor, creates a new HTTPClientSource.WrappedFileOutputStream instance.

Parameters:
file - File to write to.
logger - Logger reference.
Throws:
java.io.IOException - if an error occurs
Method Detail

close

public void close()
           throws java.io.IOException
Closes the stream, and uploads the file written to the server.

Specified by:
close in interface java.io.Closeable
Overrides:
close in class java.io.FileOutputStream
Throws:
java.io.IOException - if an error occurs

canCancel

public boolean canCancel()
Method to test whether this stream can be closed.

Returns:
true if possible, false otherwise.

cancel

public void cancel()
            throws java.io.IOException
Cancels this stream.

Throws:
java.io.IOException - if stream is already closed

upload

private void upload()
             throws java.io.IOException
Helper method to attempt uploading of the local data file to the remove server via a HTTP PUT.

Throws:
java.io.IOException - if an error occurs

successfulUpload

private boolean successfulUpload(int response)
According to RFC2616 (HTTP 1.1) valid responses for a HTTP PUT are 201 (Created), 200 (OK), and 204 (No Content).

Parameters:
response - response code from the HTTP PUT
Returns:
true if upload was successful, false otherwise.