Пример #1
0
 private void nextCurrent() throws IOException {
   if (rootPart != null) {
     if (writingHeaders) {
       writingHeaders = false;
       current = rootPart.getInputStream();
       rootPart = null;
     } else {
       writingHeaders = true;
       bout.reset();
       writer.append("--").append(boundary).append("\r\n");
       writer.append("Content-Type: ").append(rootPart.getContentType()).append("\r\n");
       writer.append("Content-ID: <").append(start).append(">\r\n\r\n");
       writer.flush();
       current = bout.createInputStream();
     }
   } else {
     if (writingHeaders) {
       writingHeaders = false;
       current = att.getDataHandler().getInputStream();
     } else if (atts.hasNext()) {
       att = atts.next();
       writingHeaders = true;
       bout.reset();
       writer.append("\r\n");
       writer.append("--").append(boundary).append("\r\n");
       Iterator<String> heads = att.getHeaderNames();
       while (heads.hasNext()) {
         String s = heads.next();
         writer.append(s).append(": ").append(att.getHeader(s)).append("\r\n");
       }
       writer.append("\r\n");
       writer.flush();
       current = bout.createInputStream();
     }
   }
 }
Пример #2
0
 MultiPartDataSource(Message message, DataSource root) {
   atts = message.getAttachments().iterator();
   String s = (String) message.get(Message.CONTENT_TYPE);
   boundary = findBoundary(s);
   start = findStart(s);
   if (!s.contains(boundary)) {
     s += "; boundary=\"" + boundary + "\"";
   }
   contentType = s;
   rootPart = root;
   try {
     writer = new OutputStreamWriter(bout, "ASCII");
     writer.append("Content-Type: ").append(contentType).append("\r\n\r\n");
     writer.flush();
     current = bout.createInputStream();
   } catch (Exception e) {
     // nothing
   }
 }