Package javax.activation

Examples of javax.activation.DataHandler


    public String embed(URL url, String name)
            throws MessagingException
    {
        MimeBodyPart mbp = new MimeBodyPart();

        mbp.setDataHandler(new DataHandler(new URLDataSource(url)));
        mbp.setFileName(name);
        mbp.setDisposition("inline");
        String cid = org.apache.turbine.util.GenerateUniqueId.getIdentifier();
        mbp.addHeader("Content-ID", cid);
View Full Code Here


        emailBody.addBodyPart(mbp);

        mbp.setDisposition(disposition);
        mbp.setFileName(name);
        mbp.setDescription(description);
        mbp.setDataHandler(new DataHandler(ds));

        return this;
    }
View Full Code Here

    List<Entry> entries = feed.getEntries();
    for (Entry entry : entries) {
      assertNull(entry.getSummaryElement());
      assertNotNull(entry.getContentElement());
      Content mediaContent = entry.getContentElement();
      DataHandler dataHandler = mediaContent.getDataHandler();
      InputStream in = (ByteArrayInputStream) dataHandler.getContent();
      ByteArrayOutputStream baos = new ByteArrayOutputStream();
      int n = -1;
      while ((n = in.read()) > -1) { baos.write(n); }
      assertEquals(baos.toString(), "Some more text.");
    }
View Full Code Here

     IRI uri = baseURI.resolve("4.1.3.3/content-jpeg-valid-base64.xml");
     Document<Feed> doc = get(uri);
     assertNotNull(doc);
     Entry entry = doc.getRoot().getEntries().get(0);
     assertEquals(entry.getContentType(), Content.Type.MEDIA);
     DataHandler dh = entry.getContentElement().getDataHandler();
     ByteArrayInputStream in = (ByteArrayInputStream) dh.getContent();
     ByteArrayOutputStream out = new ByteArrayOutputStream();
     int n = -1;
     while ((n = in.read()) != -1) { out.write(n); }
     out.flush();
     assertEquals(out.toByteArray().length,1538);
     assertEquals(dh.getContentType(), "image/jpeg");
   }
View Full Code Here

        ((SOAPBinding)binding).setMTOMEnabled(true);

        Holder<String> name = new Holder<String>("Sam");
        URL fileURL = this.getClass().getResource("/org/apache/cxf/systest/jms/JMSClientServerTest.class");
        Holder<DataHandler> handler1 = new Holder<DataHandler>();
        handler1.value = new DataHandler(fileURL);
        int size = handler1.value.getInputStream().available();
        mtom.testDataHandler(name, handler1);
       
        byte bytes[] = IOUtils.readBytesFromStream(handler1.value.getInputStream());
        assertEquals("The response file is not same with the sent file.", size, bytes.length);
View Full Code Here

    MimeType type = getMimeType();
    java.net.URL src = null;
    try {
      src = getSrc().toURL();
    } catch (Exception e) {}
    DataHandler dh = null;
    if (src == null) {
      dh = (DataHandler)DataHandlerUtils.getDataHandlerFromText(
        getText(), (type != null) ? type.toString() : null);
    } else {
      dh = new DataHandler(new URLDataSource(src));
    }
    return dh;
  }
View Full Code Here

    content.setSrc("foo");
    assertNotNull(content);
    assertEquals(content.getMimeType().toString(), "text/foo");
    assertEquals(content.getSrc().toString(), "foo");
    content = factory.newContent(new MimeType("text/foo"));
    content.setDataHandler(new DataHandler(new ByteArrayDataSource("foo".getBytes())));
    assertEquals(content.getValue(), "Zm9v");
    assertEquals(content.getContentType(), Content.Type.MEDIA);
    el = factory.newName();
    assertNotNull(el);
    el = factory.newName();
View Full Code Here

        ((SOAPBinding)binding).setMTOMEnabled(true);

        Holder<String> name = new Holder<String>("Sam");
        URL fileURL = this.getClass().getResource("/org/apache/cxf/systest/jms/JMSClientServerTest.class");
        Holder<DataHandler> handler1 = new Holder<DataHandler>();
        handler1.value = new DataHandler(fileURL);
        int size = handler1.value.getInputStream().available();
        mtom.testDataHandler(name, handler1);
       
        byte bytes[] = IOUtils.readBytesFromStream(handler1.value.getInputStream());
        assertEquals("The response file is not same with the sent file.", size, bytes.length);
View Full Code Here

        JMSOutMTOMService service = new JMSOutMTOMService(wsdl, serviceName);
        assertNotNull(service);

        JMSMTOMPortType mtom = service.getPort(portName, JMSMTOMPortType.class);
        URL fileURL = this.getClass().getResource("/org/apache/cxf/systest/jms/JMSClientServerTest.class");
        DataHandler handler1 = new DataHandler(fileURL);
        int size = handler1.getInputStream().available();
        DataHandler ret = mtom.testOutMtom();
       
        byte bytes[] = IOUtils.readBytesFromStream(ret.getInputStream());
        assertEquals("The response file is not same with the original file.", size, bytes.length);
    }
View Full Code Here

            DataSource source = new AttachmentDataSource(ct,
                                                         new QuotedPrintableDecoderStream(stream));
            if (!StringUtils.isEmpty(fileName)) {
                ((AttachmentDataSource)source).setName(fileName);
            }
            att.setDataHandler(new DataHandler(source));
        } else {
            DataSource source = new AttachmentDataSource(ct, stream);
            if (!StringUtils.isEmpty(fileName)) {
                ((AttachmentDataSource)source).setName(fileName);
            }
            att.setDataHandler(new DataHandler(source));
        }
       
        return att;
    }
View Full Code Here

TOP

Related Classes of javax.activation.DataHandler

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.