attachmentutil.java
来自「Xfire文件 用于开发web service 的一个开源工具 很好用的」· Java 代码 · 共 59 行
JAVA
59 行
package org.codehaus.xfire.attachments;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import javax.activation.DataHandler;
import javax.activation.URLDataSource;
import org.codehaus.xfire.XFireRuntimeException;
import org.codehaus.xfire.exchange.AbstractMessage;
import org.codehaus.xfire.util.UID;
public class AttachmentUtil
{
public static String createContentID(String ns)
{
String uid = UID.generate();
try
{
URI uri = new URI(ns);
return uid + "@" + uri;
}
catch (URISyntaxException e)
{
throw new XFireRuntimeException("Could not create URI for namespace: " + ns);
}
}
public static Attachment getAttachment(String id, AbstractMessage msg)
{
int i = id.indexOf("cid:");
if (i != -1) id = id.substring(4).trim();
Attachments atts = msg.getAttachments();
if (atts == null)
return null;
Attachment att = atts.getPart(id);
// Try loading the URL remotely
if (att == null)
{
try
{
URLDataSource source = new URLDataSource(new URL(id));
att = new SimpleAttachment(id, new DataHandler(source));
}
catch (MalformedURLException e)
{
return null;
}
}
return att;
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?