private final class Base64Data.Base64StreamingDataHandler extends StreamingDataHandler
Constructor and Description |
---|
Base64StreamingDataHandler(javax.activation.DataSource source) |
Modifier and Type | Method and Description |
---|---|
void |
close()
Releases any resources associated with this DataHandler.
|
void |
moveTo(java.io.File dst)
Obtains the BLOB into a specified file.
|
java.io.InputStream |
readOnce()
Works like
DataHandler.getInputStream() except that this method
can be invoked only once. |
getHrefCid, setHrefCid
getAllCommands, getBean, getCommand, getContent, getContentType, getDataSource, getInputStream, getName, getOutputStream, getPreferredCommands, getTransferData, getTransferDataFlavors, isDataFlavorSupported, setCommandMap, setDataContentHandlerFactory, writeTo
Base64StreamingDataHandler(javax.activation.DataSource source)
public java.io.InputStream readOnce() throws java.io.IOException
StreamingDataHandler
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.
readOnce
in class StreamingDataHandler
BufferedInputStream
.java.io.IOException
- if any i/o errorpublic void moveTo(java.io.File dst) throws java.io.IOException
StreamingDataHandler
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.
moveTo
in class StreamingDataHandler
java.io.IOException
public void close() throws java.io.IOException
StreamingDataHandler
close
in interface java.io.Closeable
close
in interface java.lang.AutoCloseable
close
in class StreamingDataHandler
java.io.IOException