开发者

Why do I need a DataHandler?

开发者 https://www.devze.com 2023-02-16 14:41 出处:网络
What is the main reason of using a javax.activation.DataHandler? Is it to facilitate the transfer of objects, that do not i开发者_StackOverflowmplement Serializable, over the network?

What is the main reason of using a javax.activation.DataHandler?

Is it to facilitate the transfer of objects, that do not i开发者_StackOverflowmplement Serializable, over the network?

I.e. for instance I have seen the conversion of files, from local file systems, to bytes and then create a DataHandler with these bytes and transfer the DataHandler over the network.

Is this the reason that one would use DataHandler?


I'll lead off with the start of the description from the API entry for DataHandler:

The DataHandler class provides a consistent interface to data available in many different sources and formats. It manages simple stream to string conversions and related operations using DataContentHandlers.

Admittedly, that's not the clearest description. DataHandler has to do with XML and SOAP, which you can see from the the use tab of its API page. Like you, I've used it to represent data about an uploaded file as it's being sent from one web service component to another for processing.

The Transferable interface that DataHandler implements is not exactly referring to "transfer" of the kind serialization deals with. It's about transfer of information between separate components in a program, or separate programs, not saving an object for later use. See the API entry for Transferable for more. You'll notice that it links to the Drag 'n' Drop Java Tutorial, which has little to do with DataHandler but does illustrate a use of Transferable.


There are also performance considerations i.e. using a javax.activation.DataHandler for a SOAP attachment will improve performance.

e.g. as mentioned by Oracle "...Improved Performance: Informal tests have shown that using DataHandler wrappers doubles throughput for image/gif MIME types, and multiplies throughput by approximately 1.5 for text/xml or java.awt.Image for image/* types...." this is from LINK

Other references

  • A discussion of Base64 encoding vs. binary attachment types MTOM and DataHandler LINK
  • Apache CXF on MTOM LINK
0

精彩评论

暂无评论...
验证码 换一张
取 消