为什么我需要DataHandler?

时间:2022-08-25 02:08:26

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

使用javax.activation.DataHandler的主要原因是什么?

Is it to facilitate the transfer of objects, that do not implement Serializable, over the network?

它是否通过网络促进不实现Serializable的对象的传输?

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?

即例如,我已经看到文件从本地文件系统转换为字节,然后用这些字节创建DataHandler并通过网络传输DataHandler。这是人们使用DataHandler的原因吗?

2 个解决方案

#1


6  

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

我将从DataHandler的API条目开始描述:

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.

DataHandler类为许多不同源和格式的数据提供了一致的接口。它使用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.

不可否认,这不是最明确的描述。 DataHandler与XML和SOAP有关,您可以从其API页面的use选项卡中看到它们。和你一样,我用它来表示有关上传文件的数据,因为它是从一个Web服务组件发送到另一个Web服务组件进行处理的。

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.

DataHandler实现的Transferable接口并不完全是指序列化处理的“转移”。它是关于程序中单独组件之间或单独程序之间的信息传输,而不是保存对象供以后使用。有关更多信息,请参阅Transferable的API条目。您会注意到它链接到Drag'n'Drop Java Tutorial,它与DataHandler几乎没有关系,但确实说明了Transferable的使用。

#2


0  

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

还有性能方面的考虑因素,即对SOAP附件使用javax.activation.DataHandler将提高性能。

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

例如正如Oracle所提到的那样“......改进的性能:非正式测试表明,使用DataHandler包装器可以使图像/ gif MIME类型的吞吐量加倍,并且对于image / *类型,text / xml或java.awt.Image的吞吐量大约增加1.5倍。 ......“这是来自LINK

Other references

  • A discussion of Base64 encoding vs. binary attachment types MTOM and DataHandler LINK
  • 讨论Base64编码与二进制附件类型MTOM和DataHandler LINK
  • Apache CXF on MTOM LINK
  • MTOM LINK上的Apache CXF

#1


6  

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

我将从DataHandler的API条目开始描述:

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.

DataHandler类为许多不同源和格式的数据提供了一致的接口。它使用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.

不可否认,这不是最明确的描述。 DataHandler与XML和SOAP有关,您可以从其API页面的use选项卡中看到它们。和你一样,我用它来表示有关上传文件的数据,因为它是从一个Web服务组件发送到另一个Web服务组件进行处理的。

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.

DataHandler实现的Transferable接口并不完全是指序列化处理的“转移”。它是关于程序中单独组件之间或单独程序之间的信息传输,而不是保存对象供以后使用。有关更多信息,请参阅Transferable的API条目。您会注意到它链接到Drag'n'Drop Java Tutorial,它与DataHandler几乎没有关系,但确实说明了Transferable的使用。

#2


0  

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

还有性能方面的考虑因素,即对SOAP附件使用javax.activation.DataHandler将提高性能。

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

例如正如Oracle所提到的那样“......改进的性能:非正式测试表明,使用DataHandler包装器可以使图像/ gif MIME类型的吞吐量加倍,并且对于image / *类型,text / xml或java.awt.Image的吞吐量大约增加1.5倍。 ......“这是来自LINK

Other references

  • A discussion of Base64 encoding vs. binary attachment types MTOM and DataHandler LINK
  • 讨论Base64编码与二进制附件类型MTOM和DataHandler LINK
  • Apache CXF on MTOM LINK
  • MTOM LINK上的Apache CXF