com.funambol.syncml.client
Class FileObjectOutputStream

java.lang.Object
  extended by java.io.OutputStream
      extended by com.funambol.syncml.client.FileObjectOutputStream
All Implemented Interfaces:
java.io.Closeable, java.io.Flushable

public class FileObjectOutputStream
extends java.io.OutputStream

This class represents a stream into which a file object can be written directly. It is responsibility of this stream to separate the meta information from the real file content. The user can simply stream bytes as they arrive from a file object source into this output stream. When the "body" of the item starts, then its content is written into an output stream that must be provided to this class. After the stream is closed, the user can ask for a FileObject which contains all the file object meta data.


Constructor Summary
FileObjectOutputStream(FileObject fo, java.io.OutputStream os)
          Builds the output stream.
 
Method Summary
 void close()
          Close the output stream.
 void flush()
          Flushes the underlying stream.
 FileObject getFileObject()
          Get the file object descrption (meta information).
 void write(int b)
          Writes a single byte into the stream.
 
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
 

Constructor Detail

FileObjectOutputStream

public FileObjectOutputStream(FileObject fo,
                              java.io.OutputStream os)
Builds the output stream.

Parameters:
fo - is the file object which is filled with the meta information which comes into the stream
os - is the output stream into which the file object body is written into
Method Detail

write

public void write(int b)
           throws java.io.IOException
Writes a single byte into the stream. If the body tag has not been found yet, then the info is kept as meta information. Once the body is encountered, then all the subsequent bytes are written into the real output stream. If the content is base64 encoded, then the method performs also decoding. The body tag is recognized by the FileObject parser, which parses the information received so far and it extracts the body content. This makes the parsing mechanism safe.

Specified by:
write in class java.io.OutputStream
Parameters:
b - the byte write
Throws:
java.io.IOException - if the operation cannot be performed. This can be due to several reasons, including a failure of the underlying output stream or an invalid file object content that cannot be parsed.

close

public void close()
           throws java.io.IOException
Close the output stream. When the stream is closed, the method makes sure that no pending bytes are present. If there are, then the body and the FileObject may get updated. After the stream has been closed, it is safe to read the FileObject.

Specified by:
close in interface java.io.Closeable
Overrides:
close in class java.io.OutputStream
Throws:
java.io.IOException - if the operation cannot be performed. Either because the underlying output stream has a failure or because the the meta information cannot be parsed properly.

flush

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

Specified by:
flush in interface java.io.Flushable
Overrides:
flush in class java.io.OutputStream
Throws:
java.io.IOException

getFileObject

public FileObject getFileObject()
Get the file object descrption (meta information). It is safe to invoke this method only after the stream was closed. If writing or closing generated an exception, then the content of the returned object may be inaccurate.



Copyright © 2001-2009 Funambol.