Package com.sun.xml.messaging.saaj.util

Examples of com.sun.xml.messaging.saaj.util.ByteOutputStream


        if (mimePart != null) {
            mimePart.close();
            mimePart = null;
        }
        dataHandler = null;
        ByteOutputStream bos = null;
        try {
            InternetHeaders hdrs = new InternetHeaders();
            hdrs.setHeader("Content-Type", contentType);
            //TODO: reading the entire attachment here is ineffcient. Somehow the MimeBodyPart
            // Ctor with inputStream causes problems based on whether the InputStream has
            // markSupported()==true or false
            bos = new ByteOutputStream();
            bos.write(content);
            rawContent = new MimeBodyPart(hdrs, bos.getBytes(), bos.getCount());
            setMimeHeader("Content-Type", contentType);
        } catch (Exception e) {
            log.log(Level.SEVERE, "SAAJ0576.soap.attachment.setrawcontent.exception", e);
            throw new SOAPExceptionImpl(e.getLocalizedMessage());
        } finally {
            if (bos != null)
                bos.close();
            try {
                content.close();
            } catch (IOException ex) {
                throw new SOAPException(ex);
            }
View Full Code Here


      throws IOException {
  if (obj instanceof MimeMultipart) {
      try {
                //TODO: temporarily allow only ByteOutputStream
                // Need to add writeTo(OutputStream) on MimeMultipart
                ByteOutputStream baos = null;
                if (os instanceof ByteOutputStream) {
                    baos = (ByteOutputStream)os;
                } else {
                    throw new IOException("Input Stream expected to be a com.sun.xml.messaging.saaj.util.ByteOutputStream, but found " +
                        os.getClass().getName());
View Full Code Here

                    "SAAJ0573.soap.attachment.getrawbytes.ioexception",
                    new String[] { ex.getLocalizedMessage()});
                throw new SOAPExceptionImpl("Raw InputStream Error: " + ex);
            }
        } else {
            ByteOutputStream bout = new ByteOutputStream();
            try {
                dataHandler.writeTo(bout);
            } catch (IOException ex) {
                log.log(
                    Level.SEVERE,
                    "SAAJ0501.soap.data.handler.err",
                    new String[] { ex.getLocalizedMessage()});
                throw new SOAPExceptionImpl("Data handler error: " + ex);
            }
            bytes = bout.getBytes();
            if (bytes != null)
                return bytes.length;
        }
        return -1;
    }
View Full Code Here

            InternetHeaders hdrs = new InternetHeaders();
            hdrs.setHeader("Content-Type", contentType);
            //TODO: reading the entire attachment here is ineffcient. Somehow the MimeBodyPart
            // Ctor with inputStream causes problems based on the InputStream
            // has markSupported()==true
            ByteOutputStream bos = new ByteOutputStream();
            bos.write(decoded);
            rawContent = new MimeBodyPart(hdrs, bos.getBytes(), bos.getCount());
            setMimeHeader("Content-Type", contentType);
        } catch (Exception e) {
            log.log(Level.SEVERE, "SAAJ0578.soap.attachment.setbase64content.exception", e);
            throw new SOAPExceptionImpl(e.getLocalizedMessage());
        }
View Full Code Here

            InternetHeaders hdrs = new InternetHeaders();
            hdrs.setHeader("Content-Type", contentType);
            //TODO: reading the entire attachment here is ineffcient. Somehow the MimeBodyPart
            // Ctor with inputStream causes problems based on whether the InputStream has
            // markSupported()==true or false
            ByteOutputStream bos = new ByteOutputStream();
            bos.write(content);
            rawContent = new MimeBodyPart(hdrs, bos.getBytes(), bos.getCount());
            setMimeHeader("Content-Type", contentType);
        } catch (Exception e) {
            log.log(Level.SEVERE, "SAAJ0576.soap.attachment.setrawcontent.exception", e);
            throw new SOAPExceptionImpl(e.getLocalizedMessage());
        }
View Full Code Here

        if (is instanceof SharedInputStream) {
            SharedInputStream sis = (SharedInputStream) is;
            contentStream = sis.newStream(sis.getPosition(), -1);
        } else {
            try {
                ByteOutputStream bos = new ByteOutputStream();
                bos.write(is);
                content = bos.getBytes();
                contentLength = bos.getCount();
            } catch (IOException ioex) {
                throw new MessagingException("Error reading input stream", ioex);
            }
        }
View Full Code Here

     *      buffer reallocation just to get the array of an exact size.
     *      Unless you absolutely need the exact size array, don't use this.
     *      Use {@link ByteOutputStream} and {@link ByteOutputStream#write(InputStream)}.
     */
    public static byte[] getBytes(InputStream is) throws IOException {
        ByteOutputStream bos = new ByteOutputStream();
        bos.write(is);
        return bos.toByteArray();
    }
View Full Code Here

            addBodyPart(mbp);
            return mbp;
           
        } else {
            InternetHeaders headers = createInternetHeaders(stream);
            ByteOutputStream baos = new ByteOutputStream();
            b = readBody(stream, pattern, null,baos, null);
            // looks like this check has to be disabled
            // in the old impl it is allowed to have Mime Package
            // without closing boundary
            /*
            if ((b == -1) && !lastBodyPartFound()) {
                throw new Exception(
                    "End of Stream encountered without closing boundary");
            }*/
            MimeBodyPart mbp = createMimeBodyPart(
                headers, baos.getBytes(), baos.getCount());
            addBodyPart(mbp);
            return mbp;
        }

    }
View Full Code Here

        if (in != null) {
            OutputUtil.writeln(bnd, os); // put out boundary
            if ((os instanceof ByteOutputStream) && lazyAttachments) {
                ((ByteOutputStream)os).write(in);
            } else {
                ByteOutputStream baos = new ByteOutputStream(in.available());
                baos.write(in);
                baos.writeTo(os);
                // reset the inputstream so that we can support a
                //getAttachment later
                in = baos.newInputStream();
            }
    
            // this will endup writing the end boundary
        } else {
        // put out last boundary
View Full Code Here

    }

    if (!in.markSupported())
        throw new MessagingException("Stream doesn't support mark");

    ByteOutputStream buf = null;
    // if we don't have a shared input stream, we copy the data
    if (sin == null)
        buf = new ByteOutputStream();
    int b;
    boolean bol = true;    // beginning of line flag
    // the two possible end of line characters
    int eol1 = -1, eol2 = -1;

    /*
     * Read and save the content bytes in buf.
     */
    for (;;) {
        if (bol) {
      /*
       * At the beginning of a line, check whether the
       * next line is a boundary.
       */
      int i;
      in.mark(bl + 4 + 1000); // bnd + "--\r\n" + lots of LWSP
      // read bytes, matching against the boundary
      for (i = 0; i < bl; i++)
          if (in.read() != bndbytes[i])
        break;
      if (i == bl) {
          // matched the boundary, check for last boundary
          int b2 = in.read();
          if (b2 == '-') {
        if (in.read() == '-') {
            done = true;
            break// ignore trailing text
        }
          }
          // skip linear whitespace
          while (b2 == ' ' || b2 == '\t')
        b2 = in.read();
          // check for end of line
          if (b2 == '\n')
        break// got it!  break out of the loop
          if (b2 == '\r') {
        in.mark(1);
        if (in.read() != '\n')
            in.reset();
        break// got it!  break out of the loop
          }
      }
      // failed to match, reset and proceed normally
      in.reset();

      // if this is not the first line, write out the
      // end of line characters from the previous line
      if (buf != null && eol1 != -1) {
          buf.write(eol1);
          if (eol2 != -1)
        buf.write(eol2);
          eol1 = eol2 = -1;
      }
        }

        // read the next byte
        if ((b = in.read()) < 0) {
      done = true;
      break;
        }

        /*
         * If we're at the end of the line, save the eol characters
         * to be written out before the beginning of the next line.
         */
        if (b == '\r' || b == '\n') {
      bol = true;
      if (sin != null)
          end = sin.getPosition() - 1;
      eol1 = b;
      if (b == '\r') {
          in.mark(1);
          if ((b = in.read()) == '\n')
        eol2 = b;
          else
        in.reset();
      }
        } else {
      bol = false;
      if (buf != null)
          buf.write(b);
        }
    }

    /*
     * Create a MimeBody element to represent this body part.
     */
    MimeBodyPart part;
    if (sin != null)
        part = createMimeBodyPart(sin.newStream(start, end));
    else
        part = createMimeBodyPart(headers, buf.getBytes(), buf.getCount());
    addBodyPart(part);
      }
  } catch (IOException ioex) {
      throw new MessagingException("IO Error", ioex);
  }
View Full Code Here

TOP

Related Classes of com.sun.xml.messaging.saaj.util.ByteOutputStream

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.