Class MIMEPartStreamingDataHandler

java.lang.Object
javax.activation.DataHandler
org.jvnet.staxex.StreamingDataHandler
com.sun.xml.ws.developer.StreamingDataHandler
com.sun.xml.ws.encoding.MIMEPartStreamingDataHandler
All Implemented Interfaces:
Transferable, Closeable, AutoCloseable

public class MIMEPartStreamingDataHandler extends StreamingDataHandler
Implementation of StreamingDataHandler to access MIME attachments efficiently. Applications can use the additional methods and decide on how to access the attachment data in JAX-WS applications.

for e.g.: DataHandler dh = proxy.getData(); StreamingDataHandler sdh = (StreamingDataHandler)dh; // readOnce() doesn't store attachment on the disk in some cases // for e.g when only one huge attachment after soap envelope part in MIME message InputStream in = sdh.readOnce(); ... in.close(); sdh.close();

Author:
Jitendra Kotamraju
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Releases any resources associated with this DataHandler.
    void
    moveTo(File file)
    Obtains the BLOB into a specified file.
    Works like DataHandler.getInputStream() except that this method can be invoked only once.

    Methods inherited from class org.jvnet.staxex.StreamingDataHandler

    getHrefCid, setHrefCid

    Methods inherited from class javax.activation.DataHandler

    getAllCommands, getBean, getCommand, getContent, getContentType, getDataSource, getInputStream, getName, getOutputStream, getPreferredCommands, getTransferData, getTransferDataFlavors, isDataFlavorSupported, setCommandMap, setDataContentHandlerFactory, writeTo

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • MIMEPartStreamingDataHandler

      public MIMEPartStreamingDataHandler(MIMEPart part)
  • Method Details

    • readOnce

      public InputStream readOnce() throws IOException
      Description copied from class: StreamingDataHandler
      Works like DataHandler.getInputStream() except that this method can be invoked only once.

      This is used as a signal from the caller that there will be no further DataHandler.getInputStream() invocation nor StreamingDataHandler.readOnce() invocation on this object (which would result in IOException.)

      When DataHandler is backed by a streaming BLOB (such as an attachment in a web service read from the network), this allows the callee to avoid unnecessary buffering.

      Note that it is legal to call DataHandler.getInputStream() multiple times and then call StreamingDataHandler.readOnce() afterward. Streams created such a way can be read in any order — there's no requirement that streams created earlier must be read first.

      Specified by:
      readOnce in class StreamingDataHandler
      Returns:
      always non-null. Represents the content of this BLOB. The returned stream is generally not buffered, so for better performance read in a big batch or wrap this into BufferedInputStream.
      Throws:
      IOException - if any i/o error
    • moveTo

      public void moveTo(File file) throws IOException
      Description copied from class: StreamingDataHandler
      Obtains the BLOB into a specified file.

      Semantically, this method is roughly equivalent to the following code, except that the actual implementation is likely to be a lot faster.

       InputStream i = getInputStream();
       OutputStream o = new FileOutputStream(dst);
       int ch;
       while((ch=i.read())!=-1)  o.write(ch);
       i.close();
       o.close();
       

      The main motivation behind this method is that often DataHandler that reads data from a streaming source will use a temporary file as a data store to hold data (think of commons-fileupload.) In such case this method can be as fast as calling File.renameTo(File).

      This method shouldn't be called when there are any open streams.

      After this method is invoked, StreamingDataHandler.readOnce() and DataHandler.getInputStream() will simply open the destination file you've specified as an argument. So if you further move the file or delete this file, those methods will behave in undefined fashion. For a simliar reason, calling this method multiple times will cause undefined behavior.

      Specified by:
      moveTo in class StreamingDataHandler
      Throws:
      IOException
    • close

      public void close() throws IOException
      Description copied from class: StreamingDataHandler
      Releases any resources associated with this DataHandler. (such as an attachment in a web service read from a temp file will be deleted.) After calling this method, it is illegal to call any other methods.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Specified by:
      close in class StreamingDataHandler
      Throws:
      IOException