Class Base64Data.FilterDataHandler
- java.lang.Object
-
- jakarta.activation.DataHandler
-
- org.jvnet.staxex.StreamingDataHandler
-
- org.jvnet.staxex.Base64Data.FilterDataHandler
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable
- Enclosing class:
- Base64Data
private static final class Base64Data.FilterDataHandler extends StreamingDataHandler
-
-
Constructor Summary
Constructors Constructor Description FilterDataHandler(jakarta.activation.DataHandler dh)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()Releases any resources associated with this DataHandler.voidmoveTo(java.io.File dst)Obtains the BLOB into a specified file.java.io.InputStreamreadOnce()Works likeDataHandler.getInputStream()except that this method can be invoked only once.-
Methods inherited from class org.jvnet.staxex.StreamingDataHandler
getHrefCid, setHrefCid
-
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
public java.io.InputStream readOnce() throws java.io.IOExceptionDescription copied from class:StreamingDataHandlerWorks 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 further
DataHandler.getInputStream()invocation norreadOnce()invocation on this object (which would result inIOException.)When
DataHandleris 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 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.- Specified by:
readOncein classStreamingDataHandler- 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:
java.io.IOException- if any i/o error
-
moveTo
public void moveTo(java.io.File dst) throws java.io.IOExceptionDescription copied from class:StreamingDataHandlerObtains 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
DataHandlerthat 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 callingFile.renameTo(File).This method shouldn't be called when there are any open streams.
After this method is invoked,
StreamingDataHandler.readOnce()andDataHandler.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:
moveToin classStreamingDataHandler- Throws:
java.io.IOException- for errors
-
close
public void close() throws java.io.IOExceptionDescription copied from class:StreamingDataHandlerReleases 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:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Specified by:
closein classStreamingDataHandler- Throws:
java.io.IOException- for errors
-
-