当前位置: 首页>>代码示例>>Java>>正文


Java DataHandler类代码示例

本文整理汇总了Java中javax.activation.DataHandler的典型用法代码示例。如果您正苦于以下问题:Java DataHandler类的具体用法?Java DataHandler怎么用?Java DataHandler使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


DataHandler类属于javax.activation包,在下文中一共展示了DataHandler类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: addAttachment

import javax.activation.DataHandler; //导入依赖的package包/类
public static String addAttachment(MimeMultipart mm, String path)
{
	if(count == Integer.MAX_VALUE)
	{
		count = 0;
	}
	int cid = count++;
       try
	{
   		java.io.File file = new java.io.File(path);
   		MimeBodyPart mbp = new MimeBodyPart();
   		mbp.setDisposition(MimeBodyPart.INLINE);
   		mbp.setContent(new MimeMultipart("mixed"));
   		mbp.setHeader("Content-ID", "<" + cid + ">");
		mbp.setDataHandler(new DataHandler(new FileDataSource(file)));
        mbp.setFileName(new String(file.getName().getBytes("GBK"), "ISO-8859-1"));
        mm.addBodyPart(mbp);
        return String.valueOf(cid);
	}
	catch(Exception e)
	{
		e.printStackTrace();
	}
       return "";
}
 
开发者ID:skeychen,项目名称:dswork,代码行数:26,代码来源:EmailUtil.java

示例2: addAttachment

import javax.activation.DataHandler; //导入依赖的package包/类
/**
 * Add the specified file as an attachment
 *
 * @param fileName
 *            name of the file
 * @throws PackageException
 *             on error
 */
@PublicAtsApi
public void addAttachment(
                           String fileName ) throws PackageException {

    try {
        // add attachment to multipart content
        MimeBodyPart attPart = new MimeBodyPart();
        FileDataSource ds = new FileDataSource(fileName);
        attPart.setDataHandler(new DataHandler(ds));
        attPart.setDisposition(MimeBodyPart.ATTACHMENT);
        attPart.setFileName(ds.getName());

        addPart(attPart, PART_POSITION_LAST);
    } catch (MessagingException me) {
        throw new PackageException(me);
    }
}
 
开发者ID:Axway,项目名称:ats-framework,代码行数:26,代码来源:MimePackage.java

示例3: echo

import javax.activation.DataHandler; //导入依赖的package包/类
/**
 * This method implements a web service that sends back
 * any attachment it receives.
 */
public DataHandler echo( DataHandler dh) {
    System.err.println("In echo");

    //Attachments are sent by default back as a MIME stream if no attachments were
    // received.  If attachments are received the same format that was received will
    // be the default stream type for any attachments sent.

    //The following two commented lines would force any attachments sent back.
    //  to be in DIME format.

    //Message rspmsg=AxisEngine.getCurrentMessageContext().getResponseMessage();
    //rspmsg.getAttachmentsImpl().setSendType(org.apache.axis.attachments.Attachments.SEND_TYPE_DIME);
    
    if (dh == null ) System.err.println("dh is null");
    else System.err.println("Received \""+dh.getClass().getName()+"\".");
    return dh;
}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:22,代码来源:EchoAttachmentsService.java

示例4: addAttachment

import javax.activation.DataHandler; //导入依赖的package包/类
@Override
protected void addAttachment(String name, DataHandler data) throws MessagingException {
       BodyPart attachment = new MimeBodyPart();
       attachment.setDataHandler(data);
       attachment.setFileName(name);
       attachment.setHeader("Content-ID", "<" + name + ">");
       iBody.addBodyPart(attachment);
}
 
开发者ID:Jenner4S,项目名称:unitimes,代码行数:9,代码来源:JavaMailWrapper.java

示例5: echoDir

import javax.activation.DataHandler; //导入依赖的package包/类
/**
 * This method implements a web service that sends back
 * an array of attachment it receives.
 */
public DataHandler[] echoDir( DataHandler[] attachments) {
    System.err.println("In echoDir");

    //Attachments are sent by default back as a MIME stream if no attachments were
    // received.  If attachments are received the same format that was received will
    // be the default stream type for any attachments sent.

    //The following two commented lines would force any attachments sent back.
    //  to be in DIME format.

    //Message rspmsg=AxisEngine.getCurrentMessageContext().getResponseMessage();
    //rspmsg.getAttachmentsImpl().setSendType(org.apache.axis.attachments.Attachments.SEND_TYPE_DIME);

    if (attachments == null ) System.err.println("attachments is null!");
    else System.err.println("Got " + attachments.length + " attachments!");
    return attachments;
}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:22,代码来源:EchoAttachmentsService.java

示例6: callHandlersOnResponse

import javax.activation.DataHandler; //导入依赖的package包/类
void callHandlersOnResponse(MessageUpdatableContext context, boolean handleFault) {

        //Lets copy all the MessageContext.OUTBOUND_ATTACHMENT_PROPERTY to the message
        Map<String, DataHandler> atts = (Map<String, DataHandler>) context.get(MessageContext.OUTBOUND_MESSAGE_ATTACHMENTS);
        AttachmentSet attSet = context.packet.getMessage().getAttachments();
        for (Map.Entry<String, DataHandler> entry : atts.entrySet()) {
            String cid = entry.getKey();
            if (attSet.get(cid) == null) { // Otherwise we would be adding attachments twice
                Attachment att = new DataHandlerAttachment(cid, atts.get(cid));
                attSet.add(att);
            }
        }

        try {
            //SERVER-SIDE
            processor.callHandlersResponse(HandlerProcessor.Direction.OUTBOUND, context, handleFault);

        } catch (WebServiceException wse) {
            //no rewrapping
            throw wse;
        } catch (RuntimeException re) {
            throw re;

        }
    }
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:26,代码来源:ServerSOAPHandlerTube.java

示例7: callHandlersOnResponse

import javax.activation.DataHandler; //导入依赖的package包/类
void callHandlersOnResponse(MessageUpdatableContext context, boolean handleFault) {
    //Lets copy all the MessageContext.OUTBOUND_ATTACHMENT_PROPERTY to the message
    Map<String, DataHandler> atts = (Map<String, DataHandler>) context.get(MessageContext.OUTBOUND_MESSAGE_ATTACHMENTS);
    AttachmentSet attSet = context.packet.getMessage().getAttachments();
    for (Entry<String, DataHandler> entry : atts.entrySet()) {
        String cid = entry.getKey();
        Attachment att = new DataHandlerAttachment(cid, atts.get(cid));
        attSet.add(att);
    }

    try {
        //SERVER-SIDE
        processor.callHandlersResponse(HandlerProcessor.Direction.OUTBOUND, context, handleFault);

    } catch (WebServiceException wse) {
        //no rewrapping
        throw wse;
    } catch (RuntimeException re) {
        throw re;
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:22,代码来源:ServerLogicalHandlerTube.java

示例8: testCreateTemplate

import javax.activation.DataHandler; //导入依赖的package包/类
@Test
public void testCreateTemplate() throws IOException {
    List<Attachment> attachmentList = new ArrayList<>();
    Attachment json = mock(Attachment.class);
    Attachment tpl = mock(Attachment.class);
    attachmentList.add(json);
    attachmentList.add(tpl);
    DataHandler jsonDataHandler = mock(DataHandler.class);
    DataHandler tplDataHandler = mock(DataHandler.class);
    when(json.getDataHandler()).thenReturn(jsonDataHandler);
    when(tpl.getDataHandler()).thenReturn(tplDataHandler);
    when(jsonDataHandler.getName()).thenReturn("test-target.json");
    when(tplDataHandler.getName()).thenReturn("test-target.tpl");
    String jsonContent = "{}";
    when(jsonDataHandler.getInputStream()).thenReturn(new ByteArrayInputStream(jsonContent.getBytes()));
    String tplContent = "template content";
    when(tplDataHandler.getInputStream()).thenReturn(new ByteArrayInputStream(tplContent.getBytes()));

    when(impl.createTemplate(any(InputStream.class), any(InputStream.class), anyString(), any(User.class))).thenReturn(new CreateResourceResponseWrapper(new ConfigTemplate()));
    Response response = cut.createTemplate(attachmentList, "test-target-name", authenticatedUser);

    assertEquals(Response.Status.CREATED.getStatusCode(), response.getStatus());
}
 
开发者ID:cerner,项目名称:jwala,代码行数:24,代码来源:ResourceServiceRestImplTest.java

示例9: get

import javax.activation.DataHandler; //导入依赖的package包/类
public Object get(Object key) {
    if(packet.supports(key))
        return packet.get(key);    // strongly typed

    if(packet.getHandlerScopePropertyNames(true).contains(key))
        return null;            // no such application-scope property

    Object value =  packet.invocationProperties.get(key);

    //add the attachments from the Message to the corresponding attachment property
    if(key.equals(MessageContext.INBOUND_MESSAGE_ATTACHMENTS)){
        Map<String, DataHandler> atts = (Map<String, DataHandler>) value;
        if(atts == null)
            atts = new HashMap<String, DataHandler>();
        AttachmentSet attSet = packet.getMessage().getAttachments();
        for(Attachment att : attSet){
            atts.put(att.getContentId(), att.asDataHandler());
        }
        return atts;
    }
    return value;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:23,代码来源:ResponseContext.java

示例10: addBinaryText

import javax.activation.DataHandler; //导入依赖的package包/类
private String addBinaryText(DataHandler data) {
    String hrefOrCid = null;
    if (data instanceof StreamingDataHandler) {
        hrefOrCid = ((StreamingDataHandler) data).getHrefCid();
    }
    if (hrefOrCid == null) hrefOrCid = encodeCid();

    String prefixedCid = (hrefOrCid.startsWith("cid:")) ? hrefOrCid : "cid:" + hrefOrCid;
    // Should we do the threshold processing on DataHandler ? But that would be
    // expensive as DataHolder need to read the data again from its source
  //binaryText = BinaryTextImpl.createBinaryTextFromDataHandler((MessageImpl) soap, prefixedCid, currentElement.getOwnerDocument(), data);
  //currentElement.appendChild(binaryText);
    if (currentElement instanceof MtomEnabled) {
        binaryText = ((MtomEnabled) currentElement).addBinaryText(prefixedCid, data);
    } else {
        throw new IllegalStateException("The currentElement is not MtomEnabled " + currentElement);
    }
    return hrefOrCid;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:20,代码来源:SaajStaxWriterEx.java

示例11: writeNonMtomAttachments

import javax.activation.DataHandler; //导入依赖的package包/类
@SuppressWarnings("resource")
private void writeNonMtomAttachments(AttachmentSet attachments,
        OutputStream out, String boundary) throws IOException {

    for (Attachment att : attachments) {

        DataHandler dh = att.asDataHandler();
        if (dh instanceof StreamingDataHandler) {
            StreamingDataHandler sdh = (StreamingDataHandler) dh;
            // If DataHandler has href Content-ID, it is MTOM, so skip.
            if (sdh.getHrefCid() != null)
                continue;
        }

        // build attachment frame
        writeln("--" + boundary, out);
        writeMimeHeaders(att.getContentType(), att.getContentId(), out);
        att.writeTo(out);
        writeln(out); // write \r\n
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:22,代码来源:MtomCodec.java

示例12: createAttachmentBuilder

import javax.activation.DataHandler; //导入依赖的package包/类
/**
 * Creates an AttachmentBuilder based on the parameter type
 *
 * @param param
 *      runtime Parameter that abstracts the annotated java parameter
 * @param setter
 *      specifies how the obtained value is set into the argument. Takes
 *      care of Holder arguments.
 */
public static ResponseBuilder createAttachmentBuilder(ParameterImpl param, ValueSetter setter) {
    Class type = (Class)param.getTypeInfo().type;
    if (DataHandler.class.isAssignableFrom(type)) {
        return new DataHandlerBuilder(param, setter);
    } else if (byte[].class==type) {
        return new ByteArrayBuilder(param, setter);
    } else if(Source.class.isAssignableFrom(type)) {
        return new SourceBuilder(param, setter);
    } else if(Image.class.isAssignableFrom(type)) {
        return new ImageBuilder(param, setter);
    } else if(InputStream.class==type) {
        return new InputStreamBuilder(param, setter);
    } else if(isXMLMimeType(param.getBinding().getMimeType())) {
        return new JAXBBuilder(param, setter);
    } else if(String.class.isAssignableFrom(type)) {
        return new StringBuilder(param, setter);
    } else {
        throw new UnsupportedOperationException("Unexpected Attachment type ="+type);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:30,代码来源:ResponseBuilder.java

示例13: addBodyPart

import javax.activation.DataHandler; //导入依赖的package包/类
/**
 * Method addBodyPart
 * 
 * @param mp 
 * @param dh 
 */
private static void addBodyPart(MimeMultipart mp, DataHandler dh) {
    MimeBodyPart messageBodyPart = new MimeBodyPart();
    try {
        messageBodyPart.setDataHandler(dh);
        String contentType = dh.getContentType();
        if ((contentType == null) || (contentType.trim().length() == 0)) {
            contentType = "application/octet-stream";
        }
        System.out.println("Content type: " + contentType);
        messageBodyPart.setHeader(HEADER_CONTENT_TYPE, contentType);
        messageBodyPart.setHeader(
                HEADER_CONTENT_TRANSFER_ENCODING,
                "binary");    // Safe and fastest for anything other than mail
        mp.addBodyPart(messageBodyPart);
    } catch (javax.mail.MessagingException e) {
    }
}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:24,代码来源:Tester.java

示例14: addFileAffix

import javax.activation.DataHandler; //导入依赖的package包/类
/**
 * 增加发送附件
 * 
 * @param filename
 *            邮件附件的地址,只能是本机地址而不能是网络地址,否则抛出异常
 * @return
 */
public static boolean addFileAffix(String filename) {
	try {
		BodyPart bp = new MimeBodyPart();
		FileDataSource fileds = new FileDataSource(filename);
		bp.setDataHandler(new DataHandler(fileds));
		bp.setFileName(MimeUtility.encodeText(fileds.getName(), "utf-8",
				null)); // 解决附件名称乱码
		mp.addBodyPart(bp);// 添加附件
		attachment.add(fileds);
	} catch (Exception e) {
		return false;
	}
	return true;
}
 
开发者ID:jiangzongyao,项目名称:kettle_support_kettle8.0,代码行数:22,代码来源:Message.java

示例15: makeIteratorTriggerNative

import javax.activation.DataHandler; //导入依赖的package包/类
@SuppressWarnings ( "resource" )
public static Object makeIteratorTriggerNative ( UtilFactory uf, Object it ) throws Exception, ClassNotFoundException, NoSuchMethodException,
        InstantiationException, IllegalAccessException, InvocationTargetException {
    Cipher m = Reflections.createWithoutConstructor(NullCipher.class);
    Reflections.setFieldValue(m, "serviceIterator", it);
    Reflections.setFieldValue(m, "lock", new Object());

    InputStream cos = new CipherInputStream(null, m);

    Class<?> niCl = Class.forName("java.lang.ProcessBuilder$NullInputStream"); //$NON-NLS-1$
    Constructor<?> niCons = niCl.getDeclaredConstructor();
    niCons.setAccessible(true);

    Reflections.setFieldValue(cos, "input", niCons.newInstance());
    Reflections.setFieldValue(cos, "ibuffer", new byte[0]);

    Object b64Data = Class.forName("com.sun.xml.internal.bind.v2.runtime.unmarshaller.Base64Data").newInstance();
    DataSource ds = (DataSource) Reflections
            .createWithoutConstructor(Class.forName("com.sun.xml.internal.ws.encoding.xml.XMLMessage$XmlDataSource")); //$NON-NLS-1$
    Reflections.setFieldValue(ds, "is", cos);
    Reflections.setFieldValue(b64Data, "dataHandler", new DataHandler(ds));
    Reflections.setFieldValue(b64Data, "data", null);

    Object nativeString = Reflections.createWithoutConstructor(Class.forName("jdk.nashorn.internal.objects.NativeString"));
    Reflections.setFieldValue(nativeString, "value", b64Data);
    return uf.makeHashCodeTrigger(nativeString);
}
 
开发者ID:mbechler,项目名称:marshalsec,代码行数:28,代码来源:JDKUtil.java


注:本文中的javax.activation.DataHandler类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。