Package com.helger.mail.datahandler
Class AbstractStreamingDataHandler
- java.lang.Object
-
- jakarta.activation.DataHandler
-
- com.helger.mail.datahandler.AbstractStreamingDataHandler
-
- All Implemented Interfaces:
Closeable,AutoCloseable
- Direct Known Subclasses:
DataSourceStreamingDataHandler
public abstract class AbstractStreamingDataHandler extends jakarta.activation.DataHandler implements Closeable
DataHandlerextended to offer better buffer management in a streaming environment.
DataHandleris used commonly as a data format across multiple systems (such as JAXB/WS.) Unfortunately,DataHandlerhas the semantics of "read as many times as you want", so this makes it difficult for involving parties to handle a BLOB in a streaming fashion.
AbstractStreamingDataHandlersolves this problem by offering methods that enable faster bulk "consume once" read operation.- Author:
- Jitendra Kotamraju, Philip Helger
-
-
Constructor Summary
Constructors Constructor Description AbstractStreamingDataHandler(jakarta.activation.DataSource aDataSource)AbstractStreamingDataHandler(Object aObj, String sMimeType)AbstractStreamingDataHandler(URL aUrl)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description StringgetHrefCid()abstract InputStreamreadOnce()Works likeDataHandler.getInputStream()except that this method can be invoked only once.
This is used as a signal from the caller that there will be no furtherDataHandler.getInputStream()invocation norreadOnce()invocation on this object (which would result inIOException.)
WhenDataHandleris 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 callDataHandler.getInputStream()multiple times and then callreadOnce()afterward.voidsetHrefCid(String sHrefCid)-
Methods inherited from class jakarta.activation.DataHandler
getAllCommands, getBean, getCommand, getContent, getContentType, getDataSource, getInputStream, getName, getOutputStream, getPreferredCommands, getTransferData, getTransferDataFlavors, isDataFlavorSupported, setCommandMap, setDataContentHandlerFactory, writeTo
-
-
-
-
Method Detail
-
readOnce
@Nonnull public abstract InputStream readOnce() throws IOException
Works likeDataHandler.getInputStream()except that this method can be invoked only once.
This is used as a signal from the caller that there will be no furtherDataHandler.getInputStream()invocation norreadOnce()invocation on this object (which would result inIOException.)
WhenDataHandleris 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 callDataHandler.getInputStream()multiple times and then callreadOnce()afterward. Streams created such a way can be read in any order - there's no requirement that streams created earlier must be read first.- 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 intoBufferedInputStream. - Throws:
IOException- if any i/o error
-
-