Package javax.activation

Examples of javax.activation.DataHandler


          String sContentType = oRSet.getString(7);
          if (DebugFile.trace) DebugFile.writeln("new ByteArrayDataSource("+sFilePath+", "+sContentType+")");
          ByteArrayDataSource baDataSrc = new ByteArrayDataSource(byData, sContentType);

          oMimeBody = new MimeBodyPart();
          oMimeBody.setDataHandler(new DataHandler(baDataSrc));
        }
        else if (id_disposition.equals("pointer")) {
          if (DebugFile.trace) DebugFile.writeln("content disposition is pointer");
          lPos = oRSet.getBigDecimal(3).longValue();
          sFilePath = oRSet.getString(4);
View Full Code Here


    String sRetVal;

    URL oUrl = new URL(sFilePath);
   
    ByteArrayOutputStream oStrm = new ByteArrayOutputStream();
    DataHandler oHndlr = new DataHandler(oUrl);
    oHndlr.writeTo(oStrm);
    sRetVal = oStrm.toString(sEncoding);
    oStrm.close();

    return sRetVal;
  } // readfilestr
View Full Code Here

          if (sSrc.startsWith("www."))
            sSrc = "http://" + sSrc;

          if (sSrc.startsWith("http://") || sSrc.startsWith("https://")) {
            oImgBodyPart.setDataHandler(new DataHandler(new URL(Hosts.resolve(sSrc))));
          }
          else {
            oImgBodyPart.setDataHandler(new DataHandler(new FileDataSource(sSrc)));
          }
     
      if (sSrc.endsWith(".png")) oImgBodyPart.setHeader("Content-Type", "image/png;name="+sCid);
          oImgBodyPart.setDisposition("inline");
          oImgBodyPart.setHeader("Content-ID", sCid);
          oImgBodyPart.setFileName(sCid);

          // Add image to multi-part
          if (DebugFile.trace) DebugFile.writeln("MimeBodyPart(multipart/related).addBodyPart("+sCid+")");
          oHtmlRelated.addBodyPart(oImgBodyPart);
        } // wend

        // Set html text alternative part (html text + inline images)
        MimeBodyPart oTextHtmlRelated = new MimeBodyPart();
        oTextHtmlRelated.setContent(oHtmlRelated);
        if (DebugFile.trace) DebugFile.writeln("MimeBodyPart(multipart/alternative).addBodyPart(multipart/related)");
        oTextHtmlAlt.addBodyPart(oTextHtmlRelated);
      }

      // ************************************************************************
      // Create message to be sent and add main text body to it

      if (0==iDraftParts) {
        oSentMessage.setContent(oTextHtmlAlt);
      } else {
        MimeBodyPart oMixedPart = new MimeBodyPart();
        oMixedPart.setContent(oTextHtmlAlt);
        oSentMsgParts.addBodyPart(oMixedPart);
      }

    } else { // (sContentType=="plain")

      // *************************************************
      // If this is a plain text message just add the text

      if (0==iDraftParts) {
        oSentMessage.setText(sBody, Charset.forName(sEncoding).name(), "plain");
      } else {
        oMsgPlainText.setDisposition("inline");
        oMsgPlainText.setText(sBody,Charset.forName(sEncoding).name(),"plain");
        if (DebugFile.trace) DebugFile.writeln("MimeBodyPart(multipart/mixed).addBodyPart(text/plain)");
        oSentMsgParts.addBodyPart(oMsgPlainText);
      }
    }
    // fi (sContentType=="html")

    // ************************************************************************
    // Add attachments to message to be sent

    if (iDraftParts>0) {

      for (int p=0; p<iDraftParts; p++) {
        DBMimePart oPart = (DBMimePart) oDraftParts.getBodyPart(p);

        String sDisposition = oPart.getDisposition();
        if (sDisposition==null)
          sDisposition = "inline";
        else if (sDisposition.equals("reference") || sDisposition.equals("pointer"))
          sDisposition = "attachment";

        int iSize = oPart.getSize();
        if (iSize<=0) iSize = 4000;
        InputStream oInStrm = oPart.getInputStream();
        ByteArrayOutputStream oByStrm = new java.io.ByteArrayOutputStream(iSize);
        new StreamPipe().between(oInStrm, oByStrm);
        oInStrm.close();

        if (DebugFile.trace) DebugFile.writeln("part " + String.valueOf(p) + " size is " + String.valueOf(oByStrm.size()));

        ByteArrayDataSource oDataSrc = new ByteArrayDataSource(oByStrm.toByteArray(), oPart.getContentType());
        MimeBodyPart oAttachment = new MimeBodyPart();
        oAttachment.setDisposition(sDisposition);
        if (sDisposition.equals("attachment"))
        if (null==oPart.getDescription())
          oAttachment.setFileName(oPart.getFileName());
        else
          oAttachment.setFileName(oPart.getDescription());
        oAttachment.setHeader("Content-Transfer-Encoding", "base64");
        oAttachment.setDataHandler(new DataHandler(oDataSrc));
        oSentMsgParts.addBodyPart(oAttachment);
      } // next
      oSentMessage.setContent(oSentMsgParts);
    } // fi (iDraftParts>0)

View Full Code Here

  try {
    IBindingFactory oIbf = BindingDirectory.getFactory(YSearchResponse.class);
    IUnmarshallingContext oUmc = oIbf.createUnmarshallingContext();

    ByteArrayOutputStream oOst = new ByteArrayOutputStream();
    DataHandler oHnd = new DataHandler(oUrl);
    oHnd.writeTo(oOst);
    ByteArrayInputStream oIst = new ByteArrayInputStream(oOst.toByteArray());
    oYsr = (YSearchResponse) oUmc.unmarshalDocument (oIst, "UTF8");   
    oIst.close();
    oOst.close();
  } catch (JiBXException jibxe) {
View Full Code Here

    bp1.setContent("Hello World!!!", "text/plain; charset=\"ISO-8859-1\"");

    // Attach the file
    MimeBodyPart bp2 = new MimeBodyPart();
    FileDataSource fileAttachment = new FileDataSource(BIGFILE_PATH);
    DataHandler dh = new DataHandler(fileAttachment);
    bp2.setDataHandler(dh);
    bp2.setFileName(fileAttachment.getName());

    Multipart multipart = new MimeMultipart();
    multipart.addBodyPart(bp1);
View Full Code Here

    MimeMessage message = new MimeMessage(this.session);
    message.addRecipient(Message.RecipientType.TO, new InternetAddress("anyone@anywhere.com"));
    message.setFrom(new InternetAddress("someone@somewhereelse.com"));
    message.setSubject("hello");
    message.setHeader("Content-Transfer-Encoding", "8bit");
    message.setDataHandler(new DataHandler(new ByteArrayDataSource(body, "application/octet-stream")));

    Transport.send(message);

    InputStream in = this.wiser.getMessages().get(0).getMimeMessage().getInputStream();
    ByteArrayOutputStream tmp = new ByteArrayOutputStream();
View Full Code Here

          if (sSrc.startsWith("www."))
            sSrc = "http://" + sSrc;

          if (sSrc.startsWith("http://") || sSrc.startsWith("https://")) {
            oImgBodyPart.setDataHandler(new DataHandler(new URL(sSrc)));
          }
          else {
            oImgBodyPart.setDataHandler(new DataHandler(new FileDataSource(sSrc)));
          }

          oImgBodyPart.setContentID(sCid);
          oImgBodyPart.setDisposition(oImgBodyPart.INLINE);
          oImgBodyPart.setFileName(sCid);
View Full Code Here

                + (attachmentFile == null ? null : attachmentFile.getAbsolutePath()), MailHelper.class);
            return msg;
          }
          messageBodyPart = new MimeBodyPart();
          DataSource source = new FileDataSource(attachmentFile);
          messageBodyPart.setDataHandler(new DataHandler(source));
          messageBodyPart.setFileName(attachmentFile.getName());
          multipart.addBodyPart(messageBodyPart);
        }
        // Put parts in message
        msg.setContent(multipart);
View Full Code Here

    }

    @Override
    public DataHandler getAttachmentAsDataHandler(final String cid) {
      final InputPart inputPart = getInputPart(cid);
      return new DataHandler(
          new InputPartBackedDataSource(cid, inputPart));
    }
View Full Code Here

      logger.info("System encoding: " + System.getProperty("file.encoding"));
      MultipartClient client = ProxyFactory.create(MultipartClient.class,
              generateBaseUrl());
      SimpleMimeMultipartResource.Xop xop = new SimpleMimeMultipartResource.Xop(
              new Customer("bill\u00E9"), new Customer("monica"),
              "Hello Xop World!".getBytes("UTF-8"), new DataHandler(
                      new ByteArrayDataSource("Hello Xop World!"
                              .getBytes("UTF-8"),
                              MediaType.APPLICATION_OCTET_STREAM)));
      client.putXop(xop);
   }
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.