axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@apache.org
Subject cvs commit: xml-axis/java/src/org/apache/axis/attachments AttachmentPart.java AttachmentUtils.java Attachments.java AttachmentsImpl.java BoundaryDelimitedStream.java ManagedMemoryDataSource.java MimeUtils.java MultiPartRelatedInputStream.java
Date Mon, 24 Jun 2002 12:34:51 GMT
dims        2002/06/24 05:34:51

  Modified:    java/src/org/apache/axis/attachments AttachmentPart.java
                        AttachmentUtils.java Attachments.java
                        AttachmentsImpl.java BoundaryDelimitedStream.java
                        ManagedMemoryDataSource.java MimeUtils.java
                        MultiPartRelatedInputStream.java
  Log:
  - Formatting changes to improve readability
  - Added javadoc stubs
  - Converted one System.err.println to log.warn
  
  Revision  Changes    Path
  1.11      +140 -69   xml-axis/java/src/org/apache/axis/attachments/AttachmentPart.java
  
  Index: AttachmentPart.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/attachments/AttachmentPart.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- AttachmentPart.java	23 Jun 2002 22:08:10 -0000	1.10
  +++ AttachmentPart.java	24 Jun 2002 12:34:51 -0000	1.11
  @@ -52,51 +52,81 @@
    * information on the Apache Software Foundation, please see
    * <http://www.apache.org/>.
    */
  -
   package org.apache.axis.attachments;
   
   import org.apache.axis.Part;
  +import org.apache.axis.transport.http.HTTPConstants;
   import org.apache.axis.utils.JavaUtils;
   import org.apache.axis.utils.SOAPUtils;
  -import org.apache.axis.transport.http.HTTPConstants;
   import org.apache.commons.logging.Log;
   import org.apache.commons.logging.LogFactory;
   
   import javax.activation.DataHandler;
   import javax.xml.soap.SOAPException;
  -import java.util.Hashtable;
   import java.util.Iterator;
   
  -public class AttachmentPart extends javax.xml.soap.AttachmentPart implements Part {
  +/**
  + * Class AttachmentPart
  + *
  + */
  +public class AttachmentPart extends javax.xml.soap.AttachmentPart
  +        implements Part {
  +
  +    /** Field log           */
       protected static Log log =
  -        LogFactory.getLog(AttachmentPart.class.getName());
  +            LogFactory.getLog(AttachmentPart.class.getName());
   
  -    javax.activation.DataHandler datahandler= null;
  +    /** Field datahandler           */
  +    javax.activation.DataHandler datahandler = null;
   
  -    //private Hashtable headers = new Hashtable();
  -    private javax.xml.soap.MimeHeaders mimeHeaders = new javax.xml.soap.MimeHeaders();
  +    // private Hashtable headers = new Hashtable();
  +
  +    /** Field mimeHeaders           */
  +    private javax.xml.soap.MimeHeaders mimeHeaders =
  +            new javax.xml.soap.MimeHeaders();
  +
  +    /** Field contentId           */
       private String contentId;
  -    private String contentLocation;
   
  +    /** Field contentLocation           */
  +    private String contentLocation;
   
  +    /**
  +     * Constructor AttachmentPart
  +     */
       public AttachmentPart() {
  -        addMimeHeader(HTTPConstants.HEADER_CONTENT_ID , SOAPUtils.getNewContentIdValue());
  -
  +        addMimeHeader(HTTPConstants.HEADER_CONTENT_ID,
  +                SOAPUtils.getNewContentIdValue());
       }
   
  -    public AttachmentPart(javax.activation.DataHandler dh ) {
  -        addMimeHeader(HTTPConstants.HEADER_CONTENT_ID , SOAPUtils.getNewContentIdValue());
  +    /**
  +     * Constructor AttachmentPart
  +     *
  +     * @param dh
  +     */
  +    public AttachmentPart(javax.activation.DataHandler dh) {
  +
  +        addMimeHeader(HTTPConstants.HEADER_CONTENT_ID,
  +                SOAPUtils.getNewContentIdValue());
  +
  +        datahandler = dh;
   
  -        datahandler= dh;
  -        addMimeHeader(HTTPConstants.HEADER_CONTENT_TYPE , dh.getContentType());
  +        addMimeHeader(HTTPConstants.HEADER_CONTENT_TYPE, dh.getContentType());
       }
   
  -    public javax.activation.DataHandler getActivationDataHandler(){
  -      return datahandler;
  +    /**
  +     * Method getActivationDataHandler
  +     *
  +     * @return
  +     */
  +    public javax.activation.DataHandler getActivationDataHandler() {
  +        return datahandler;
       }
   
       /**
        * TODO: everything!
  +     *
  +     * @return
        */
       public String getContentType() {
           return getFirstMimeHeader(HTTPConstants.HEADER_CONTENT_TYPE);
  @@ -104,43 +134,51 @@
   
       /**
        * Add the specified MIME header, as per JAXM.
  +     *
  +     * @param header
  +     * @param value
        */
  -    public void addMimeHeader (String header, String value) {
  +    public void addMimeHeader(String header, String value) {
   
  -        if(null == header) {
  -            throw new IllegalArgumentException(JavaUtils.getMessage("headerNotNull"));
  +        if (null == header) {
  +            throw new IllegalArgumentException(
  +                    JavaUtils.getMessage("headerNotNull"));
           }
   
           header = header.trim();
   
  -        if(header.length() == 0) {
  +        if (header.length() == 0) {
               throw new IllegalArgumentException(
                       JavaUtils.getMessage("headerNotEmpty"));
           }
   
  -        if(null == value) {
  +        if (null == value) {
               throw new IllegalArgumentException(
                       JavaUtils.getMessage("headerValueNotNull"));
           }
  +
           mimeHeaders.setHeader(header.toLowerCase(), value);
       }
   
       /**
        * Get the specified MIME header.
  +     *
  +     * @param header
  +     *
  +     * @return
        */
  -    public String getFirstMimeHeader (String header) {
  +    public String getFirstMimeHeader(String header) {
  +
           String[] values = mimeHeaders.getHeader(header.toLowerCase());
  -        if(values != null && values.length  > 0)
  +
  +        if ((values != null) && (values.length > 0)) {
               return values[0];
  +        }
  +
           return null;
       }
   
       /**
  -     * Total size in bytes (of all content and headers, as encoded).
  -    public abstract int getSize();
  -     */
  -
  -    /**
        * Content location.
        */
       public String getContentLocation() {
  @@ -149,54 +187,74 @@
   
       /**
        * Set content location.
  +     *
  +     * @param loc
        */
       public void setContentLocation(String loc) {
           addMimeHeader(HTTPConstants.HEADER_CONTENT_LOCATION, loc);
       }
   
       /**
  -         * Sets Content-Id of this part. "cid:" prefix will be added if one wan't
  -         *  already defined.
  -         * @param newCid new Content-Id
  -         * @returns void
  -         */
  -        public void setContentId(String newCid){
  -                if(!newCid.toLowerCase().startsWith("cid:")){
  -                        newCid="cid:"+newCid;
  -                }
  -                addMimeHeader(HTTPConstants.HEADER_CONTENT_ID,newCid);
  +     *     Sets Content-Id of this part. "cid:" prefix will be added if one wan't
  +     *      already defined.
  +     *     @param newCid new Content-Id
  +     *     @returns void
  +     */
  +    public void setContentId(String newCid) {
  +
  +        if (!newCid.toLowerCase().startsWith("cid:")) {
  +            newCid = "cid:" + newCid;
           }
   
  +        addMimeHeader(HTTPConstants.HEADER_CONTENT_ID, newCid);
  +    }
  +
       /**
        * Content ID.
  +     *
  +     * @return
        */
       public String getContentId() {
  -        String ret= getFirstMimeHeader(HTTPConstants.HEADER_CONTENT_ID);
  -        //Do not let the contentID ever be empty.
  -        if(ret == null){
  -            ret=SOAPUtils.getNewContentIdValue();
  -            addMimeHeader(HTTPConstants.HEADER_CONTENT_ID , ret);
  +
  +        String ret = getFirstMimeHeader(HTTPConstants.HEADER_CONTENT_ID);
  +
  +        // Do not let the contentID ever be empty.
  +        if (ret == null) {
  +            ret = SOAPUtils.getNewContentIdValue();
  +
  +            addMimeHeader(HTTPConstants.HEADER_CONTENT_ID, ret);
           }
  -        ret= ret.trim();
  -        if(ret.length() ==0){
  -            ret=SOAPUtils.getNewContentIdValue();
  -            addMimeHeader(HTTPConstants.HEADER_CONTENT_ID , ret);
  +
  +        ret = ret.trim();
  +
  +        if (ret.length() == 0) {
  +            ret = SOAPUtils.getNewContentIdValue();
  +
  +            addMimeHeader(HTTPConstants.HEADER_CONTENT_ID, ret);
           }
  +
           return ret;
       }
   
  -
       /**
        * Get all headers that match
  +     *
  +     * @param match
  +     *
  +     * @return
        */
  -    public java.util.Iterator getMatchingMimeHeaders( final String[] match){
  +    public java.util.Iterator getMatchingMimeHeaders(final String[] match) {
           return mimeHeaders.getMatchingHeaders(match);
       }
   
       /**
        * Get all headers that do not match
  +     *
  +     * @param match
  +     *
  +     * @return
        */
  -    public java.util.Iterator getNonMatchingMimeHeaders( final String[] match){
  +    public java.util.Iterator getNonMatchingMimeHeaders(final String[] match) {
           return mimeHeaders.getNonMatchingHeaders(match);
       }
   
  @@ -228,8 +286,8 @@
        *     there was a problem with the specified mime header name
        *     or value
        */
  -    public void setMimeHeader(String name, String value){
  -        mimeHeaders.setHeader(name,value);
  +    public void setMimeHeader(String name, String value) {
  +        mimeHeaders.setHeader(name, value);
       }
   
       /** Removes all the MIME header entries. */
  @@ -310,20 +368,26 @@
        *     was a data transformation error
        */
       public Object getContent() throws SOAPException {
  +
           javax.activation.DataSource ds = datahandler.getDataSource();
  -        if(ds instanceof ManagedMemoryDataSource){
  -            ManagedMemoryDataSource mds = (ManagedMemoryDataSource)ds;
  -            if(ds.getContentType().equals("text/plain")){
  +
  +        if (ds instanceof ManagedMemoryDataSource) {
  +            ManagedMemoryDataSource mds = (ManagedMemoryDataSource) ds;
  +
  +            if (ds.getContentType().equals("text/plain")) {
                   try {
                       java.io.InputStream is = ds.getInputStream();
                       byte[] bytes = new byte[is.available()];
  +
                       is.read(bytes);
  +
                       return new String(bytes);
  -                } catch (java.io.IOException io){
  +                } catch (java.io.IOException io) {
                       log.error(JavaUtils.getMessage("javaIOException00"), io);
                   }
               }
           }
  +
           return null;
       }
   
  @@ -335,9 +399,9 @@
        * the <CODE>Content-Type</CODE>. This depends on the particular
        * set of <CODE>DataContentHandler</CODE> objects in use.
        * @param  object  the Java object that makes up
  -          the content for this attachment part
  +     *     the content for this attachment part
        * @param  contentType the MIME string that
  -          specifies the type of the content
  +     *     specifies the type of the content
        * @throws java.lang.IllegalArgumentException if
        *     the contentType does not match the type of the content
        *     object, or if there was no <CODE>
  @@ -346,18 +410,26 @@
        * @see #getContent() getContent()
        */
       public void setContent(Object object, String contentType) {
  -        if(object instanceof String) {
  +
  +        if (object instanceof String) {
               try {
  -                String s = (String)object;
  -                java.io.ByteArrayInputStream bais = new java.io.ByteArrayInputStream(s.getBytes());
  -                datahandler = new DataHandler(new ManagedMemoryDataSource(bais, 1024, contentType, true));
  +                String s = (String) object;
  +                java.io.ByteArrayInputStream bais =
  +                        new java.io.ByteArrayInputStream(s.getBytes());
  +
  +                datahandler = new DataHandler(new ManagedMemoryDataSource(bais,
  +                        1024, contentType, true));
  +
                   return;
  -            } catch (java.io.IOException io){
  +            } catch (java.io.IOException io) {
                   log.error(JavaUtils.getMessage("javaIOException00"), io);
  -                throw new java.lang.IllegalArgumentException(JavaUtils.getMessage("illegalAccessException00"));
  +
  +                throw new java.lang.IllegalArgumentException(
  +                        JavaUtils.getMessage("illegalAccessException00"));
               }
           } else {
  -            throw new java.lang.IllegalArgumentException(JavaUtils.getMessage("illegalAccessException00"));
  +            throw new java.lang.IllegalArgumentException(
  +                    JavaUtils.getMessage("illegalAccessException00"));
           }
       }
   
  @@ -367,7 +439,7 @@
        * untouched.
        */
       public void clearContent() {
  -        //TODO: Implement this.
  +        // TODO: Implement this.
       }
   
       /**
  @@ -380,7 +452,7 @@
        *     while trying to determine the size.
        */
       public int getSize() throws SOAPException {
  -        //TODO: Implement this.
  +        // TODO: Implement this.
           return -1;
       }
   
  @@ -397,4 +469,3 @@
           return mimeHeaders.getHeader(name);
       }
   }
  -
  
  
  
  1.6       +36 -21    xml-axis/java/src/org/apache/axis/attachments/AttachmentUtils.java
  
  Index: AttachmentUtils.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/attachments/AttachmentUtils.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- AttachmentUtils.java	29 May 2002 13:05:54 -0000	1.5
  +++ AttachmentUtils.java	24 Jun 2002 12:34:51 -0000	1.6
  @@ -52,51 +52,66 @@
    * information on the Apache Software Foundation, please see
    * <http://www.apache.org/>.
    */
  -
   package org.apache.axis.attachments;
  -import javax.activation.DataHandler;
  -import org.apache.axis.Part;
  +
   import org.apache.axis.AxisFault;
  +import org.apache.axis.Part;
   import org.apache.axis.utils.JavaUtils;
   
  +import javax.activation.DataHandler;
   
   /**
  - * This class allow access to the Jaf data handler in AttachmentPart. 
  + * This class allow access to the Jaf data handler in AttachmentPart.
    *
    * @author Rick Rineholt
    */
  -
   public class AttachmentUtils {
  -    private AttachmentUtils(){};  //no one should create.
  +
  +    /**
  +     * Constructor AttachmentUtils
  +     */
  +    private AttachmentUtils() {
  +    }
  +    // no one should create.
   
       /**
        * Obtain the DataHandler from the part.
        * @param part the part containing the Java Activiation Framework data source.
        * @return The Java activiation data handler.
  +     *
  +     * @throws AxisFault
        */
  +    public static DataHandler getActivationDataHandler(Part part)
  +            throws AxisFault {
   
  -    public static DataHandler getActivationDataHandler(Part part) throws AxisFault{
  -       if( null == part) {
  -        throw new AxisFault(JavaUtils.getMessage("gotNullPart"));
  -       }
  -
  -       if(!( part instanceof AttachmentPart)){
  -        throw new AxisFault(JavaUtils.getMessage("unsupportedAttach",
  -                part.getClass().getName(), AttachmentPart.class.getName()));
  -       }
  -       return ((AttachmentPart) part).getActivationDataHandler();
  +        if (null == part) {
  +            throw new AxisFault(JavaUtils.getMessage("gotNullPart"));
  +        }
  +
  +        if (!(part instanceof AttachmentPart)) {
  +            throw new AxisFault(
  +                    JavaUtils.getMessage(
  +                            "unsupportedAttach", part.getClass().getName(),
  +                            AttachmentPart.class.getName()));
  +        }
  +
  +        return ((AttachmentPart) part).getActivationDataHandler();
       }
   
       /**
  -     * Determine if an object is to be treated as an attchment. 
  +     * Determine if an object is to be treated as an attchment.
        *
        * @param value the value that is to be determined if
        * its an attachment.
        *
  -     * @return True if value should be treated as an attchment. 
  +     * @return True if value should be treated as an attchment.
        */
  -    public static boolean isAttachment( Object value){
  -        if( null == value ) return false;
  -        return value instanceof  javax.activation.DataHandler;
  +    public static boolean isAttachment(Object value) {
  +
  +        if (null == value) {
  +            return false;
  +        }
  +
  +        return value instanceof javax.activation.DataHandler;
       }
   }
  
  
  
  1.8       +80 -36    xml-axis/java/src/org/apache/axis/attachments/Attachments.java
  
  Index: Attachments.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/attachments/Attachments.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- Attachments.java	23 Jun 2002 20:20:19 -0000	1.7
  +++ Attachments.java	24 Jun 2002 12:34:51 -0000	1.8
  @@ -52,7 +52,6 @@
    * information on the Apache Software Foundation, please see
    * <http://www.apache.org/>.
    */
  -
   package org.apache.axis.attachments;
   
   import org.apache.axis.Part;
  @@ -67,7 +66,6 @@
    * @author Rob Jellinghaus (robj@unrealities.com)
    * @author Rick Rineholt
    */
  -
   public interface Attachments {
   
       /**
  @@ -75,18 +73,26 @@
        * Note: Passed part will be bound to this message.
        * @param newPart new part to add
        * @returns Part old attachment with the same Content-ID, or null.
  +     *
  +     * @return
        * @throws org.apache.axis.AxisFault
        */
  -     public Part addAttachmentPart(Part newPart) throws org.apache.axis.AxisFault;
  +    public Part addAttachmentPart(Part newPart)
  +            throws org.apache.axis.AxisFault;
   
       /**
        * This method uses getAttacmentByReference() to look for attachment.
        * If attachment has been found, it will be removed from the list, and
        * returned to the user.
        * @param  The reference that referers to an attachment.
  +     *
  +     * @param reference
        * @return The part associated with the removed attachment, or null.
  +     *
  +     * @throws org.apache.axis.AxisFault
        */
  -     public Part removeAttachmentPart(String reference) throws org.apache.axis.AxisFault;
  +    public Part removeAttachmentPart(String reference)
  +            throws org.apache.axis.AxisFault;
   
       /**
        * Removes all <CODE>AttachmentPart</CODE> objects that have
  @@ -100,16 +106,24 @@
        * This method should look at a refernce and determine if it is a CID: or url
        * to look for attachment.
        * @param  The reference in the xml that referers to an attachment.
  +     *
  +     * @param reference
        * @return The part associated with the attachment.
  -     */ 
  -    public Part getAttachmentByReference(String reference) throws org.apache.axis.AxisFault;
  +     *
  +     * @throws org.apache.axis.AxisFault
  +     */
  +    public Part getAttachmentByReference(String reference)
  +            throws org.apache.axis.AxisFault;
   
       /**
  -     * This method will return all attachments as a collection. 
  -     * 
  -     * @return A collection of attachments. 
  -     */ 
  -    public java.util.Collection getAttachments() throws org.apache.axis.AxisFault;
  +     * This method will return all attachments as a collection.
  +     *
  +     * @return A collection of attachments.
  +     *
  +     * @throws org.apache.axis.AxisFault
  +     */
  +    public java.util.Collection getAttachments()
  +            throws org.apache.axis.AxisFault;
   
       /**
        * Retrieves all the <CODE>AttachmentPart</CODE> objects
  @@ -122,69 +136,99 @@
        * @return an iterator over all attachments that have a header
        *     that matches one of the given headers
        */
  -    public java.util.Iterator getAttachments(javax.xml.soap.MimeHeaders headers);
  +    public java.util.Iterator getAttachments(
  +            javax.xml.soap.MimeHeaders headers);
   
       /**
        * Create a new attachment Part in this Message.
        * Will actually, and always, return an AttachmentPart.
  -     * @param The part that is referenced 
  -     */ 
  -    public Part createAttachmentPart(Object part) throws org.apache.axis.AxisFault;
  +     * @param The part that is referenced
  +     *
  +     * @param part
  +     *
  +     * @return
  +     *
  +     * @throws org.apache.axis.AxisFault
  +     */
  +    public Part createAttachmentPart(Object part)
  +            throws org.apache.axis.AxisFault;
   
       /**
        * Create a new attachment Part in this Message.
        * Will actually, and always, return an AttachmentPart.
  +     *
  +     * @return
  +     *
  +     * @throws org.apache.axis.AxisFault
        */
       public Part createAttachmentPart() throws org.apache.axis.AxisFault;
   
       /**
        *  Will the attachments of this message to that of the colleciton.
  -     */ 
  -    public void setAttachmentParts( java.util.Collection parts) throws org.apache.axis.AxisFault;
  +     *
  +     * @param parts
  +     *
  +     * @throws org.apache.axis.AxisFault
  +     */
  +    public void setAttachmentParts(java.util.Collection parts)
  +            throws org.apache.axis.AxisFault;
   
       /**
  -     * From the complex stream return the SOAP part. 
  +     * From the complex stream return the SOAP part.
        * @return will return the root part if the stream is supported,
        *         otherwise null.
  -     */ 
  +     */
       public Part getRootPart();
   
       /**
        * Sets the root part of this multipart block
  +     *
  +     * @param newRoot
        */
       public void setRootPart(Part newRoot);
   
       /**
  -     * Get the content length of the stream. 
  -     */ 
  +     * Get the content length of the stream.
  +     *
  +     * @return
  +     *
  +     * @throws org.apache.axis.AxisFault
  +     */
       public int getContentLength() throws org.apache.axis.AxisFault;
   
       /**
  -     * Write the content to the stream. 
  -     */ 
  -    public void writeContentToStream(java.io.OutputStream os) throws org.apache.axis.AxisFault;
  +     * Write the content to the stream.
  +     *
  +     * @param os
  +     *
  +     * @throws org.apache.axis.AxisFault
  +     */
  +    public void writeContentToStream(java.io.OutputStream os)
  +            throws org.apache.axis.AxisFault;
   
       /**
  -     * Write the content to the stream. 
  -     */ 
  -    public String getContentType()throws org.apache.axis.AxisFault;
  +     * Write the content to the stream.
  +     *
  +     * @return
  +     *
  +     * @throws org.apache.axis.AxisFault
  +     */
  +    public String getContentType() throws org.apache.axis.AxisFault;
   
       /**
  -     *This is the number of attachments.
  -     **/
  +     * This is the number of attachments.
  +     *
  +     * @return
  +     */
       public int getAttachmentCount();
   
       /**
  -     * Determine if an object is to be treated as an attchment. 
  +     * Determine if an object is to be treated as an attchment.
        *
        * @param value the value that is to be determined if
        * its an attachment.
        *
  -     * @return True if value should be treated as an attchment. 
  +     * @return True if value should be treated as an attchment.
        */
  -
  -    public boolean isAttachment( Object value);
  -
  -
  -    
  +    public boolean isAttachment(Object value);
   }
  
  
  
  1.17      +284 -139  xml-axis/java/src/org/apache/axis/attachments/AttachmentsImpl.java
  
  Index: AttachmentsImpl.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/attachments/AttachmentsImpl.java,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- AttachmentsImpl.java	23 Jun 2002 22:08:10 -0000	1.16
  +++ AttachmentsImpl.java	24 Jun 2002 12:34:51 -0000	1.17
  @@ -54,33 +54,40 @@
    */
   
   /* @author Rob Jellinghaus (robj@unrealities.com) */
  -/* @author Rick Rineholt  */
  -
  +/* @author Rick Rineholt */
   package org.apache.axis.attachments;
   
   import org.apache.axis.AxisFault;
  -import org.apache.axis.Message;
   import org.apache.axis.Part;
   import org.apache.axis.SOAPPart;
   import org.apache.axis.utils.JavaUtils;
  +
   import javax.activation.DataHandler;
   import javax.activation.DataSource;
  -
  -import java.util.*;
  +import java.util.Collection;
  +import java.util.HashMap;
  +import java.util.LinkedList;
   
   /**
    * Implements the Attachment interface, via an actual Hashmap of actual
    * AttachmentParts.
    */
  -
   public class AttachmentsImpl implements Attachments {
  +
  +    /** Field attachments           */
       private HashMap attachments = new java.util.HashMap();
  -    private LinkedList orderedAttachments=new LinkedList();
  +
  +    /** Field orderedAttachments           */
  +    private LinkedList orderedAttachments = new LinkedList();
  +
  +    /** Field soapPart           */
       protected SOAPPart soapPart = null;
  +
       /**
        * The actual stream to manage the multi-related input stream.
        */
  -    protected org.apache.axis.attachments.MultiPartRelatedInputStream mpartStream = null;
  +    protected org.apache.axis.attachments.MultiPartRelatedInputStream mpartStream =
  +            null;
   
       /**
        * This is the content location as specified in SOAP with Attachments.
  @@ -93,52 +100,71 @@
        * Should only ever be called by Message constructor!
        * @param initialContents should be anything but today only a stream is
        *        supported.
  -     * @param The mime content type of the stream for transports that provide 
  +     * @param The mime content type of the stream for transports that provide
        *        it.
  +     *
  +     * @param intialContents
  +     * @param contentType
  +     * @param contentLocation
  +     *
  +     * @throws org.apache.axis.AxisFault
        */
  -    public AttachmentsImpl(Object intialContents,
  -                           String contentType,
  -                           String contentLocation) 
  -            throws org.apache.axis.AxisFault 
  -    {
  +    public AttachmentsImpl(
  +            Object intialContents, String contentType, String contentLocation)
  +            throws org.apache.axis.AxisFault {
  +
           if (contentLocation != null) {
               contentLocation = contentLocation.trim();
  -            if (contentLocation.length() == 0) contentLocation = null;
  +
  +            if (contentLocation.length() == 0) {
  +                contentLocation = null;
  +            }
           }
  +
           this.contentLocation = contentLocation;
   
           if (contentType != null) {
               if (contentType.equals(org.apache.axis.Message.MIME_UNKNOWN)) {
  -                //Process the input stream for headers to determine the mime
  -                //type.
  -                //TODO
  +
  +                // Process the input stream for headers to determine the mime
  +                // type.
  +                // TODO
               } else {
  -                java.util.StringTokenizer st = 
  +                java.util.StringTokenizer st =
                           new java.util.StringTokenizer(contentType, " \t;");
  +
                   if (st.hasMoreTokens()) {
                       String mimetype = st.nextToken();
  +
                       if (mimetype.equalsIgnoreCase(
                               org.apache.axis.Message.MIME_MULTIPART_RELATED)) {
  -                        mpartStream = 
  -                                new org.apache.axis.attachments.MultiPartRelatedInputStream(contentType,
  -                                                                                            (java.io.InputStream) intialContents);
  +                        mpartStream =
  +                                new org.apache.axis.attachments.MultiPartRelatedInputStream(
  +                                        contentType,
  +                                        (java.io.InputStream) intialContents);
  +
                           if (null == contentLocation) {
  -                            //If the content location is not specified as
  -                            //of the main message use the SOAP content location.
  +
  +                            // If the content location is not specified as
  +                            // of the main message use the SOAP content location.
                               contentLocation = mpartStream.getContentLocation();
   
                               if (contentLocation != null) {
                                   contentLocation = contentLocation.trim();
  -                                if (contentLocation.length() == 0) 
  +
  +                                if (contentLocation.length() == 0) {
                                       contentLocation = null;
  +                                }
                               }
                           }
   
                           soapPart = new org.apache.axis.SOAPPart(null,
  -                                                                mpartStream, 
  -                                                                false);
  -                    } else if (mimetype.equalsIgnoreCase(org.apache.axis.Message.MIME_APPLICATION_DIME)) { //do nothing today.
  -                        //is= new DIMEInputStreamManager(is);
  +                                mpartStream,
  +                                false);
  +                    } else if (mimetype.equalsIgnoreCase(
  +                            org.apache.axis.Message.MIME_APPLICATION_DIME)) {    // do nothing today.
  +
  +                        // is= new DIMEInputStreamManager(is);
                       }
                   }
               }
  @@ -148,136 +174,209 @@
       /**
        * Copies attachment references from the multipartStream to local list.
        * Done only once per object creation.
  +     *
  +     * @throws AxisFault
        */
  -     private void mergeinAttachments() throws AxisFault{
  -                if(mpartStream!=null){
  -                        Collection atts=mpartStream.getAttachments();
  -                        mpartStream=null;
  -                        setAttachmentParts(atts);
  -                }
  +    private void mergeinAttachments() throws AxisFault {
  +
  +        if (mpartStream != null) {
  +            Collection atts = mpartStream.getAttachments();
  +
  +            mpartStream = null;
  +
  +            setAttachmentParts(atts);
           }
  +    }
   
       /**
        * This method uses getAttacmentByReference() to look for attachment.
  -         * If attachment has been found, it will be removed from the list, and
  -         * returned to the user.
  +     *     If attachment has been found, it will be removed from the list, and
  +     *     returned to the user.
        * @param  The reference that referers to an attachment.
  +     *
  +     * @param reference
        * @return The part associated with the removed attachment, or null.
  +     *
  +     * @throws org.apache.axis.AxisFault
        */
  -     public Part removeAttachmentPart(String reference) throws org.apache.axis.AxisFault{
  -                mergeinAttachments();
  -                Part removedPart=getAttachmentByReference(reference);
  -                if(removedPart!=null){
  -                        attachments.remove(removedPart.getContentId());
  -                        attachments.remove(removedPart.getContentLocation());
  -                        orderedAttachments.remove(removedPart);
  -                }
  -                return removedPart;
  +    public Part removeAttachmentPart(String reference)
  +            throws org.apache.axis.AxisFault {
  +
  +        mergeinAttachments();
  +
  +        Part removedPart = getAttachmentByReference(reference);
  +
  +        if (removedPart != null) {
  +            attachments.remove(removedPart.getContentId());
  +            attachments.remove(removedPart.getContentLocation());
  +            orderedAttachments.remove(removedPart);
           }
   
  -        /**
  -         * Adds an existing attachment to this list.
  -         * Note: Passed part will be bound to this message.
  -         * @param newPart new part to add
  -         * @returns Part old attachment with the same Content-ID, or null.
  -         */
  -        public Part addAttachmentPart(Part newPart) throws org.apache.axis.AxisFault{
  -                mergeinAttachments();
  -                Part oldPart=(Part)attachments.put(newPart.getContentId(),newPart);
  -                if(oldPart!=null){
  -                        orderedAttachments.remove(oldPart);
  -                        attachments.remove(oldPart.getContentLocation());
  -                }
  -                orderedAttachments.add(newPart);
  -                if(newPart.getContentLocation()!=null){
  -                        attachments.put(newPart.getContentLocation(),newPart);
  -                }
  -                return oldPart;
  +        return removedPart;
  +    }
  +
  +    /**
  +     * Adds an existing attachment to this list.
  +     * Note: Passed part will be bound to this message.
  +     * @param newPart new part to add
  +     * @returns Part old attachment with the same Content-ID, or null.
  +     *
  +     * @return
  +     *
  +     * @throws org.apache.axis.AxisFault
  +     */
  +    public Part addAttachmentPart(Part newPart)
  +            throws org.apache.axis.AxisFault {
  +
  +        mergeinAttachments();
  +
  +        Part oldPart = (Part) attachments.put(newPart.getContentId(), newPart);
  +
  +        if (oldPart != null) {
  +            orderedAttachments.remove(oldPart);
  +            attachments.remove(oldPart.getContentLocation());
  +        }
  +
  +        orderedAttachments.add(newPart);
  +
  +        if (newPart.getContentLocation() != null) {
  +            attachments.put(newPart.getContentLocation(), newPart);
           }
   
  +        return oldPart;
  +    }
  +
       /**
        * Create an attachment part with a buried JAF data handler.
  +     *
  +     * @param datahandler
  +     *
  +     * @return
  +     *
  +     * @throws org.apache.axis.AxisFault
        */
  -    public Part createAttachmentPart(Object datahandler) 
  +    public Part createAttachmentPart(Object datahandler)
               throws org.apache.axis.AxisFault {
  -                mergeinAttachments();
  +
  +        mergeinAttachments();
  +
           if (!(datahandler instanceof javax.activation.DataHandler)) {
  -            throw new org.apache.axis.AxisFault(JavaUtils.getMessage(
  -                    "unsupportedAttach", datahandler.getClass().getName(),
  -                    javax.activation.DataHandler.class.getName()));
  +            throw new org.apache.axis.AxisFault(
  +                    JavaUtils.getMessage(
  +                            "unsupportedAttach", datahandler.getClass().getName(),
  +                            javax.activation.DataHandler.class.getName()));
           }
  -        Part ret = new AttachmentPart((javax.activation.DataHandler)datahandler);
  +
  +        Part ret =
  +                new AttachmentPart((javax.activation.DataHandler) datahandler);
  +
           addAttachmentPart(ret);
  +
           return ret;
       }
   
       /**
  -     * Add the collection of parts. 
  +     * Add the collection of parts.
  +     *
  +     * @param parts
  +     *
  +     * @throws org.apache.axis.AxisFault
        */
  -    public void setAttachmentParts(java.util.Collection parts) 
  +    public void setAttachmentParts(java.util.Collection parts)
               throws org.apache.axis.AxisFault {
  -                mergeinAttachments();
  +
  +        mergeinAttachments();
           attachments.clear();
  -                orderedAttachments.clear();
  -        if (parts != null && !parts.isEmpty()) {
  +        orderedAttachments.clear();
  +
  +        if ((parts != null) && !parts.isEmpty()) {
               for (java.util.Iterator i = parts.iterator(); i.hasNext();) {
                   Part part = (Part) i.next();
  +
                   if (null != part) {
  -                        addAttachmentPart(part);
  +                    addAttachmentPart(part);
                   }
               }
           }
       }
   
       /**
  -     * This method should look at a refernce and determine if it is a CID: or 
  +     * This method should look at a refernce and determine if it is a CID: or
        * url to look for attachment.
  -         * <br>
  -         * Note: if Content-Id or Content-Location headers have changed by outside
  -         * code, lookup will not return proper values. In order to change these
  -         * values attachment should be removed, then added again.
  +     *     <br>
  +     *     Note: if Content-Id or Content-Location headers have changed by outside
  +     *     code, lookup will not return proper values. In order to change these
  +     *     values attachment should be removed, then added again.
        * @param  The reference in the xml that referers to an attachment.
  +     *
  +     * @param reference
        * @return The part associated with the attachment.
  +     *
  +     * @throws org.apache.axis.AxisFault
        */
  -    public Part getAttachmentByReference(String reference) 
  +    public Part getAttachmentByReference(String reference)
               throws org.apache.axis.AxisFault {
  -                mergeinAttachments();
  -        if (null == reference) return null;
  +
  +        mergeinAttachments();
  +
  +        if (null == reference) {
  +            return null;
  +        }
  +
           reference = reference.trim();
  -        if (0 == reference.length()) return null;
   
  -                Part ret = (Part) attachments.get(reference);
  -                if(ret!=null)
  -                        return ret;
  +        if (0 == reference.length()) {
  +            return null;
  +        }
  +
  +        Part ret = (Part) attachments.get(reference);
  +
  +        if (ret != null) {
  +            return ret;
  +        }
   
           String referenceLC = reference.toLowerCase();
  -        if (!referenceLC.startsWith("cid:") && null != contentLocation) {
  +
  +        if (!referenceLC.startsWith("cid:") && (null != contentLocation)) {
               String fqreference = contentLocation;
  -            if (!fqreference.endsWith("/")) fqreference += "/";
  -            if (reference.startsWith("/"))
  +
  +            if (!fqreference.endsWith("/")) {
  +                fqreference += "/";
  +            }
  +
  +            if (reference.startsWith("/")) {
                   fqreference += reference.substring(1);
  -            else
  +            } else {
                   fqreference += reference;
  -                        //lets see if we can get it as Content-Location
  -                        ret = (AttachmentPart) attachments.get(fqreference);
  +            }
  +
  +            // lets see if we can get it as Content-Location
  +            ret = (AttachmentPart) attachments.get(fqreference);
           }
  +
           return ret;
       }
   
       /**
  -     * This method will return all attachments as a collection. 
  -     * 
  -     * @return A collection of attachments. 
  +     * This method will return all attachments as a collection.
  +     *
  +     * @return A collection of attachments.
  +     *
  +     * @throws org.apache.axis.AxisFault
        */
  -    public java.util.Collection getAttachments() 
  +    public java.util.Collection getAttachments()
               throws org.apache.axis.AxisFault {
  -                mergeinAttachments();
  -                return new LinkedList(orderedAttachments);
  -        }
  +
  +        mergeinAttachments();
  +
  +        return new LinkedList(orderedAttachments);
  +    }
   
       /**
  -     * From the complex stream return the root part. 
  +     * From the complex stream return the root part.
        * Today this is SOAP.
  +     *
  +     * @return
        */
       public Part getRootPart() {
           return soapPart;
  @@ -285,83 +384,122 @@
   
       /**
        * Sets the root part of this multipart block
  +     *
  +     * @param newRoot
        */
  -    public void setRootPart(Part newRoot){
  +    public void setRootPart(Part newRoot) {
  +
           try {
  -            this.soapPart=(SOAPPart)newRoot;
  -        } catch(ClassCastException e) {
  +            this.soapPart = (SOAPPart) newRoot;
  +        } catch (ClassCastException e) {
               throw new ClassCastException(JavaUtils.getMessage("onlySOAPParts"));
           }
       }
   
  -
  +    /** Field multipart           */
       public javax.mail.internet.MimeMultipart multipart = null;
   
       /**
  -     * Get the content length of the stream. 
  +     * Get the content length of the stream.
  +     *
  +     * @return
  +     *
  +     * @throws org.apache.axis.AxisFault
        */
       public int getContentLength() throws org.apache.axis.AxisFault {
  -                mergeinAttachments();
  +
  +        mergeinAttachments();
  +
           try {
  -            return (int)org.apache.axis.attachments.MimeUtils.getContentLength(
  -                              multipart != null ? multipart : (multipart = org.apache.axis.attachments.MimeUtils.createMP(soapPart.getAsString(), orderedAttachments)));
  +            return (int) org.apache.axis.attachments.MimeUtils.getContentLength(
  +                    (multipart != null)
  +                    ? multipart
  +                    : (multipart = org.apache.axis.attachments.MimeUtils.createMP(
  +                            soapPart.getAsString(), orderedAttachments)));
           } catch (Exception e) {
               throw AxisFault.makeFault(e);
           }
       }
   
       /**
  -     * Write the content to the stream. 
  +     * Write the content to the stream.
  +     *
  +     * @param os
  +     *
  +     * @throws org.apache.axis.AxisFault
        */
  -    public void writeContentToStream(java.io.OutputStream os) 
  +    public void writeContentToStream(java.io.OutputStream os)
               throws org.apache.axis.AxisFault {
  -                mergeinAttachments();
  -        org.apache.axis.attachments.MimeUtils.writeToMultiPartStream(os, multipart != null ? multipart :
  -                                                                         (multipart = org.apache.axis.attachments.MimeUtils.createMP(soapPart.getAsString(), orderedAttachments)));
  -        for( java.util.Iterator i= orderedAttachments.iterator(); i.hasNext(); ){
  -          AttachmentPart part= (AttachmentPart)i.next();
  -              DataHandler dh= AttachmentUtils.getActivationDataHandler(part);
  -              DataSource ds= dh.getDataSource();
  -              if( ds != null && ds instanceof ManagedMemoryDataSource ){
  -                  ((ManagedMemoryDataSource) ds).delete();
  -              }
  +
  +        mergeinAttachments();
  +        org.apache.axis.attachments.MimeUtils.writeToMultiPartStream(os,
  +                (multipart != null)
  +                ? multipart
  +                : (multipart = org.apache.axis.attachments.MimeUtils.createMP(
  +                        soapPart.getAsString(), orderedAttachments)));
  +
  +        for (java.util.Iterator i = orderedAttachments.iterator();
  +             i.hasNext();) {
  +            AttachmentPart part = (AttachmentPart) i.next();
  +            DataHandler dh =
  +                    AttachmentUtils.getActivationDataHandler(part);
  +            DataSource ds = dh.getDataSource();
  +
  +            if ((ds != null) && (ds instanceof ManagedMemoryDataSource)) {
  +                ((ManagedMemoryDataSource) ds).delete();
  +            }
           }
       }
   
       /**
        * Gets the content type for the whole stream.
  +     *
  +     * @return
  +     *
  +     * @throws org.apache.axis.AxisFault
        */
       public String getContentType() throws org.apache.axis.AxisFault {
  -                mergeinAttachments();
  -        return org.apache.axis.attachments.MimeUtils.getContentType(multipart != null ? multipart :
  -                (multipart = org.apache.axis.attachments.MimeUtils.createMP(soapPart.getAsString(), orderedAttachments)));
  +
  +        mergeinAttachments();
  +
  +        return org.apache.axis.attachments.MimeUtils.getContentType((multipart
  +                != null)
  +                ? multipart
  +                : (multipart =
  +                org.apache.axis.attachments.MimeUtils.createMP(
  +                        soapPart.getAsString(),
  +                        orderedAttachments)));
       }
   
       /**
  -     *This is the number of attachments.
  -     **/
  +     * This is the number of attachments.
  +     *
  +     * @return
  +     */
       public int getAttachmentCount() {
  -                try{
  -                        mergeinAttachments();
  -                return orderedAttachments.size();
  -                }catch(AxisFault e){}
  -                return 0;
  +
  +        try {
  +            mergeinAttachments();
  +
  +            return orderedAttachments.size();
  +        } catch (AxisFault e) {
  +        }
  +
  +        return 0;
       }
   
       /**
  -     * Determine if an object is to be treated as an attchment. 
  +     * Determine if an object is to be treated as an attchment.
        *
        * @param value the value that is to be determined if
        * its an attachment.
        *
  -     * @return True if value should be treated as an attchment. 
  +     * @return True if value should be treated as an attchment.
        */
  -
       public boolean isAttachment(Object value) {
           return AttachmentUtils.isAttachment(value);
       }
   
  -
       /**
        * Removes all <CODE>AttachmentPart</CODE> objects that have
        *   been added to this <CODE>SOAPMessage</CODE> object.
  @@ -369,7 +507,8 @@
        *   <P>This method does not touch the SOAP part.</P>
        */
       public void removeAllAttachments() {
  -        //TODO: Flesh it out.
  +
  +        // TODO: Flesh it out.
       }
   
       /**
  @@ -383,14 +522,20 @@
        * @return an iterator over all attachments that have a header
        *     that matches one of the given headers
        */
  -    public java.util.Iterator getAttachments(javax.xml.soap.MimeHeaders headers) {
  -        //TODO: Flesh it out.
  +    public java.util.Iterator getAttachments(
  +            javax.xml.soap.MimeHeaders headers) {
  +
  +        // TODO: Flesh it out.
           return null;
       }
   
       /**
        * Create a new attachment Part in this Message.
        * Will actually, and always, return an AttachmentPart.
  +     *
  +     * @return
  +     *
  +     * @throws org.apache.axis.AxisFault
        */
       public Part createAttachmentPart() throws org.apache.axis.AxisFault {
           return new AttachmentPart();
  
  
  
  1.12      +387 -204  xml-axis/java/src/org/apache/axis/attachments/BoundaryDelimitedStream.java
  
  Index: BoundaryDelimitedStream.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/attachments/BoundaryDelimitedStream.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- BoundaryDelimitedStream.java	29 Apr 2002 19:41:17 -0000	1.11
  +++ BoundaryDelimitedStream.java	24 Jun 2002 12:34:51 -0000	1.12
  @@ -52,52 +52,84 @@
    * information on the Apache Software Foundation, please see
    * <http://www.apache.org/>.
    */
  -
   package org.apache.axis.attachments;
  -import java.lang.ref.WeakReference;
  -
   
   import org.apache.axis.utils.JavaUtils;
  -
   import org.apache.commons.logging.Log;
   import org.apache.commons.logging.LogFactory;
   
   /**
  - * @author Rick Rineholt 
  + * This class takes the input stream and turns it multiple streams.
  + *
  + * @author Rick Rineholt
    */
  +public class BoundaryDelimitedStream extends java.io.FilterInputStream {
   
  - /**
  -  * This class takes the input stream and turns it multiple streams. 
  -  */
  -public class BoundaryDelimitedStream extends java.io.FilterInputStream
  -{
  +    /** Field log           */
       protected static Log log =
  -        LogFactory.getLog(BoundaryDelimitedStream.class.getName());
  +            LogFactory.getLog(BoundaryDelimitedStream.class.getName());
   
  +    /** Field boundary           */
       protected byte[] boundary = null;
  -    int boundaryLen = 0;  //The boundary length.
  -    int boundaryBufLen = 0; //The boundary length plus crlf. 
  -    java.io.InputStream is = null; //The source input stream.
  -    boolean closed = true; //The stream has been closed.
  -    boolean eos = false;  //eof has been detected.
  -    boolean theEnd = false; //There are no more streams left.
  -
  -    int readbufsz = 0; //Minimum to read at one time.
  -    byte[] readbuf = null; //The buffer we are reading.
  -    int readBufPos = 0;  //Where we have read so far in the stream.
  -    int readBufEnd = 0;  //The number of bytes in array.
  +
  +    /** Field boundaryLen           */
  +    int boundaryLen = 0;              // The boundary length.
  +
  +    /** Field boundaryBufLen           */
  +    int boundaryBufLen = 0;           // The boundary length plus crlf.
  +
  +    /** Field is           */
  +    java.io.InputStream is = null;    // The source input stream.
  +
  +    /** Field closed           */
  +    boolean closed = true;            // The stream has been closed.
  +
  +    /** Field eos           */
  +    boolean eos = false;              // eof has been detected.
  +
  +    /** Field theEnd           */
  +    boolean theEnd = false;           // There are no more streams left.
  +
  +    /** Field readbufsz           */
  +    int readbufsz = 0;                // Minimum to read at one time.
  +
  +    /** Field readbuf           */
  +    byte[] readbuf = null;            // The buffer we are reading.
  +
  +    /** Field readBufPos           */
  +    int readBufPos = 0;               // Where we have read so far in the stream.
  +
  +    /** Field readBufEnd           */
  +    int readBufEnd = 0;               // The number of bytes in array.
  +
  +    /** Field BOUNDARY_NOT_FOUND           */
       protected static final int BOUNDARY_NOT_FOUND = Integer.MAX_VALUE;
  -                                   // Where in the stream a boundary is located.
  +
  +    // Where in the stream a boundary is located.
  +
  +    /** Field boundaryPos           */
       int boundaryPos = BOUNDARY_NOT_FOUND;
   
  -    static int streamCount= 0; //number of streams produced.
  -    protected synchronized static int newStreamNo(){
  -     log.debug(JavaUtils.getMessage("streamNo", "" + (streamCount + 1)));
  +    /** Field streamCount           */
  +    static int streamCount = 0;       // number of streams produced.
  +
  +    /**
  +     * Method newStreamNo
  +     *
  +     * @return
  +     */
  +    protected synchronized static int newStreamNo() {
  +
  +        log.debug(JavaUtils.getMessage("streamNo", "" + (streamCount + 1)));
  +
           return ++streamCount;
       }
  -    protected int streamNo=-1; //Keeps track of stream
   
  -    static boolean isDebugEnabled= false;
  +    /** Field streamNo           */
  +    protected int streamNo = -1;    // Keeps track of stream
  +
  +    /** Field isDebugEnabled           */
  +    static boolean isDebugEnabled = false;
   
       /**
        * Gets the next stream. From the previous using the same buffer size to read.
  @@ -109,183 +141,268 @@
   
       /**
        * Gets the next stream. From the previous using  new buffer reading size.
  +     *
  +     * @param readbufsz
        * @return the boundary delmited stream. Null if there are no more streams.
        */
  -    protected synchronized BoundaryDelimitedStream getNextStream(int readbufsz) {
  +    protected synchronized BoundaryDelimitedStream getNextStream(
  +            int readbufsz) {
  +
           BoundaryDelimitedStream ret = null;
   
  -        if ( !theEnd ) {
  -          //Create an new boundary stream  that comes after this one.
  +        if (!theEnd) {
  +
  +            // Create an new boundary stream  that comes after this one.
               ret = new BoundaryDelimitedStream(this, readbufsz);
           }
  +
           return ret;
       }
  +
       /**
  -      * Constructor to create the next stream from the previous one.
  -      */
  +     *  Constructor to create the next stream from the previous one.
  +     *
  +     * @param prev
  +     * @param readbufsz
  +     */
       protected BoundaryDelimitedStream(BoundaryDelimitedStream prev,
  -      int readbufsz ) {
  -        super (null);
  +                                      int readbufsz) {
   
  -        streamNo= newStreamNo();
  +        super(null);
   
  +        streamNo = newStreamNo();
           boundary = prev.boundary;
           boundaryLen = prev.boundaryLen;
           boundaryBufLen = prev.boundaryBufLen;
  -        skip= prev.skip;
  +        skip = prev.skip;
           is = prev.is;
  -        closed = false; //The new one is not closed.
  -        eos = false;  //Its not at th EOS.
  +        closed = false;    // The new one is not closed.
  +        eos = false;    // Its not at th EOS.
           readbufsz = prev.readbufsz;
           readbuf = prev.readbuf;
  -        //Move past the old boundary.
  -        readBufPos = prev.readBufPos + boundaryBufLen; 
  +
  +        // Move past the old boundary.
  +        readBufPos = prev.readBufPos + boundaryBufLen;
           readBufEnd = prev.readBufEnd;
  -        //find the new boundary.
  -        boundaryPos = boundaryPosition( readbuf, readBufPos, readBufEnd);
  -        prev.theEnd = theEnd; //The stream.
  +
  +        // find the new boundary.
  +        boundaryPos = boundaryPosition(readbuf, readBufPos, readBufEnd);
  +        prev.theEnd = theEnd;      // The stream.
       }
   
       /**
        * Create a new boundary stream;
  +     *
  +     * @param is
        * @param boundary is the boundary that separates the individual streams.
        * @param readbufsz lets you have some control over the amount of buffering.
        *   by buffering you can some effiency in searching.
  +     *
  +     * @throws org.apache.axis.AxisFault
        */
  -     BoundaryDelimitedStream( java.io.InputStream is, byte[] boundary,
  -      int readbufsz) throws org.apache.axis.AxisFault {
  +    BoundaryDelimitedStream(
  +            java.io.InputStream is, byte[] boundary, int readbufsz)
  +            throws org.apache.axis.AxisFault {
  +
           // super (is);
  -         super(null); //we handle everything so this is not necessary, don't won't to hang on to a reference.
  -        isDebugEnabled= log.isDebugEnabled();
  -        streamNo= newStreamNo();
  +        super(null);    // we handle everything so this is not necessary, don't won't to hang on to a reference.
  +
  +        isDebugEnabled = log.isDebugEnabled();
  +        streamNo = newStreamNo();
           closed = false;
  -        this.is =  is;
  -        //Copy the boundary array to make certain it is never altered.
  -        this.boundary= new byte[boundary.length];
  -        System.arraycopy(boundary,0,this.boundary,0, boundary.length);
  +        this.is = is;
  +
  +        // Copy the boundary array to make certain it is never altered.
  +        this.boundary = new byte[boundary.length];
  +
  +        System.arraycopy(boundary, 0, this.boundary, 0, boundary.length);
  +
           this.boundaryLen = this.boundary.length;
           this.boundaryBufLen = boundaryLen + 2;
  -          //allways leave room for at least a 2x boundary
  -          //Most mime boundaries are 40 bytes or so.
  -        this.readbufsz = Math.max( (boundaryBufLen) * 2, readbufsz); 
  -    }
  -
  -    private final int readFromStream( final byte[] b) throws java.io.IOException{
  -       return readFromStream(b, 0, b.length);
  -    }
  -    private final int readFromStream( final byte[] b, final int start, final int length) throws java.io.IOException{
  -            int minRead= Math.max(boundaryBufLen *2, length); 
  -            minRead= Math.min(minRead, length-start); 
  -            int br= 0;
  -            int brTotal=0;
  -            do
  -            {
  -              br= is.read(b, brTotal + start, length - brTotal);
  -              if(br > 0) brTotal+= br;
  -            }while(br > -1 && brTotal < minRead);
   
  -            return brTotal != 0?  brTotal : br;
  +        // allways leave room for at least a 2x boundary
  +        // Most mime boundaries are 40 bytes or so.
  +        this.readbufsz = Math.max((boundaryBufLen) * 2, readbufsz);
  +    }
  +
  +    /**
  +     * Method readFromStream
  +     *
  +     * @param b
  +     *
  +     * @return
  +     *
  +     * @throws java.io.IOException
  +     */
  +    private final int readFromStream(final byte[] b)
  +            throws java.io.IOException {
  +        return readFromStream(b, 0, b.length);
       }
  -     
  +
  +    /**
  +     * Method readFromStream
  +     *
  +     * @param b
  +     * @param start
  +     * @param length
  +     *
  +     * @return
  +     *
  +     * @throws java.io.IOException
  +     */
  +    private final int readFromStream(
  +            final byte[] b, final int start, final int length)
  +            throws java.io.IOException {
  +
  +        int minRead = Math.max(boundaryBufLen * 2, length);
  +
  +        minRead = Math.min(minRead, length - start);
  +
  +        int br = 0;
  +        int brTotal = 0;
  +
  +        do {
  +            br = is.read(b, brTotal + start, length - brTotal);
  +
  +            if (br > 0) {
  +                brTotal += br;
  +            }
  +        } while ((br > -1) && (brTotal < minRead));
  +
  +        return (brTotal != 0)
  +                ? brTotal
  +                : br;
  +    }
  +
       /**
        * Read from the boundary delimited stream.
        * @param b is the array to read into.
  -     * @param off is the offset 
  +     * @param off is the offset
  +     * @param len
        * @return the number of bytes read. -1 if endof stream.
  +     *
  +     * @throws java.io.IOException
        */
  -
       public synchronized int read(byte[] b, final int off, final int len)
  -                                                throws java.io.IOException {
  +            throws java.io.IOException {
  +
           if (closed) {
               throw new java.io.IOException(JavaUtils.getMessage("streamClosed"));
           }
  +
           if (eos) {
               return -1;
           }
   
  -        if (readbuf == null) { //Allocate the buffer.
  -            readbuf = new byte[Math.max(len, readbufsz ) ];
  +        if (readbuf == null) {    // Allocate the buffer.
  +            readbuf = new byte[Math.max(len, readbufsz)];
               readBufEnd = readFromStream(readbuf);
  -            if( readBufEnd < 0) {
  -                readbuf= null;
  -                closed= true;
  +
  +            if (readBufEnd < 0) {
  +                readbuf = null;
  +                closed = true;
                   theEnd = true;
  +
                   throw new java.io.IOException(
                           JavaUtils.getMessage("eosBeforeMarker"));
               }
  +
               readBufPos = 0;
  -                                                       //Finds the boundary pos.
  -            boundaryPos = boundaryPosition( readbuf, 0, readBufEnd);
  +
  +            // Finds the boundary pos.
  +            boundaryPos = boundaryPosition(readbuf, 0, readBufEnd);
           }
  -        int bwritten = 0; //Number of bytes written.
   
  -         //read and copy bytes in.
  -        do {    //Always allow to have a boundary length left in the buffer.
  +        int bwritten = 0;    // Number of bytes written.
  +
  +        // read and copy bytes in.
  +        do {                                // Always allow to have a boundary length left in the buffer.
               int bcopy = Math.min(readBufEnd - readBufPos - boundaryBufLen,
  -              len - bwritten);
  -                                                   //never go past the boundary.
  -            bcopy = Math.min(bcopy, boundaryPos - readBufPos); 
  +                    len - bwritten);
  +
  +            // never go past the boundary.
  +            bcopy = Math.min(bcopy, boundaryPos - readBufPos);
   
               if (bcopy > 0) {
                   System.arraycopy(readbuf, readBufPos, b, off + bwritten, bcopy);
  +
                   bwritten += bcopy;
                   readBufPos += bcopy;
               }
  +
               if (readBufPos == boundaryPos) {
  -                eos = true; //hit the boundary so it the end of the stream.
  +                eos = true;                 // hit the boundary so it the end of the stream.
  +
                   log.debug(JavaUtils.getMessage("atEOS", "" + streamNo));
  -            }
  -            else if ( bwritten < len) { //need to get more data.
  -                byte[]dstbuf = readbuf;
  +            } else if (bwritten < len) {    // need to get more data.
  +                byte[] dstbuf = readbuf;
  +
  +                if (readbuf.length < len) {
  +                    dstbuf = new byte[len];
  +                }
   
  -                if ( readbuf.length < len) dstbuf = new byte[len];
                   int movecnt = readBufEnd - readBufPos;
   
  -                //copy what was left over.
  +                // copy what was left over.
                   System.arraycopy(readbuf, readBufPos, dstbuf, 0, movecnt);
  -                //Read in the new data.
  -                int readcnt = readFromStream(dstbuf, movecnt, dstbuf.length - movecnt);
  -                
  -                if( readcnt < 0) {
  -                    readbuf= null;
  -                    closed= true;
  +
  +                // Read in the new data.
  +                int readcnt = readFromStream(dstbuf, movecnt,
  +                        dstbuf.length - movecnt);
  +
  +                if (readcnt < 0) {
  +                    readbuf = null;
  +                    closed = true;
                       theEnd = true;
  +
                       throw new java.io.IOException(
                               JavaUtils.getMessage("eosBeforeMarker"));
                   }
   
                   readBufEnd = readcnt + movecnt;
                   readbuf = dstbuf;
  -                readBufPos = 0; //start at the begining.
  -                                      //just move the boundary by what we moved
  -                if (BOUNDARY_NOT_FOUND != boundaryPos ) boundaryPos -= movecnt;
  -                else boundaryPos = boundaryPosition( readbuf, readBufPos,
  -                                 readBufEnd); //See if the boundary is now there.
  -            }
  +                readBufPos = 0;             // start at the begining.
   
  +                // just move the boundary by what we moved
  +                if (BOUNDARY_NOT_FOUND != boundaryPos) {
  +                    boundaryPos -= movecnt;
  +                } else {
  +                    boundaryPos = boundaryPosition(
  +                            readbuf, readBufPos,
  +                            readBufEnd);        // See if the boundary is now there.
  +                }
  +            }
           }
  -        //read till we get the amount or the stream is finished.
  -        while ( !eos && bwritten < len );
   
  -        if ( log.isDebugEnabled()) {
  -            if (bwritten  > 0) {
  +                // read till we get the amount or the stream is finished.
  +        while (!eos && (bwritten < len));
  +
  +        if (log.isDebugEnabled()) {
  +            if (bwritten > 0) {
                   byte tb[] = new byte[bwritten];
   
                   System.arraycopy(b, off, tb, 0, bwritten);
  -                log.debug(JavaUtils.getMessage("readBStream", new String[]
  -                        {"" + bwritten, "" + streamNo, new String(tb)}));
  +                log.debug(JavaUtils.getMessage("readBStream",
  +                        new String[]{"" + bwritten,
  +                                     "" + streamNo,
  +                                     new String(tb)}));
               }
           }
  -        if(eos && theEnd)readbuf= null; //dealloc even in Java.  
  +
  +        if (eos && theEnd) {
  +            readbuf = null;    // dealloc even in Java.
  +        }
   
           return bwritten;
       }
   
       /**
        * Read from the boundary delimited stream.
  -     * @param b is the array to read into. Read as much as possible 
  +     * @param b is the array to read into. Read as much as possible
        *   into the size of this array.
        * @return the number of bytes read. -1 if endof stream.
  +     *
  +     * @throws java.io.IOException
        */
       public int read(byte[] b) throws java.io.IOException {
           return read(b, 0, b.length);
  @@ -294,149 +411,215 @@
       /**
        * Read from the boundary delimited stream.
        * @return The byte read, or -1 if endof stream.
  +     *
  +     * @throws java.io.IOException
        */
  -
       public int read() throws java.io.IOException {
  -        byte[] b = new byte[1];  //quick and dirty. //for now
  +
  +        byte[] b = new byte[1];    // quick and dirty. //for now
           int read = read(b);
   
  -        if ( read < 0 ) return -1;
  -        else return b[0];
  +        if (read < 0) {
  +            return -1;
  +        } else {
  +            return b[0];
  +        }
       }
   
       /**
        * Closes the stream.
  +     *
  +     * @throws java.io.IOException
        */
       public synchronized void close() throws java.io.IOException {
  -        if (closed) return;
  +
  +        if (closed) {
  +            return;
  +        }
  +
           log.debug(JavaUtils.getMessage("bStreamClosed", "" + streamNo));
  -        closed = true; //mark it closed.
  -        if (!eos) { //We need get this off the stream.
  -                                //Easy way to flush through the stream;
  +
  +        closed = true;    // mark it closed.
  +
  +        if (!eos) {    // We need get this off the stream.
  +
  +            // Easy way to flush through the stream;
               byte[] readrest = new byte[1024 * 16];
               int bread = 0;
   
               do {
                   bread = read(readrest);
  -            }
  -            while ( bread > -1 );
  -
  +            } while (bread > -1);
           }
       }
  +
       /**
        * mark the stream.
        * This is not supported.
  +     *
  +     * @param readlimit
        */
  -    public void mark( int readlimit){
  -    //do nothing
  +    public void mark(int readlimit) {
  +
  +        // do nothing
       }
   
       /**
        * reset the stream.
        * This is not supported.
  +     *
  +     * @throws java.io.IOException
        */
  -    public void reset() throws java.io.IOException{
  -      throw new java.io.IOException(JavaUtils.getMessage("attach.bounday.mns"));
  +    public void reset() throws java.io.IOException {
  +        throw new java.io.IOException(
  +                JavaUtils.getMessage("attach.bounday.mns"));
       }
   
       /**
        * markSupported
  -     * return false; 
  +     * return false;
  +     *
  +     * @return
        */
  -    public boolean markSupported(){
  -      return false;
  +    public boolean markSupported() {
  +        return false;
       }
   
  -    public int available() throws java.io.IOException{
  -      int bcopy = readBufEnd - readBufPos - boundaryBufLen;
  -                             //never go past the boundary.
  -      bcopy = Math.min(bcopy, boundaryPos - readBufPos); 
  -      return Math.max(0,bcopy);
  -    }
  +    /**
  +     * Method available
  +     *
  +     * @return
  +     *
  +     * @throws java.io.IOException
  +     */
  +    public int available() throws java.io.IOException {
  +
  +        int bcopy = readBufEnd - readBufPos - boundaryBufLen;
   
  +        // never go past the boundary.
  +        bcopy = Math.min(bcopy, boundaryPos - readBufPos);
  +
  +        return Math.max(0, bcopy);
  +    }
   
       /**
        * Read from the boundary delimited stream.
  +     *
  +     * @param searchbuf
  +     * @param start
  +     * @param end
        * @return The position of the boundary. Detects the end of the source stream.
  -     * 
  +     *
        */
  -    protected int boundaryPosition( byte[] searchbuf, int start, int end) {
  +    protected int boundaryPosition(byte[] searchbuf, int start, int end) {
  +
           int foundAt = boundarySearch(searchbuf, start, end);
  -                                               //First find the boundary marker
   
  -        if (BOUNDARY_NOT_FOUND != foundAt) { //Something was found.
  -           if(foundAt + boundaryLen +2 > end) foundAt= BOUNDARY_NOT_FOUND;
  -           else{
  -              //If the marker has a "--" at the end then this is the last boundary.
  -              if ( searchbuf[foundAt + boundaryLen] == '-' && 
  -                                  searchbuf[foundAt + boundaryLen + 1 ] == '-' ) {
  -                  theEnd = true;
  -              }
  -              else if ( searchbuf[foundAt + boundaryLen] != 13 ||
  -                                    searchbuf[foundAt + boundaryLen + 1 ] != 10 ) {
  -             //If there really was no crlf at then end then this is not a boundary.
  -                  foundAt = BOUNDARY_NOT_FOUND;
  -              }
  -           }
  +        // First find the boundary marker
  +        if (BOUNDARY_NOT_FOUND != foundAt) {    // Something was found.
  +            if (foundAt + boundaryLen + 2 > end) {
  +                foundAt = BOUNDARY_NOT_FOUND;
  +            } else {
  +
  +                // If the marker has a "--" at the end then this is the last boundary.
  +                if ((searchbuf[foundAt + boundaryLen] == '-')
  +                        && (searchbuf[foundAt + boundaryLen + 1] == '-')) {
  +                    theEnd = true;
  +                } else if ((searchbuf[foundAt + boundaryLen] != 13)
  +                        || (searchbuf[foundAt + boundaryLen + 1] != 10)) {
  +
  +                    // If there really was no crlf at then end then this is not a boundary.
  +                    foundAt = BOUNDARY_NOT_FOUND;
  +                }
  +            }
           }
  +
           return foundAt;
       }
   
  -  /* The below uses a standard textbook Boyer-Moore pattern search.*/
  -   
  +    /* The below uses a standard textbook Boyer-Moore pattern search. */
  +
  +    /** Field skip           */
  +    private int[] skip = null;
  +
  +    /**
  +     * Method boundarySearch
  +     *
  +     * @param text
  +     * @param start
  +     * @param end
  +     *
  +     * @return
  +     */
  +    private int boundarySearch(final byte[] text, final int start,
  +                               final int end) {
  +
  +        // log.debug(">>>>" + start + "," + end);
  +        int i = 0, j = 0, k = 0;
  +
  +        if (boundaryLen > (end - start)) {
  +            return BOUNDARY_NOT_FOUND;
  +        }
  +
  +        if (null == skip) {
  +            skip = new int[256];
  +
  +            java.util.Arrays.fill(skip, boundaryLen);
  +
  +            for (k = 0; k < boundaryLen - 1; k++) {
  +                skip[boundary[k]] = boundaryLen - k - 1;
  +            }
  +        }
   
  -   private int[] skip= null;
  -   private int boundarySearch(final byte[]text,final int start, final int end ) {
  -//log.debug(">>>>" + start + "," + end);   
  -
  -       int i=0, j=0, k=0;
  -       if(boundaryLen > (end - start)) return BOUNDARY_NOT_FOUND;
  -      
  -       if(null == skip){
  -           skip= new int[256];
  -           java.util.Arrays.fill(skip, boundaryLen);   
  -           for( k=0; k<boundaryLen-1; k++ ) skip[boundary[k]] = boundaryLen-k-1;
  -       }
  -
  -
  -       for( k=start + boundaryLen-1; k <end; k += skip[text[k] & (0xff)] ) {
  -// log.debug(">>>>" + k);   
  -//printarry(text, k-boundaryLen+1, end);
  -            try{
  -            for( j=boundaryLen-1, i=k; j>=0 && text[i] == boundary[j]; j-- ) i--;
  -            }catch(ArrayIndexOutOfBoundsException e){
  -              System.
  -              err.println(">>>" +e); //rr temporary till a boundary issue is resolved.
  -              System.
  -              err.println("start=" +start);
  -              System.
  -              err.println("k=" +k);
  -              System.
  -              err.println("text.length=" + text.length );
  -              System.
  -              err.println("i=" + i );
  -              System.
  -              err.println("boundary.length=" + boundary.length );
  -              System.
  -              err.println("j=" + j );
  -              System.
  -              err.println("end=" + end );
  -              throw e;
  +        for (k = start + boundaryLen - 1; k < end;
  +             k += skip[text[k] & (0xff)]) {
   
  +            // log.debug(">>>>" + k);
  +            // printarry(text, k-boundaryLen+1, end);
  +            try {
  +                for (j = boundaryLen - 1, i = k;
  +                     (j >= 0) && (text[i] == boundary[j]); j--) {
  +                    i--;
  +                }
  +            } catch (ArrayIndexOutOfBoundsException e) {
  +                StringBuffer sb = new StringBuffer();
  +                sb.append(
  +                        ">>>"
  +                        + e);    // rr temporary till a boundary issue is resolved.
  +                sb.append("start=" + start);
  +                sb.append("k=" + k);
  +                sb.append("text.length=" + text.length);
  +                sb.append("i=" + i);
  +                sb.append("boundary.length=" + boundary.length);
  +                sb.append("j=" + j);
  +                sb.append("end=" + end);
  +                log.warn(JavaUtils.getMessage("exception01",sb.toString()));
  +                throw e;
               }
  -            if( j == (-1) ) return i+1;
  -       }
   
  -// log.debug(">>>> not found" );   
  -       return BOUNDARY_NOT_FOUND;
  -   }
  +            if (j == (-1)) {
  +                return i + 1;
  +            }
  +        }
  +
  +        // log.debug(">>>> not found" );
  +        return BOUNDARY_NOT_FOUND;
  +    }
  +
  +    /**
  +     * Method printarry
  +     *
  +     * @param b
  +     * @param start
  +     * @param end
  +     */
  +    public static void printarry(byte[] b, int start, int end) {
   
  -    public static void printarry(byte[] b, int start , int end){
           if (log.isDebugEnabled()) {
  -            byte tb[] = new byte[end-start];
  -            System.arraycopy(b, start, tb, 0, end-start);
  +            byte tb[] = new byte[end - start];
  +
  +            System.arraycopy(b, start, tb, 0, end - start);
               log.debug("\"" + new String(tb) + "\"");
           }
       }
  -
   }
  
  
  
  1.13      +498 -247  xml-axis/java/src/org/apache/axis/attachments/ManagedMemoryDataSource.java
  
  Index: ManagedMemoryDataSource.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/attachments/ManagedMemoryDataSource.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- ManagedMemoryDataSource.java	15 Mar 2002 01:14:10 -0000	1.12
  +++ ManagedMemoryDataSource.java	24 Jun 2002 12:34:51 -0000	1.13
  @@ -52,106 +52,139 @@
    * information on the Apache Software Foundation, please see
    * <http://www.apache.org/>.
    */
  -
   package org.apache.axis.attachments;
   
   import org.apache.axis.InternalException;
  -import org.apache.axis.MessageContext; 
  +import org.apache.axis.MessageContext;
   import org.apache.axis.utils.JavaUtils;
  -
   import org.apache.commons.logging.Log;
   import org.apache.commons.logging.LogFactory;
   
  -import java.io.File; 
  -
  -/**
  - * @author Rick Rineholt 
  - */
  +import java.io.File;
   
   /**
    * This class allows small attachments to be cached in memory, while large ones are
    * cached out.  It implements a Java Activiation Data source interface.
    * TODO TODO TODO need to delete cached out data sources after a service ends.
  + *
  + * @author Rick Rineholt
    */
  +public class ManagedMemoryDataSource implements javax.activation.DataSource {
   
  -public class ManagedMemoryDataSource implements  javax.activation.DataSource
  -{
  +    /** Field log           */
       protected static Log log =
  -        LogFactory.getLog(ManagedMemoryDataSource.class.getName());
  +            LogFactory.getLog(ManagedMemoryDataSource.class.getName());
  +
  +    /** Field contentType           */
  +    protected String contentType = "application/octet-stream";    // Is the default.
  +
  +    /** Field ss           */
  +    java.io.InputStream ss = null;             // The incoming source stream.
   
  -    protected String contentType = "application/octet-stream"; //Is the default.
  -    java.io.InputStream ss = null; //The incoming source stream.
  -    public static final  int MAX_MEMORY_DISK_CACHED = -1;
  -    protected int maxCached = 16  * 1024;  //max in memory cached. Default.
  -                                        //If set the file the disk is cached to.
  -    protected java.io.File diskCacheFile = null; 
  +    /** Field MAX_MEMORY_DISK_CACHED           */
  +    public static final int MAX_MEMORY_DISK_CACHED = -1;
   
  -   //A list of open input Streams.
  +    /** Field maxCached           */
  +    protected int maxCached = 16 * 1024;       // max in memory cached. Default.
  +
  +    // If set the file the disk is cached to.
  +
  +    /** Field diskCacheFile           */
  +    protected java.io.File diskCacheFile = null;
  +
  +    // A list of open input Streams.
  +
  +    /** Field readers           */
       protected java.util.WeakHashMap readers = new java.util.WeakHashMap();
  -    protected boolean deleted = false; //The resources behind this have been deleted.
  -    
  -                             //Memory is allocated in these size chunks.
  -    public static final int READ_CHUNK_SZ = 32 * 1024 ;
   
  -    protected boolean debugEnabled= false; //Log debugging if true.        
  +    /** Field deleted           */
  +    protected boolean deleted =
  +            false;                                 // The resources behind this have been deleted.
  +
  +    // Memory is allocated in these size chunks.
  +
  +    /** Field READ_CHUNK_SZ           */
  +    public static final int READ_CHUNK_SZ = 32 * 1024;
   
  -    //Should not be called; 
  -    protected ManagedMemoryDataSource () {
  +    /** Field debugEnabled           */
  +    protected boolean debugEnabled = false;    // Log debugging if true.
  +
  +    // Should not be called;
  +
  +    /**
  +     * Constructor ManagedMemoryDataSource
  +     */
  +    protected ManagedMemoryDataSource() {
       }
   
       /**
        * Create a new boundary stream;
  -     * @param ss is the source input stream that is used to create this data source.. 
  +     * @param ss is the source input stream that is used to create this data source..
        * @param readbufsz lets you have some control over the amount of buffering.
        * @param maxCached  This is the max memory that is to be used to cache the data.
        * @param contentType the mime type for this data stream.
        *   by buffering you can some effiency in searching.
  +     *
  +     * @throws java.io.IOException
        */
  -    public ManagedMemoryDataSource(java.io.InputStream ss, int maxCached,
  -                               String contentType) throws java.io.IOException {
  -        this (ss, maxCached, contentType, false);
  +    public ManagedMemoryDataSource(
  +            java.io.InputStream ss, int maxCached, String contentType)
  +            throws java.io.IOException {
  +        this(ss, maxCached, contentType, false);
       }
   
       /**
        * Create a new boundary stream;
  -     * @param ss is the source input stream that is used to create this data source.. 
  +     * @param ss is the source input stream that is used to create this data source..
        * @param readbufsz lets you have some control over the amount of buffering.
        * @param maxCached  This is the max memory that is to be used to cache the data.
        * @param contentType the mime type for this data stream.
        *   by buffering you can some effiency in searching.
        * @param readall if true will read in the whole source.
  +     *
  +     * @throws java.io.IOException
        */
  -    public ManagedMemoryDataSource(java.io.InputStream ss, int maxCached,
  -              String contentType,  boolean readall) throws java.io.IOException {
  +    public ManagedMemoryDataSource(
  +            java.io.InputStream ss, int maxCached, String contentType, boolean readall)
  +            throws java.io.IOException {
  +
           this.ss = ss;
           this.maxCached = maxCached;
  -        if (null != contentType && contentType.length() != 0 ) this.contentType = contentType;
  -        if ( maxCached < MAX_MEMORY_DISK_CACHED) {
  +
  +        if ((null != contentType) && (contentType.length() != 0)) {
  +            this.contentType = contentType;
  +        }
  +
  +        if (maxCached < MAX_MEMORY_DISK_CACHED) {
               throw new IllegalArgumentException(
                       JavaUtils.getMessage("badMaxCached", "" + maxCached));
           }
  +
           if (log.isDebugEnabled()) {
  -            debugEnabled= true; //Logging should be initialized by time;
  +            debugEnabled = true;    // Logging should be initialized by time;
           }
   
  -        //for now read all in to disk.
  -        if ( readall) {
  +        // for now read all in to disk.
  +        if (readall) {
               byte[] readbuffer = new byte[READ_CHUNK_SZ];
               int read = 0;
   
               do {
                   read = ss.read(readbuffer);
  -                if (read > 0) write(readbuffer, read);
  -            }
  -            while ( read > -1);
  +
  +                if (read > 0) {
  +                    write(readbuffer, read);
  +                }
  +            } while (read > -1);
  +
               close();
           }
       }
   
  -    /*  javax.activation.Interface DataSource implementation */
  +    /* javax.activation.Interface DataSource implementation */
   
       /**
  -     * This method returns the MIME type of the data in the form of a string. 
  +     * This method returns the MIME type of the data in the form of a string.
        * @return The mime type.
        */
       public java.lang.String getContentType() {
  @@ -159,272 +192,399 @@
       }
   
       /**
  -     *This method returns an InputStream representing the the data and throws the appropriate exception if it can not do so. 
  -     *@return the java.io.InputStream for the data source.
  +     * This method returns an InputStream representing the the data and throws the appropriate exception if it can not do so.
  +     * @return the java.io.InputStream for the data source.
  +     *
  +     * @throws java.io.IOException
        */
       public synchronized java.io.InputStream getInputStream()
  -        throws java.io.IOException {
  +            throws java.io.IOException {
  +
           /*
  -        if (memorybuflist == null) {
  -            return  new java.io.FileInputStream(diskCacheFile);
  -        }
  -        else */
  -            return new Instream(); //Return the memory held stream.
  +         * if (memorybuflist == null) {
  +         *   return  new java.io.FileInputStream(diskCacheFile);
  +         * }
  +         * else
  +         */
  +        return new Instream();    // Return the memory held stream.
       }
   
       /**
        * This will flush any memory source to disk and
        * provide the name of the file if desired.
        * Return the name of the file of the stream.
  +     *
  +     * @return
        */
       public java.lang.String getName() {
  -        String ret= null;
  -        try{
  +
  +        String ret = null;
  +
  +        try {
               flushToDisk();
  -            if(diskCacheFile != null)
  -               ret= diskCacheFile.getAbsolutePath(); 
  -        }catch( Exception e){
  -                diskCacheFile= null;
  -        }        
  +
  +            if (diskCacheFile != null) {
  +                ret = diskCacheFile.getAbsolutePath();
  +            }
  +        } catch (Exception e) {
  +            diskCacheFile = null;
  +        }
  +
           return ret;
       }
   
  -    /** 
  -     *This method returns an OutputStream where the data can be written and throws the appropriate exception if it can not do so. 
  +    /**
  +     * This method returns an OutputStream where the data can be written and throws the appropriate exception if it can not do so.
        * NOT SUPPORTED, not need for axis, data sources are create by constructors.
        *
  +     *
  +     * @return
  +     *
  +     * @throws java.io.IOException
        */
       public java.io.OutputStream getOutputStream() throws java.io.IOException {
           return null;
       }
   
  -    protected java.util.LinkedList memorybuflist = new java.util.LinkedList(); //The linked list to hold the in memory buffers.
  -    protected byte[] currentMemoryBuf = null; //Hold the last memory buffer.
  -    protected int currentMemoryBufSz = 0; //The number of bytes written to the above buffer.
  -    protected int totalsz = 0;  //The total size in bytes in this data source. 
  -    protected java.io.BufferedOutputStream cachediskstream = null; //This is the cached disk stream.
  -                              //If true the source input stream is now closed. 
  -    protected boolean closed = false; 
  +    /** Field memorybuflist           */
  +    protected java.util.LinkedList memorybuflist =
  +            new java.util.LinkedList();    // The linked list to hold the in memory buffers.
  +
  +    /** Field currentMemoryBuf           */
  +    protected byte[] currentMemoryBuf = null;    // Hold the last memory buffer.
  +
  +    /** Field currentMemoryBufSz           */
  +    protected int currentMemoryBufSz =
  +            0;                                       // The number of bytes written to the above buffer.
  +
  +    /** Field totalsz           */
  +    protected int totalsz = 0;    // The total size in bytes in this data source.
  +
  +    /** Field cachediskstream           */
  +    protected java.io.BufferedOutputStream cachediskstream =
  +            null;                                    // This is the cached disk stream.
  +
  +    // If true the source input stream is now closed.
  +
  +    /** Field closed           */
  +    protected boolean closed = false;
   
       /**
        * Write bytes to the stream.
        * @param data all bytes of this array are written to the stream.
  +     *
  +     * @throws java.io.IOException
        */
  -    protected void write( byte[] data) throws java.io.IOException {
  +    protected void write(byte[] data) throws java.io.IOException {
           write(data, data.length);
       }
   
  -
  -
       /**
        * This method is a low level write.
        * Note it is designed to in the future to allow streaming to both memory
        *  AND to disk simultaneously.
  +     *
  +     * @param data
  +     * @param length
  +     *
  +     * @throws java.io.IOException
        */
  +    protected synchronized void write(byte[] data, int length)
  +            throws java.io.IOException {
   
  -    protected synchronized  void  write( byte[] data, int length)
  -      throws java.io.IOException {
           if (closed) {
               throw new java.io.IOException(JavaUtils.getMessage("streamClosed"));
           }
  +
           int writesz = length;
           int byteswritten = 0;
   
  -        if ( null != memorybuflist && totalsz + writesz > maxCached ) { //Cache to disk.
  -
  -            if (null == cachediskstream)   //Need to create a disk cache
  +        if ((null != memorybuflist)
  +                && (totalsz + writesz > maxCached)) {    // Cache to disk.
  +            if (null == cachediskstream) {               // Need to create a disk cache
                   flushToDisk();
  +            }
           }
   
  -        if ( memorybuflist != null) { //Can write to memory.
  +        if (memorybuflist != null) {    // Can write to memory.
               do {
  -                if ( null == currentMemoryBuf) {
  +                if (null == currentMemoryBuf) {
                       currentMemoryBuf = new byte[READ_CHUNK_SZ];
                       currentMemoryBufSz = 0;
  +
                       memorybuflist.add(currentMemoryBuf);
                   }
  -                //bytes to write is the min. between the remaining bytes and what is left in this buffer.
  -                int bytes2write = Math.min( (writesz - byteswritten),
  -                          (currentMemoryBuf.length - currentMemoryBufSz));
   
  -                //copy the data.
  +                // bytes to write is the min. between the remaining bytes and what is left in this buffer.
  +                int bytes2write = Math.min((writesz - byteswritten),
  +                        (currentMemoryBuf.length
  +                        - currentMemoryBufSz));
  +
  +                // copy the data.
                   System.arraycopy(data, byteswritten, currentMemoryBuf,
  -                   currentMemoryBufSz, bytes2write);
  +                        currentMemoryBufSz, bytes2write);
   
                   byteswritten += bytes2write;
                   currentMemoryBufSz += bytes2write;
   
  -                if (byteswritten < writesz) { //only get more if we really need it.
  +                if (byteswritten
  +                        < writesz) {    // only get more if we really need it.
                       currentMemoryBuf = new byte[READ_CHUNK_SZ];
                       currentMemoryBufSz = 0;
  -                    memorybuflist.add(currentMemoryBuf); //add it to the chain.
  +
  +                    memorybuflist.add(currentMemoryBuf);    // add it to the chain.
                   }
  -            } 
  -            while (byteswritten < writesz);
  +            } while (byteswritten < writesz);
           }
   
  -        if (null != cachediskstream) { //Write to the out going stream.
  +        if (null != cachediskstream) {    // Write to the out going stream.
               cachediskstream.write(data, 0, length);
           }
   
           totalsz += writesz;
  +
           return;
       }
   
       /**
        * This method is a low level write.
  -     * Close the stream. 
  +     * Close the stream.
  +     *
  +     * @throws java.io.IOException
        */
  -    protected synchronized  void close() throws java.io.IOException {
  +    protected synchronized void close() throws java.io.IOException {
  +
           if (!closed) {
  -            closed = true; //Markit as closed.
  -            if (null != cachediskstream) { //close the disk cache.
  +            closed = true;                    // Markit as closed.
  +
  +            if (null != cachediskstream) {    // close the disk cache.
                   cachediskstream.close();
  +
                   cachediskstream = null;
               }
  -            if (null != memorybuflist) {  //There is a memory buffer.
   
  -                if (currentMemoryBufSz > 0){
  -                    byte[] tmp = new byte[currentMemoryBufSz]; //Get the last buffer and make it the sizeof the actual data.
  +            if (null != memorybuflist) {      // There is a memory buffer.
  +                if (currentMemoryBufSz > 0) {
  +                    byte[] tmp =
  +                            new byte[currentMemoryBufSz];    // Get the last buffer and make it the sizeof the actual data.
  +
                       System.arraycopy(currentMemoryBuf, 0, tmp, 0,
  -                       currentMemoryBufSz);
  -                    memorybuflist.set( memorybuflist.size() - 1, tmp);  //Now replace the last buffer with this size.
  -                 }
  +                            currentMemoryBufSz);
  +                    memorybuflist.set(
  +                            memorybuflist.size() - 1,
  +                            tmp);                 // Now replace the last buffer with this size.
  +                }
   
  -                currentMemoryBuf = null; //No need for this anymore.
  +                currentMemoryBuf = null;      // No need for this anymore.
               }
           }
       }
   
  -    protected void finalize() throws Throwable{
  -        if (null != cachediskstream) { //close the disk cache.
  -                cachediskstream.close();
  -                cachediskstream = null;
  -         }
  +    /**
  +     * Method finalize
  +     *
  +     * @throws Throwable
  +     */
  +    protected void finalize() throws Throwable {
  +
  +        if (null != cachediskstream) {    // close the disk cache.
  +            cachediskstream.close();
  +
  +            cachediskstream = null;
  +        }
       }
   
       /**
  -     * Routine to flush data to disk if is in memory. 
  +     * Routine to flush data to disk if is in memory.
  +     *
  +     * @throws java.io.IOException
  +     * @throws java.io.FileNotFoundException
        */
  +    protected void flushToDisk()
  +            throws java.io.IOException, java.io.FileNotFoundException {
  +
  +        java.util.LinkedList ml = memorybuflist;
  +
  +        memorybuflist = null;
   
  -    protected void flushToDisk() throws java.io.IOException, java.io.FileNotFoundException {
  -       java.util.LinkedList ml=memorybuflist;
  -       memorybuflist =null;
  +        log.debug(JavaUtils.getMessage("maxCached", "" + maxCached,
  +                "" + totalsz));
   
  -       log.debug(JavaUtils.getMessage(
  -               "maxCached", "" + maxCached, "" +  totalsz));
  +        if (ml != null) {
  +            if (null == cachediskstream) {    // Need to create a disk cache
  +                try {
  +                    MessageContext mc = MessageContext.getCurrentContext();
  +                    String attdir = (mc == null)
  +                            ? null
  +                            : mc.getStrProp(
  +                                    MessageContext.ATTACHMENTS_DIR);
   
  -       if( ml != null){
  -           if (null == cachediskstream) { //Need to create a disk cache
  -                try{
  -                    MessageContext mc= MessageContext.getCurrentContext();
  -                    String attdir= mc == null ? null :  mc.getStrProp(MessageContext.ATTACHMENTS_DIR );
                       diskCacheFile = java.io.File.createTempFile("Axis", "axis",
  -                       attdir== null ? null : new File( attdir)); 
  -                    log.debug(JavaUtils.getMessage(
  -                            "diskCache", diskCacheFile.getAbsolutePath()));
  +                            (attdir == null)
  +                            ? null
  +                            : new File(
  +                                    attdir));
  +
  +                    log.debug(
  +                            JavaUtils.getMessage(
  +                                    "diskCache", diskCacheFile.getAbsolutePath()));
  +
                       cachediskstream = new java.io.BufferedOutputStream(
  -                         new java.io.FileOutputStream(diskCacheFile));
  +                            new java.io.FileOutputStream(diskCacheFile));
  +
                       int listsz = ml.size();
  -                  
  -                    //Write out the entire memory held store to disk.
  +
  +                    // Write out the entire memory held store to disk.
                       for (java.util.Iterator it = ml.iterator();
  -                           it.hasNext(); ) {
  +                         it.hasNext();) {
                           byte[] rbuf = (byte[]) it.next();
  -                        int bwrite = listsz-- == 0 ? currentMemoryBufSz :
  -                           rbuf.length;
  +                        int bwrite = (listsz-- == 0)
  +                                ? currentMemoryBufSz
  +                                : rbuf.length;
   
                           cachediskstream.write(rbuf, 0, bwrite);
  -                        if(closed){
  +
  +                        if (closed) {
                               cachediskstream.close();
  -                            cachediskstream= null;
  +
  +                            cachediskstream = null;
                           }
                       }
  -                    memorybuflist= null;
  -                }catch(java.lang.SecurityException se){
  -                    diskCacheFile=null;
  -                    cachediskstream= null;
  -                    maxCached= java.lang.Integer.MAX_VALUE; 
  +
  +                    memorybuflist = null;
  +                } catch (java.lang.SecurityException se) {
  +                    diskCacheFile = null;
  +                    cachediskstream = null;
  +                    maxCached = java.lang.Integer.MAX_VALUE;
  +
                       log.info(JavaUtils.getMessage("nodisk00"), se);
                   }
               }
           }
       }
   
  -    public synchronized boolean delete(){
  -        boolean ret= false;
  +    /**
  +     * Method delete
  +     *
  +     * @return
  +     */
  +    public synchronized boolean delete() {
  +
  +        boolean ret = false;
  +
           deleted = true;
  -        if(diskCacheFile != null){
  -            if(cachediskstream != null){
  -                try{
  -                cachediskstream.close();
  -                }catch(Exception e){
  -                }
  -                cachediskstream= null;
  -            }    
  -            for(java.util.Iterator i= readers.keySet().iterator(); i.hasNext();){
  -                Instream stream= (Instream ) i.next();
  -                if( null != stream){
  -                try{
  -                    stream.close();
  -                    }catch(Exception e){
  +
  +        if (diskCacheFile != null) {
  +            if (cachediskstream != null) {
  +                try {
  +                    cachediskstream.close();
  +                } catch (Exception e) {
                   }
  +
  +                cachediskstream = null;
  +            }
  +
  +            for (java.util.Iterator i = readers.keySet().iterator();
  +                 i.hasNext();) {
  +                Instream stream = (Instream) i.next();
  +
  +                if (null != stream) {
  +                    try {
  +                        stream.close();
  +                    } catch (Exception e) {
  +                    }
                   }
               }
  +
               readers.clear();
  -            try{
  +
  +            try {
                   diskCacheFile.delete();
  -                ret= true;
  -            }catch (Exception e){
  -              // Give it our best shot.
  +
  +                ret = true;
  +            } catch (Exception e) {
  +
  +                // Give it our best shot.
                   diskCacheFile.deleteOnExit();
  -              try{
  -              }catch(Exception e2){
  -                // Gave it our best shot.
  -              }
   
  +                try {
  +                } catch (Exception e2) {
  +
  +                    // Gave it our best shot.
  +                }
               }
           }
  +
           memorybuflist = null;
  +
           return ret;
       }
   
       // inner classes cannot have static declarations...
  -    protected static Log is_log =
  -        LogFactory.getLog(Instream.class.getName());
   
  -    /** Inner class to handle getting an input stream to this data source
  +    /** Field is_log           */
  +    protected static Log is_log = LogFactory.getLog(Instream.class.getName());
  +
  +    /**
  +     * Inner class to handle getting an input stream to this data source
        *  Handles creating an input stream to the source.
        */
  -    private class Instream extends java.io.InputStream
  -    {
  -        protected int bread = 0; //bytes read
  -        java.io.FileInputStream fin = null;  //The real stream.
  -        int currentIndex = 0;  //The position in the list were we are reading from.
  -        byte[] currentBuf = null; //the buffer we are currently reading from.
  -        int currentBufPos = 0; //The current position in there.
  -        boolean readClosed= false; //The read stream has been closed.
  +    private class Instream extends java.io.InputStream {
  +
  +        /** Field bread           */
  +        protected int bread = 0;               // bytes read
   
  +        /** Field fin           */
  +        java.io.FileInputStream fin = null;    // The real stream.
  +
  +        /** Field currentIndex           */
  +        int currentIndex =
  +                0;                                 // The position in the list were we are reading from.
  +
  +        /** Field currentBuf           */
  +        byte[] currentBuf = null;    // the buffer we are currently reading from.
  +
  +        /** Field currentBufPos           */
  +        int currentBufPos = 0;                 // The current position in there.
  +
  +        /** Field readClosed           */
  +        boolean readClosed = false;            // The read stream has been closed.
  +
  +        /**
  +         * Constructor Instream
  +         *
  +         * @throws java.io.IOException
  +         */
  +        protected Instream() throws java.io.IOException {
   
  -        protected Instream() throws java.io.IOException{
               if (deleted) {
                   throw new java.io.IOException(
                           JavaUtils.getMessage("resourceDeleted"));
               }
  -            readers.put( this, null);
  +
  +            readers.put(this, null);
           }
   
  +        /**
  +         * Method available
  +         *
  +         * @return
  +         *
  +         * @throws java.io.IOException
  +         */
           public int available() throws java.io.IOException {
   
               if (deleted) {
                   throw new java.io.IOException(
                           JavaUtils.getMessage("resourceDeleted"));
               }
  +
               if (readClosed) {
                   throw new java.io.IOException(
                           JavaUtils.getMessage("streamClosed"));
               }
  -            int ret= totalsz - bread;
  +
  +            int ret = totalsz - bread;
   
               if (debugEnabled) {
                   is_log.debug("available() = " + ret + ".");
  @@ -436,30 +596,46 @@
           /**
            * Read a byte from the stream.
            * @param byte to read or -1 if no more data.
  +         *
  +         * @return
  +         *
  +         * @throws java.io.IOException
            */
           public int read() throws java.io.IOException {
  -            synchronized (ManagedMemoryDataSource.this){
  -              byte[]retb = new byte[1];
  -              int br = read(retb, 0, 1);
   
  -              if (br == -1) return -1;
  -              return retb[0];
  +            synchronized (ManagedMemoryDataSource.this) {
  +                byte[] retb = new byte[1];
  +                int br = read(retb, 0, 1);
  +
  +                if (br == -1) {
  +                    return -1;
  +                }
  +
  +                return retb[0];
               }
           }
  +
           /**
            * Not supported.
  +         *
  +         * @return
            */
           public boolean markSupported() {
  +
               if (debugEnabled) {
                   is_log.debug("markSupported() = " + false + ".");
               }
  +
               return false;
           }
   
           /**
            * Not supported.
  +         *
  +         * @param readlimit
            */
  -        public void mark(int readlimit){
  +        public void mark(int readlimit) {
  +
               if (debugEnabled) {
                   is_log.debug("mark()");
               }
  @@ -467,19 +643,28 @@
   
           /**
            * Not supported.
  +         *
  +         * @throws java.io.IOException
            */
           public void reset() throws java.io.IOException {
  +
               if (debugEnabled) {
                   is_log.debug("reset()");
               }
  +
               throw new java.io.IOException(JavaUtils.getMessage("noResetMark"));
           }
   
           /**
            * Skip bytes in the stream.
            * @param the number of bytes to skip.
  +         *
  +         * @param skipped
  +         *
  +         * @return
  +         *
  +         * @throws java.io.IOException
            */
  -
           public long skip(long skipped) throws java.io.IOException {
   
               if (debugEnabled) {
  @@ -490,154 +675,200 @@
                   throw new java.io.IOException(
                           JavaUtils.getMessage("resourceDeleted"));
               }
  +
               if (readClosed) {
                   throw new java.io.IOException(
                           JavaUtils.getMessage("streamClosed"));
               }
  -            if ( skipped < 1) return 0; //nothing to skip.
   
  +            if (skipped < 1) {
  +                return 0;    // nothing to skip.
  +            }
  +
  +            synchronized (ManagedMemoryDataSource.this) {
  +                skipped = Math.min(skipped,
  +                        totalsz
  +                        - bread);    // only skip what we've read.
   
  -            synchronized (ManagedMemoryDataSource.this){
  +                if (skipped == 0) {
  +                    return 0;
  +                }
   
  -                skipped = Math.min(skipped, totalsz - bread);//only skip what we've read. 
  -                if(skipped == 0) return 0;
  -                java.util.List ml = memorybuflist; //hold the memory list.
  +                java.util.List ml = memorybuflist;    // hold the memory list.
                   int bwritten = 0;
   
  -                if ( ml != null) {
  -                    if ( null == currentBuf ) { //get the buffer we need to read from.
  +                if (ml != null) {
  +                    if (null == currentBuf) {    // get the buffer we need to read from.
                           currentBuf = (byte[]) ml.get(currentIndex);
  -                        currentBufPos = 0; //start reading from the begining.
  +                        currentBufPos = 0;    // start reading from the begining.
                       }
  +
                       do {
  -                        long bcopy = Math.min(currentBuf.length - currentBufPos,
  -                        skipped - bwritten);
  +                        long bcopy = Math.min(currentBuf.length
  +                                - currentBufPos,
  +                                skipped - bwritten);
   
                           bwritten += bcopy;
                           currentBufPos += bcopy;
  +
                           if (bwritten < skipped) {
                               currentBuf = (byte[]) ml.get(++currentIndex);
                               currentBufPos = 0;
                           }
  -                    }
  -                    while ( bwritten < skipped);
  +                    } while (bwritten < skipped);
                   }
  -                if (null != fin) fin.skip(skipped);
  +
  +                if (null != fin) {
  +                    fin.skip(skipped);
  +                }
  +
                   bread += skipped;
               }
   
               if (debugEnabled) {
                   is_log.debug("skipped " + skipped + ".");
               }
  +
               return skipped;
           }
   
           /**
  -         * Read from the stream. 
  -         * @param b the data buffer to write to. 
  +         * Read from the stream.
  +         * @param b the data buffer to write to.
            * @param off the offset in the buffer to write to
            * @param len the number of bytes to write to the buffer.
  +         *
  +         * @return
  +         *
  +         * @throws java.io.IOException
            */
  -
           public int read(byte[] b, int off, int len) throws java.io.IOException {
  +
               if (debugEnabled) {
  -                is_log.debug(this.hashCode() + " read(" + off + ", " + len +")");
  +                is_log.debug(this.hashCode() + " read(" + off + ", " + len
  +                        + ")");
               }
  +
               if (deleted) {
                   throw new java.io.IOException(
                           JavaUtils.getMessage("resourceDeleted"));
               }
  +
               if (readClosed) {
                   throw new java.io.IOException(
                           JavaUtils.getMessage("streamClosed"));
               }
  +
               if (b == null) {
                   throw new InternalException(JavaUtils.getMessage("nullInput"));
               }
  -            if (off < 0)  {
  +
  +            if (off < 0) {
                   throw new IndexOutOfBoundsException(
                           JavaUtils.getMessage("negOffset", "" + off));
               }
  +
               if (len < 0) {
                   throw new IndexOutOfBoundsException(
                           JavaUtils.getMessage("length", "" + len));
               }
  +
               if (len + off > b.length) {
                   throw new IndexOutOfBoundsException(
                           JavaUtils.getMessage("writeBeyond"));
               }
  +
               if (len == 0) {
                   return 0;
               }
   
               int bwritten = 0;
   
  -            synchronized(ManagedMemoryDataSource.this){
  +            synchronized (ManagedMemoryDataSource.this) {
                   if (bread == totalsz) {
                       return -1;
                   }
  +
                   java.util.List ml = memorybuflist;
  -                len = Math.min(len, totalsz - bread); //Only return the number of bytes in the data store that is left.
  +
  +                len = Math.min(
  +                        len,
  +                        totalsz
  +                        - bread);    // Only return the number of bytes in the data store that is left.
  +
                   if (debugEnabled) {
                       is_log.debug("len = " + len);
                   }
  -                if ( ml != null) {
  -                    if ( null == currentBuf ) { //Get the buffer we need to read from.
  +
  +                if (ml != null) {
  +                    if (null == currentBuf) {    // Get the buffer we need to read from.
                           currentBuf = (byte[]) ml.get(currentIndex);
  -                        currentBufPos = 0; //New buffer start from the begining.
  +                        currentBufPos = 0;    // New buffer start from the begining.
                       }
  +
                       do {
  -                        //The bytes to copy, the minimum of the bytes left in this buffer or bytes remaining. 
  -                        int bcopy = Math.min(currentBuf.length - currentBufPos, len - bwritten);
   
  -                        //Copy the data.
  -                        System.arraycopy(currentBuf, currentBufPos , b,
  -                            off + bwritten , bcopy );
  +                        // The bytes to copy, the minimum of the bytes left in this buffer or bytes remaining.
  +                        int bcopy = Math.min(currentBuf.length - currentBufPos,
  +                                len - bwritten);
  +
  +                        // Copy the data.
  +                        System.arraycopy(currentBuf, currentBufPos, b,
  +                                off + bwritten, bcopy);
  +
                           bwritten += bcopy;
                           currentBufPos += bcopy;
   
  -                        if (bwritten < len) { //Get the next buffer.
  +                        if (bwritten < len) {    // Get the next buffer.
                               currentBuf = (byte[]) ml.get(++currentIndex);
                               currentBufPos = 0;
                           }
  -                    }
  -                    while ( bwritten < len);
  +                    } while (bwritten < len);
                   }
   
  -                if (bwritten == 0 && null != diskCacheFile) {
  +                if ((bwritten == 0) && (null != diskCacheFile)) {
                       if (debugEnabled) {
                           is_log.debug(JavaUtils.getMessage("reading", "" + len));
                       }
  -                    if (null == fin) { //we are now reading from disk.
  +
  +                    if (null == fin) {           // we are now reading from disk.
                           if (debugEnabled) {
  -                            is_log.debug(JavaUtils.getMessage("openBread",
  -                                    diskCacheFile.getCanonicalPath()));
  +                            is_log.debug(
  +                                    JavaUtils.getMessage(
  +                                            "openBread",
  +                                            diskCacheFile.getCanonicalPath()));
                           }
  +
                           if (debugEnabled) {
                               is_log.debug(JavaUtils.getMessage("openBread",
                                       "" + bread));
  -                        }                 
  -                        fin = new java.io.FileInputStream( diskCacheFile);
  -                        if (bread >0) {
  -                            fin.skip(bread); //Skip what we've read so far.
  +                        }
  +
  +                        fin = new java.io.FileInputStream(diskCacheFile);
  +
  +                        if (bread > 0) {
  +                            fin.skip(bread);     // Skip what we've read so far.
                           }
                       }
   
                       if (cachediskstream != null) {
                           if (debugEnabled) {
                               is_log.debug(JavaUtils.getMessage("flushing"));
  -                        }                 
  -                        cachediskstream.flush();  
  +                        }
  +
  +                        cachediskstream.flush();
  +                    }
  +
  +                    if (debugEnabled) {
  +                        is_log.debug(JavaUtils.getMessage("flushing"));
  +                        is_log.debug("len=" + len);
  +                        is_log.debug("off=" + off);
  +                        is_log.debug("b.length=" + b.length);
                       }
   
  -                   if (debugEnabled) {
  -                       is_log.debug(JavaUtils.getMessage("flushing"));
  -                       is_log.debug("len=" + len);
  -                       is_log.debug("off=" + off);
  -                       is_log.debug("b.length=" + b.length);
  -                   }
  -                   bwritten = fin.read(b, off, len);
  +                    bwritten = fin.read(b, off, len);
                   }
  +
                   if (bwritten > 0) {
                       bread += bwritten;
                   }
  @@ -647,59 +878,79 @@
                   is_log.debug(this.hashCode()
                           + JavaUtils.getMessage("read", "" + bwritten));
               }
  +
               return bwritten;
           }
   
           /**
  -         * close the stream. 
  +         * close the stream.
  +         *
  +         * @throws java.io.IOException
            */
  -
           public synchronized void close() throws java.io.IOException {
  -            if(debugEnabled) is_log.debug("close()");
  -            if(!readClosed){
  +
  +            if (debugEnabled) {
  +                is_log.debug("close()");
  +            }
  +
  +            if (!readClosed) {
                   readers.remove(this);
  -                readClosed= true;
  -                if( fin != null) fin.close(); 
  -                fin= null;
  +
  +                readClosed = true;
  +
  +                if (fin != null) {
  +                    fin.close();
  +                }
  +
  +                fin = null;
               }
           }
   
  -
  -        protected void finalize() throws Throwable{
  +        /**
  +         * Method finalize
  +         *
  +         * @throws Throwable
  +         */
  +        protected void finalize() throws Throwable {
               close();
           }
  +    }                                          // endof innerclass Instream
   
  -    }//endof innerclass Instream 
  +    // Used to test.
   
  +    /**
  +     * Method main
  +     *
  +     * @param arg
  +     */
  +    public static void main(String arg[]) {    // test
   
  -    //Used to test.
  -    public static void main( String arg[]) { //test
           try {
               String readFile = arg[0];
               String writeFile = arg[1];
  -            java.io.FileInputStream ss = new java.io.FileInputStream(readFile);
  -
  -            ManagedMemoryDataSource ms = new ManagedMemoryDataSource( ss,
  -             1024 * 1024,  "foo/data",  true);
  -            javax.activation.DataHandler dh = new javax.activation.DataHandler
  -                      (ms);
  +            java.io.FileInputStream ss =
  +                    new java.io.FileInputStream(readFile);
  +            ManagedMemoryDataSource ms =
  +                    new ManagedMemoryDataSource(ss, 1024 * 1024, "foo/data", true);
  +            javax.activation.DataHandler dh =
  +                    new javax.activation.DataHandler(ms);
               java.io.InputStream is = dh.getInputStream();
               java.io.FileOutputStream fo =
  -                 new java.io.FileOutputStream(writeFile);
  +                    new java.io.FileOutputStream(writeFile);
               byte[] buf = new byte[512];
               int read = 0;
   
               do {
                   read = is.read(buf);
  -                if (read > 0) fo.write(buf, 0, read);
   
  -            }
  -            while (read > -1);
  +                if (read > 0) {
  +                    fo.write(buf, 0, read);
  +                }
  +            } while (read > -1);
  +
               fo.close();
               is.close();
  -
  -        }
  -        catch ( java.lang.Exception e) {
  +        } catch (java.lang.Exception e) {
               log.error(JavaUtils.getMessage("exception00"), e);
           }
       }
  
  
  
  1.15      +173 -97   xml-axis/java/src/org/apache/axis/attachments/MimeUtils.java
  
  Index: MimeUtils.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/attachments/MimeUtils.java,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- MimeUtils.java	29 May 2002 13:05:54 -0000	1.14
  +++ MimeUtils.java	24 Jun 2002 12:34:51 -0000	1.15
  @@ -54,241 +54,315 @@
    */
   
   /**
  - * @author Rick Rineholt 
  + * @author Rick Rineholt
    * @author Wouter Cloetens (wouter@mind.be)
    */
  -
   package org.apache.axis.attachments;
   
  -
  -import org.apache.axis.transport.http.HTTPConstants ;
  +import org.apache.axis.transport.http.HTTPConstants;
   import org.apache.axis.utils.JavaUtils;
  -
   import org.apache.commons.logging.Log;
   import org.apache.commons.logging.LogFactory;
   
  -import java.util.Properties;
  -import javax.mail.*;
  -import javax.mail.internet.*;
  -import javax.activation.*;
  -
   /**
    * This class is defines utilities for mime.
    */
  +public class MimeUtils {
   
  -public class MimeUtils
  -{
  -    protected static Log log =
  -        LogFactory.getLog(MimeUtils.class.getName());
  +    /** Field log           */
  +    protected static Log log = LogFactory.getLog(MimeUtils.class.getName());
   
       /**
  -    * Determine as efficiently as possible the content length for attachments in a mail Multipart.
  -    * @param mp is the multipart to be serarched.
  -    * @return the actual length.
  -    */
  -    public static long getContentLength(javax.mail.Multipart mp ) throws javax.mail.MessagingException, java.io.IOException {
  +     * Determine as efficiently as possible the content length for attachments in a mail Multipart.
  +     * @param mp is the multipart to be serarched.
  +     * @return the actual length.
  +     *
  +     * @throws javax.mail.MessagingException
  +     * @throws java.io.IOException
  +     */
  +    public static long getContentLength(javax.mail.Multipart mp)
  +            throws javax.mail.MessagingException, java.io.IOException {
   
           int totalParts = mp.getCount();
           long totalContentLength = 0;
   
           for (int i = 0; i < totalParts; ++i) {
  -            javax.mail.internet.MimeBodyPart bp = (javax.mail.internet.MimeBodyPart) mp.getBodyPart(i);
  +            javax.mail.internet.MimeBodyPart bp =
  +                    (javax.mail.internet.MimeBodyPart) mp.getBodyPart(i);
   
               totalContentLength += getContentLength(bp);
           }
   
           String ctype = mp.getContentType();
  -        javax.mail.internet.ContentType ct = new javax.mail.internet.ContentType( ctype);
  -        String boundaryStr = ct.getParameter("boundary");
  -        int boundaryStrLen = boundaryStr.length() + 4; //must add two for -- prefix and another two for crlf
  -
  -        //there is one more boundary than parts
  -        //each parts data must have crlf after it.
  -        //last boundary has an additional --crlf
  -        return totalContentLength
  -            + boundaryStrLen * (totalParts + 1)
  -            + 2 * totalParts +
  -            +4;
  +        javax.mail.internet.ContentType ct =
  +                new javax.mail.internet.ContentType(ctype);
  +        String boundaryStr =
  +                ct.getParameter("boundary");
  +        int boundaryStrLen =
  +                boundaryStr.length()
  +                + 4;    // must add two for -- prefix and another two for crlf
  +
  +        // there is one more boundary than parts
  +        // each parts data must have crlf after it.
  +        // last boundary has an additional --crlf
  +        return totalContentLength + boundaryStrLen * (totalParts + 1)
  +                + 2 * totalParts + +4;
       }
   
       /**
  -    * Determine the length for the individual part. 
  -    * @param mp is the part to be serarched.
  -    * @return the length in bytes.
  -    */
  -    protected  static long  getContentLength(javax.mail.internet.MimeBodyPart bp) {
  +     * Determine the length for the individual part.
  +     * @param mp is the part to be serarched.
  +     *
  +     * @param bp
  +     * @return the length in bytes.
  +     */
  +    protected static long getContentLength(
  +            javax.mail.internet.MimeBodyPart bp) {
  +
           long headerLength = -1L;
           long dataSize = -1L;
   
           try {
  -            headerLength = getHeaderLength( bp);
  -            javax.activation.DataHandler dh =  bp.getDataHandler();
  +            headerLength = getHeaderLength(bp);
  +
  +            javax.activation.DataHandler dh = bp.getDataHandler();
               javax.activation.DataSource ds = dh.getDataSource();
   
  -            //Do files our selfs since this is costly to read in. Ask the file system.
  +            // Do files our selfs since this is costly to read in. Ask the file system.
               // This is 90% of the use of attachments.
  -            if ( ds instanceof javax.activation.FileDataSource) {
  -                javax.activation.FileDataSource fdh = (javax.activation.FileDataSource) ds;
  +            if (ds instanceof javax.activation.FileDataSource) {
  +                javax.activation.FileDataSource fdh =
  +                        (javax.activation.FileDataSource) ds;
                   java.io.File df = fdh.getFile();
   
                   if (!df.exists()) {
  -                    throw new RuntimeException(
  -                            JavaUtils.getMessage("noFile", df.getAbsolutePath()));
  +                    throw new RuntimeException(JavaUtils.getMessage("noFile",
  +                            df.getAbsolutePath()));
                   }
  +
                   dataSize = df.length();
  -            }
  -            else {
  +            } else {
                   dataSize = bp.getSize();
  -                if (-1 == dataSize ) { //Data size is not known so read it the hard way...
  +
  +                if (-1 == dataSize) {    // Data size is not known so read it the hard way...
                       dataSize = 0;
  +
                       java.io.InputStream in = ds.getInputStream();
                       byte[] readbuf = new byte[64 * 1024];
                       int bytesread;
   
                       do {
                           bytesread = in.read(readbuf);
  -                        if (bytesread > 0) dataSize += bytesread;
  -                    }
  -                    while ( bytesread > -1);
  +
  +                        if (bytesread > 0) {
  +                            dataSize += bytesread;
  +                        }
  +                    } while (bytesread > -1);
  +
                       in.close();
                   }
               }
  -        }
  -        catch (Exception e) {
  +        } catch (Exception e) {
               log.error(JavaUtils.getMessage("exception00"), e);
           }
  +
           return dataSize + headerLength;
       }
  +
       /**
        * Gets the header length for any part.
        * @param the part to determine the header length for.
  +     *
  +     * @param bp
        * @return the length in bytes.
  +     *
  +     * @throws javax.mail.MessagingException
  +     * @throws java.io.IOException
        */
  -    private static long  getHeaderLength(javax.mail.internet.MimeBodyPart bp) throws javax.mail.MessagingException, java.io.IOException {
  +    private static long getHeaderLength(javax.mail.internet.MimeBodyPart bp)
  +            throws javax.mail.MessagingException, java.io.IOException {
   
  -        javax.mail.internet.MimeBodyPart headersOnly = new javax.mail.internet.MimeBodyPart(new javax.mail.internet.InternetHeaders(), new byte[0]);
  +        javax.mail.internet.MimeBodyPart headersOnly =
  +                new javax.mail.internet.MimeBodyPart(
  +                        new javax.mail.internet.InternetHeaders(), new byte[0]);
   
  -        for ( java.util.Enumeration en = bp.getAllHeaders(); en.hasMoreElements() ; ) {
  +        for (java.util.Enumeration en = bp.getAllHeaders();
  +             en.hasMoreElements();) {
               javax.mail.Header header = (javax.mail.Header) en.nextElement();
   
  -            headersOnly.addHeader( header.getName(), header.getValue());
  +            headersOnly.addHeader(header.getName(), header.getValue());
           }
   
  -        java.io.ByteArrayOutputStream bas = new java.io.ByteArrayOutputStream( 1024 * 16);
  +        java.io.ByteArrayOutputStream bas =
  +                new java.io.ByteArrayOutputStream(1024 * 16);
   
           headersOnly.writeTo(bas);
           bas.close();
   
  -        return (long) bas.size(); //This has header length plus the crlf part that seperates the data
  +        return (long) bas.size();    // This has header length plus the crlf part that seperates the data
       }
   
  -    public static String[] filter = new String[] { "Message-ID", "Mime-Version", "Content-Type" } ;
  -    
  +    /** Field filter           */
  +    public static String[] filter = new String[]{"Message-ID", "Mime-Version",
  +                                                 "Content-Type"};
  +
       /**
        * This routine will the multi part type and write it out to a stream.
        * @param os is the output stream to write to.
        * @param the multipart that needs to be written to the stream.
  +     * @param mp
        */
  -    public static void writeToMultiPartStream(java.io.OutputStream os, javax.mail.internet.MimeMultipart  mp) {
  +    public static void writeToMultiPartStream(
  +            java.io.OutputStream os, javax.mail.internet.MimeMultipart mp) {
  +
           try {
               java.util.Properties props = System.getProperties();
   
  -            props.put("mail.smtp.host", "localhost"); //this is a bogus since we will never mail it.
  -            javax.mail.Session session = javax.mail.Session.getInstance(props, null);
  -            javax.mail.internet.MimeMessage message = new javax.mail.internet.MimeMessage(session);
  +            props.put(
  +                    "mail.smtp.host",
  +                    "localhost");    // this is a bogus since we will never mail it.
  +
  +            javax.mail.Session session =
  +                    javax.mail.Session.getInstance(props, null);
  +            javax.mail.internet.MimeMessage message =
  +                    new javax.mail.internet.MimeMessage(session);
   
               message.setContent(mp);
               message.saveChanges();
               message.writeTo(os, filter);
  -
  -        }
  -        catch (javax.mail.MessagingException e) {
  +        } catch (javax.mail.MessagingException e) {
               log.error(JavaUtils.getMessage("javaxMailMessagingException00"), e);
  -        }
  -        catch (java.io.IOException e) {
  +        } catch (java.io.IOException e) {
               log.error(JavaUtils.getMessage("javaIOException00"), e);
           }
       }
  +
       /**
        * This routine will get the content type.
  +     *
  +     * @param mp
  +     *
  +     * @return
        */
       public static String getContentType(javax.mail.internet.MimeMultipart mp) {
           return mp.getContentType();
       }
  +
       /**
        * This routine will create a multipar object from the parts and the SOAP content.
        * @param the env should be the text for the main root part.
        * @param the parts contain a collection of the message parts.
  +     *
  +     * @param env
  +     * @param parts
  +     *
  +     * @return
  +     *
  +     * @throws org.apache.axis.AxisFault
        */
  +    public static javax.mail.internet.MimeMultipart createMP(
  +            String env, java.util.Collection parts)
  +            throws org.apache.axis.AxisFault {
   
  -    public static javax.mail.internet.MimeMultipart createMP(String env, java.util.Collection parts ) throws org.apache.axis.AxisFault {
           javax.mail.internet.MimeMultipart multipart = null;
   
           try {
               String rootCID = getNewContentIdValue();
   
  -            if (rootCID.startsWith("cid:")) rootCID = rootCID.substring(4);
  -            multipart = new javax.mail.internet.MimeMultipart("related; type=\"text/xml\"; start=\"<" + rootCID + ">\"" );
  +            if (rootCID.startsWith("cid:")) {
  +                rootCID = rootCID.substring(4);
  +            }
   
  -            javax.mail.internet.MimeBodyPart messageBodyPart = new javax.mail.internet.MimeBodyPart();
  +            multipart = new javax.mail.internet.MimeMultipart(
  +                    "related; type=\"text/xml\"; start=\"<" + rootCID + ">\"");
   
  -            messageBodyPart.setText(env);
  -            messageBodyPart.setHeader("Content-Type", "text/xml; charset=UTF-8" );
  -            messageBodyPart.setHeader("Content-ID", "<" + rootCID  + ">" );
  -            messageBodyPart.setHeader(HTTPConstants.HEADER_CONTENT_TRANSFER_ENCODING, "binary");
  +            javax.mail.internet.MimeBodyPart messageBodyPart =
  +                    new javax.mail.internet.MimeBodyPart();
   
  +            messageBodyPart.setText(env);
  +            messageBodyPart.setHeader("Content-Type",
  +                    "text/xml; charset=UTF-8");
  +            messageBodyPart.setHeader("Content-ID", "<" + rootCID + ">");
  +            messageBodyPart.setHeader(
  +                    HTTPConstants.HEADER_CONTENT_TRANSFER_ENCODING, "binary");
               multipart.addBodyPart(messageBodyPart);
   
  -            for (java.util.Iterator it = parts.iterator(); it.hasNext(); ) {
  -                org.apache.axis.Part part=  (org.apache.axis.Part) it.next();
  +            for (java.util.Iterator it = parts.iterator(); it.hasNext();) {
  +                org.apache.axis.Part part =
  +                        (org.apache.axis.Part) it.next();
                   javax.activation.DataHandler dh =
  -                    org.apache.axis.attachments.AttachmentUtils.getActivationDataHandler(part);
  +                        org.apache.axis.attachments.AttachmentUtils.getActivationDataHandler(
  +                                part);
                   String contentID = part.getContentId();
   
  -                if (contentID.startsWith("cid:")) contentID = contentID.substring(4);
  +                if (contentID.startsWith("cid:")) {
  +                    contentID = contentID.substring(4);
  +                }
   
                   messageBodyPart = new javax.mail.internet.MimeBodyPart();
   
                   messageBodyPart.setDataHandler(dh);
  +
                   String contentType = dh.getContentType();
   
  -                if (contentType == null || contentType.trim().length() == 0) {
  +                if ((contentType == null)
  +                        || (contentType.trim().length() == 0)) {
                       contentType = "application/octet-stream";
                   }
  -                messageBodyPart.setHeader(HTTPConstants.HEADER_CONTENT_TYPE , contentType );
  -                messageBodyPart.setHeader(HTTPConstants.HEADER_CONTENT_ID , "<" + contentID  + ">" );
  -                messageBodyPart.setHeader(HTTPConstants.HEADER_CONTENT_TRANSFER_ENCODING , "binary"); //Safe and fastest for anything other than mail;
  -                for( java.util.Iterator i= part.getNonMatchingMimeHeaders(new String[]{
  -                   HTTPConstants.HEADER_CONTENT_TYPE, HTTPConstants.HEADER_CONTENT_ID,
  -                   HTTPConstants.HEADER_CONTENT_TRANSFER_ENCODING }); i.hasNext(); ){
  -                       String header= (String) i.next();
  -                       messageBodyPart.setHeader(header, part.getFirstMimeHeader(header)); 
  +
  +                messageBodyPart.setHeader(HTTPConstants.HEADER_CONTENT_TYPE,
  +                        contentType);
  +                messageBodyPart.setHeader(HTTPConstants.HEADER_CONTENT_ID,
  +                        "<" + contentID + ">");
  +                messageBodyPart.setHeader(
  +                        HTTPConstants.HEADER_CONTENT_TRANSFER_ENCODING,
  +                        "binary");    // Safe and fastest for anything other than mail;
  +
  +                for (java.util.Iterator i =
  +                        part.getNonMatchingMimeHeaders(new String[]{
  +                            HTTPConstants.HEADER_CONTENT_TYPE,
  +                            HTTPConstants.HEADER_CONTENT_ID,
  +                            HTTPConstants.HEADER_CONTENT_TRANSFER_ENCODING}); i.hasNext();) {
  +                    String header = (String) i.next();
  +
  +                    messageBodyPart.setHeader(header,
  +                            part.getFirstMimeHeader(header));
                   }
  +
                   multipart.addBodyPart(messageBodyPart);
               }
  -        }
  -        catch (javax.mail.MessagingException e) {
  +        } catch (javax.mail.MessagingException e) {
               log.error(JavaUtils.getMessage("javaxMailMessagingException00"), e);
           }
  -        return multipart ;
  +
  +        return multipart;
       }
   
  +    /** Field thisHost           */
       static String thisHost = null;
   
  +    /** Field count           */
       private static int count = (int) (Math.random() * 100);
   
  +    /**
  +     * Method getNewContentIdValue
  +     *
  +     * @return
  +     */
       public static String getNewContentIdValue() {
  +
           int lcount;
   
  -        synchronized (org.apache.axis.Message.class  ) {
  +        synchronized (org.apache.axis.Message.class) {
               lcount = ++count;
           }
  +
           if (null == thisHost) {
               try {
                   thisHost = java.net.InetAddress.getLocalHost().getHostName();
  -            } 
  -            catch (java.net.UnknownHostException e) {
  -                log.error(JavaUtils.getMessage("javaNetUnknownHostException00"), e);
  +            } catch (java.net.UnknownHostException e) {
  +                log.error(JavaUtils.getMessage("javaNetUnknownHostException00"),
  +                        e);
   
                   thisHost = "localhost";
               }
  @@ -297,7 +371,9 @@
           StringBuffer s = new StringBuffer();
   
           // Unique string is <hashcode>.<currentTime>.apache-soap.<hostname>
  -        s.append("cid:").append( lcount).append(s.hashCode()).append('.').append(System.currentTimeMillis()).append(".AXIS@").append(thisHost);
  +        s.append("cid:").append(lcount).append(s.hashCode()).append('.').append(
  +                System.currentTimeMillis()).append(".AXIS@").append(thisHost);
  +
           return s.toString();
       }
   }
  
  
  
  1.13      +486 -210  xml-axis/java/src/org/apache/axis/attachments/MultiPartRelatedInputStream.java
  
  Index: MultiPartRelatedInputStream.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/attachments/MultiPartRelatedInputStream.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- MultiPartRelatedInputStream.java	24 Mar 2002 18:51:28 -0000	1.12
  +++ MultiPartRelatedInputStream.java	24 Jun 2002 12:34:51 -0000	1.13
  @@ -52,328 +52,565 @@
    * information on the Apache Software Foundation, please see
    * <http://www.apache.org/>.
    */
  -
   package org.apache.axis.attachments;
  -import org.apache.axis.transport.http.HTTPConstants; 
  -import org.apache.axis.attachments.ManagedMemoryDataSource;
  -import javax.activation.DataHandler;
  +
   import org.apache.axis.Part;
  +import org.apache.axis.transport.http.HTTPConstants;
   import org.apache.axis.utils.JavaUtils;
  -import javax.mail.internet.MimeUtility;
   import org.apache.commons.logging.Log;
   import org.apache.commons.logging.LogFactory;
   
  +import javax.activation.DataHandler;
  +import javax.mail.internet.MimeUtility;
   
   /**
  + * This simulates the multipart stream
    *
  - * @author Rick Rineholt 
  + * @author Rick Rineholt
    */
  +public class MultiPartRelatedInputStream extends java.io.FilterInputStream {
   
  - /** This simulates the multipart stream 
  -  *
  -  */
  -public class MultiPartRelatedInputStream extends java.io.FilterInputStream
  -{
  +    /** Field log           */
       protected static Log log =
               LogFactory.getLog(MultiPartRelatedInputStream.class.getName());
   
  +    /** Field MIME_MULTIPART_RELATED           */
       public static final String MIME_MULTIPART_RELATED = "multipart/related";
  -    protected java.util.HashMap parts =  new java.util.HashMap();
  -    protected java.util.LinkedList orderedParts =  new java.util.LinkedList();
  +
  +    /** Field parts           */
  +    protected java.util.HashMap parts = new java.util.HashMap();
  +
  +    /** Field orderedParts           */
  +    protected java.util.LinkedList orderedParts = new java.util.LinkedList();
  +
  +    /** Field rootPartLength           */
       protected int rootPartLength = 0;
  -    protected boolean closed = false; //If true the stream has been closed.
  -    protected boolean eos = false;  //This is set once the SOAP packet has reached the end of stream.
  +
  +    /** Field closed           */
  +    protected boolean closed = false;    // If true the stream has been closed.
  +
  +    /** Field eos           */
  +    protected boolean eos =
  +            false;    // This is set once the SOAP packet has reached the end of stream.
  +
       // protected java.io.InputStream is = null; //The orginal multipart/related stream.
  -    //This stream controls and manages the  boundary.
  -    protected org.apache.axis.attachments.BoundaryDelimitedStream boundaryDelimitedStream = null;
  -    protected java.io.InputStream soapStream = null; //Set the soap stream once found.
  -    protected java.io.InputStream soapStreamBDS= null; //Set to the boundary delimited stream assoc. with soap stream once found.
  +    // This stream controls and manages the  boundary.
  +
  +    /** Field boundaryDelimitedStream           */
  +    protected org.apache.axis.attachments.BoundaryDelimitedStream boundaryDelimitedStream =
  +            null;
  +
  +    /** Field soapStream           */
  +    protected java.io.InputStream soapStream =
  +            null;                            // Set the soap stream once found.
  +
  +    /** Field soapStreamBDS           */
  +    protected java.io.InputStream soapStreamBDS =
  +            null;    // Set to the boundary delimited stream assoc. with soap stream once found.
  +
  +    /** Field boundary           */
       protected byte[] boundary = null;
  -    protected java.io.ByteArrayInputStream cachedSOAPEnvelope = null; //Caches the soap stream if it is
  -              //Still open and a reference to read data in a later attachment occurs.
  -    protected String contentLocation= null;          
  -    protected String contentId= null;
  +
  +    /** Field cachedSOAPEnvelope           */
  +    protected java.io.ByteArrayInputStream cachedSOAPEnvelope =
  +            null;                            // Caches the soap stream if it is
  +
  +    // Still open and a reference to read data in a later attachment occurs.
  +
  +    /** Field contentLocation           */
  +    protected String contentLocation = null;
  +
  +    /** Field contentId           */
  +    protected String contentId = null;
   
       /**
        * Multipart stream.
        * @param the string that holds the contentType
  +     *
  +     * @param contentType
        * @param is the true input stream from where the source.
  +     *
  +     * @throws org.apache.axis.AxisFault
        */
  -    public MultiPartRelatedInputStream ( String contentType, java.io.InputStream is) throws org.apache.axis.AxisFault {
  -        super (null); //don't cache this stream.
  -        try {
  -            //First find the start and boundary parameters. There are real weird rules regard what
  -            // can be in real headers what needs to be escaped etc  let mail parse it.
  -            javax.mail.internet.ContentType ct = new javax.mail.internet.ContentType(contentType);
  +    public MultiPartRelatedInputStream(
  +            String contentType, java.io.InputStream is)
  +            throws org.apache.axis.AxisFault {
   
  -            String boundaryStr = "--" + ct.getParameter("boundary"); //The boundary with -- add as always the case.
  +        super(null);    // don't cache this stream.
   
  -            String rootPartContentId = ct.getParameter("start"); //Get the root part content.
  +        try {
  +
  +            // First find the start and boundary parameters. There are real weird rules regard what
  +            // can be in real headers what needs to be escaped etc  let mail parse it.
  +            javax.mail.internet.ContentType ct =
  +                    new javax.mail.internet.ContentType(contentType);
  +            String boundaryStr =
  +                    "--"
  +                    + ct.getParameter(
  +                            "boundary");    // The boundary with -- add as always the case.
  +            String rootPartContentId =
  +                    ct.getParameter("start");       // Get the root part content.
   
               if (rootPartContentId != null) {
                   rootPartContentId = rootPartContentId.trim();
  -                if (rootPartContentId.startsWith("<")) rootPartContentId = rootPartContentId.substring(1);
  -                if (rootPartContentId.endsWith(">")) rootPartContentId = rootPartContentId.substring(0, rootPartContentId.length() - 1);
  -                if (!rootPartContentId.startsWith("cid:")) rootPartContentId = "cid:" + rootPartContentId;
  +
  +                if (rootPartContentId.startsWith("<")) {
  +                    rootPartContentId = rootPartContentId.substring(1);
  +                }
  +
  +                if (rootPartContentId.endsWith(">")) {
  +                    rootPartContentId = rootPartContentId.substring(0,
  +                            rootPartContentId.length() - 1);
  +                }
  +
  +                if (!rootPartContentId.startsWith("cid:")) {
  +                    rootPartContentId = "cid:" + rootPartContentId;
  +                }
               }
   
  -            //if start is null then the first attachment is the rootpart
  -            //First read the start boundary -- this is done with brute force since the servlet may swallow the crlf between headers.
  +            // if start is null then the first attachment is the rootpart
  +            // First read the start boundary -- this is done with brute force since the servlet may swallow the crlf between headers.
               // after this we use the more efficient boundarydelimeted stream.  There should never be any data here anyway.
               byte[][] boundaryMarker = new byte[2][boundaryStr.length() + 2];
   
               is.read(boundaryMarker[0]);
   
               boundary = (boundaryStr + "\r\n").getBytes("US-ASCII");
  +
               int current = 0;
  -            //This just goes brute force one byte at a time to find the first boundary.  
  +
  +            // This just goes brute force one byte at a time to find the first boundary.
               // in most cases this just a crlf.
               for (boolean found = false; !found; ++current) {
  -                if (!(found = java.util.Arrays.equals(boundaryMarker[current & 0x1], boundary))) {
  -                    System.arraycopy(boundaryMarker[current & 0x1], 1, boundaryMarker[(current + 1) & 0x1], 0, boundaryMarker[0].length - 1);
  -                    if ( is.read(boundaryMarker[(current + 1) & 0x1], boundaryMarker[0].length - 1, 1) < 1) {
  +                if (!(found =
  +                        java.util.Arrays.equals(boundaryMarker[current & 0x1],
  +                                boundary))) {
  +                    System.arraycopy(boundaryMarker[current & 0x1], 1,
  +                            boundaryMarker[(current + 1) & 0x1], 0,
  +                            boundaryMarker[0].length - 1);
  +
  +                    if (is.read(
  +                            boundaryMarker[(current + 1) & 0x1],
  +                            boundaryMarker[0].length - 1, 1) < 1) {
                           throw new org.apache.axis.AxisFault(
  -                                JavaUtils.getMessage("mimeErrorNoBoundary",
  -                                new String(boundary)));
  +                                JavaUtils.getMessage(
  +                                        "mimeErrorNoBoundary", new String(boundary)));
                       }
                   }
               }
   
  -            //after the first boundary each boundary will have a cr lf at the beginning since after the data in any part there
  +            // after the first boundary each boundary will have a cr lf at the beginning since after the data in any part there
               // is a cr lf added to put the boundary at the begining of a line.
  -            boundaryStr = "\r\n"  + boundaryStr;
  +            boundaryStr = "\r\n" + boundaryStr;
               boundary = boundaryStr.getBytes("US-ASCII");
   
  -            //create the boundary delmited stream.
  -            boundaryDelimitedStream = new org.apache.axis.attachments.BoundaryDelimitedStream( is, boundary, 1024);
  +            // create the boundary delmited stream.
  +            boundaryDelimitedStream =
  +                    new org.apache.axis.attachments.BoundaryDelimitedStream(is,
  +                            boundary, 1024);
   
  -            //Now read through all potential streams until we have found the root part.
  +            // Now read through all potential streams until we have found the root part.
               String contentTransferEncoding = null;
  +
               do {
                   contentId = null;
                   contentTransferEncoding = null;
  -                //Read this attachments headers from the stream.  
  -                javax.mail.internet.InternetHeaders headers = new javax.mail.internet.InternetHeaders(boundaryDelimitedStream);
  -                //Use java mail utility to read through the headers.
  -                contentId = headers.getHeader(HTTPConstants.HEADER_CONTENT_ID, null);
  -                //Clean up the headers and remove any < >
  +
  +                // Read this attachments headers from the stream.
  +                javax.mail.internet.InternetHeaders headers =
  +                        new javax.mail.internet.InternetHeaders(
  +                                boundaryDelimitedStream);
  +
  +                // Use java mail utility to read through the headers.
  +                contentId = headers.getHeader(HTTPConstants.HEADER_CONTENT_ID,
  +                        null);
  +
  +                // Clean up the headers and remove any < >
                   if (contentId != null) {
                       contentId = contentId.trim();
  -                    if (contentId.startsWith("<")) contentId = contentId.substring(1);
  -                    if (contentId.endsWith(">")) contentId = contentId.substring(0, contentId.length() - 1);
  +
  +                    if (contentId.startsWith("<")) {
  +                        contentId = contentId.substring(1);
  +                    }
  +
  +                    if (contentId.endsWith(">")) {
  +                        contentId = contentId.substring(0, contentId.length()
  +                                - 1);
  +                    }
  +
                       contentId = contentId.trim();
  -                    if (!contentId.startsWith("cid:")) contentId = "cid:" + contentId; //make sure its identified as cid
  +
  +                    if (!contentId.startsWith("cid:")) {
  +                        contentId =
  +                                "cid:"
  +                                + contentId;        // make sure its identified as cid
  +                    }
                   }
   
  -                contentLocation = headers.getHeader(HTTPConstants.HEADER_CONTENT_LOCATION, null);
  +                contentLocation =
  +                        headers.getHeader(HTTPConstants.HEADER_CONTENT_LOCATION,
  +                                null);
  +
                   if (contentLocation != null) {
                       contentLocation = contentLocation.trim();
  -                    if (contentLocation.startsWith("<")) contentLocation = contentLocation.substring(1);
  -                    if (contentLocation.endsWith(">")) contentLocation = contentLocation.substring(0, contentLocation.length() - 1);
  +
  +                    if (contentLocation.startsWith("<")) {
  +                        contentLocation = contentLocation.substring(1);
  +                    }
  +
  +                    if (contentLocation.endsWith(">")) {
  +                        contentLocation = contentLocation.substring(
  +                                0, contentLocation.length() - 1);
  +                    }
  +
                       contentLocation = contentLocation.trim();
                   }
  -                contentType = headers.getHeader(HTTPConstants.HEADER_CONTENT_TYPE, null);
  -                if (contentType != null) contentType = contentType.trim();
   
  -                contentTransferEncoding = headers.getHeader(HTTPConstants.HEADER_CONTENT_TRANSFER_ENCODING, null);
  -                if(contentTransferEncoding != null ) contentTransferEncoding = contentTransferEncoding.trim();
  +                contentType =
  +                        headers.getHeader(HTTPConstants.HEADER_CONTENT_TYPE, null);
   
  -                java.io.InputStream decodedStream=  boundaryDelimitedStream;
  -                if(contentTransferEncoding != null && 0 != contentTransferEncoding.length()){
  -                    decodedStream= MimeUtility.decode(decodedStream, contentTransferEncoding);
  -                }
  -
  -                if (rootPartContentId != null && !rootPartContentId.equals( contentId)) { //This is a part that has come in prior to the root part. Need to buffer it up.
  -                    javax.activation.DataHandler dh = new javax.activation.DataHandler(new org.apache.axis.attachments.ManagedMemoryDataSource(decodedStream,
  -                   16 * 1024, contentType, true));
  -
  -                    AttachmentPart ap= new AttachmentPart(dh);
  -                    if(contentId != null) 
  -                        ap.addMimeHeader(HTTPConstants.HEADER_CONTENT_ID, contentId); 
  -
  -                    if (contentLocation != null)
  -                        ap.addMimeHeader(HTTPConstants.HEADER_CONTENT_LOCATION, contentLocation); 
  -                    
  -
  -                    for( java.util.Enumeration en= headers.getNonMatchingHeaders(
  -                            new String[]{HTTPConstants.HEADER_CONTENT_ID,
  -                             HTTPConstants.HEADER_CONTENT_LOCATION,
  -                             HTTPConstants.HEADER_CONTENT_TYPE }); en.hasMoreElements(); ){
  -                             javax.mail.Header header= (javax.mail.Header) en.nextElement();
  -                             String name= header.getName();
  -                             String value= header.getValue();
  -                             if(name != null && value != null){
  -                                 name= name.trim();
  -                                 if(name.length() != 0)
  -                                     ap.addMimeHeader(name , value); 
  -                             }
  -                    }         
  +                if (contentType != null) {
  +                    contentType = contentType.trim();
  +                }
   
  -                    addPart(contentId, contentLocation, ap);
  -                    boundaryDelimitedStream = boundaryDelimitedStream.getNextStream(); //Gets the next stream.
  +                contentTransferEncoding = headers.getHeader(
  +                        HTTPConstants.HEADER_CONTENT_TRANSFER_ENCODING, null);
  +
  +                if (contentTransferEncoding != null) {
  +                    contentTransferEncoding = contentTransferEncoding.trim();
                   }
   
  -            }
  -            while ( null != boundaryDelimitedStream &&  rootPartContentId != null && !rootPartContentId.equals( contentId) );
  +                java.io.InputStream decodedStream = boundaryDelimitedStream;
  +
  +                if ((contentTransferEncoding != null)
  +                        && (0 != contentTransferEncoding.length())) {
  +                    decodedStream = MimeUtility.decode(decodedStream,
  +                            contentTransferEncoding);
  +                }
   
  -            if (boundaryDelimitedStream  == null ) {
  +                if ((rootPartContentId != null) && !rootPartContentId.equals(
  +                        contentId)) {    // This is a part that has come in prior to the root part. Need to buffer it up.
  +                    javax.activation.DataHandler dh =
  +                            new javax.activation.DataHandler(
  +                                    new org.apache.axis.attachments.ManagedMemoryDataSource(
  +                                            decodedStream, 16 * 1024, contentType, true));
  +                    AttachmentPart ap = new AttachmentPart(dh);
  +
  +                    if (contentId != null) {
  +                        ap.addMimeHeader(HTTPConstants.HEADER_CONTENT_ID,
  +                                contentId);
  +                    }
  +
  +                    if (contentLocation != null) {
  +                        ap.addMimeHeader(HTTPConstants.HEADER_CONTENT_LOCATION,
  +                                contentLocation);
  +                    }
  +
  +                    for (java.util.Enumeration en =
  +                            headers.getNonMatchingHeaders(new String[]{
  +                                HTTPConstants.HEADER_CONTENT_ID,
  +                                HTTPConstants.HEADER_CONTENT_LOCATION,
  +                                HTTPConstants.HEADER_CONTENT_TYPE}); en.hasMoreElements();) {
  +                        javax.mail.Header header =
  +                                (javax.mail.Header) en.nextElement();
  +                        String name = header.getName();
  +                        String value = header.getValue();
  +
  +                        if ((name != null) && (value != null)) {
  +                            name = name.trim();
  +
  +                            if (name.length() != 0) {
  +                                ap.addMimeHeader(name, value);
  +                            }
  +                        }
  +                    }
  +
  +                    addPart(contentId, contentLocation, ap);
  +
  +                    boundaryDelimitedStream =
  +                            boundaryDelimitedStream.getNextStream();    // Gets the next stream.
  +                }
  +            } while ((null != boundaryDelimitedStream)
  +                    && (rootPartContentId != null)
  +                    && !rootPartContentId.equals(contentId));
  +
  +            if (boundaryDelimitedStream == null) {
                   throw new org.apache.axis.AxisFault(
                           JavaUtils.getMessage("noRoot", rootPartContentId));
               }
   
  -            soapStreamBDS= boundaryDelimitedStream;
  -            if(contentTransferEncoding != null && 0 != contentTransferEncoding.length()){
  -                    soapStream = MimeUtility.decode(boundaryDelimitedStream, contentTransferEncoding);
  -            }else soapStream = boundaryDelimitedStream; //This should be the SOAP part
  +            soapStreamBDS = boundaryDelimitedStream;
   
  -        //Read from the input stream all attachments prior to the root part.
  -        }
  -        catch (javax.mail.internet.ParseException e) {
  +            if ((contentTransferEncoding != null)
  +                    && (0 != contentTransferEncoding.length())) {
  +                soapStream = MimeUtility.decode(boundaryDelimitedStream,
  +                        contentTransferEncoding);
  +            } else {
  +                soapStream =
  +                        boundaryDelimitedStream;    // This should be the SOAP part
  +            }
  +
  +            // Read from the input stream all attachments prior to the root part.
  +        } catch (javax.mail.internet.ParseException e) {
               throw new org.apache.axis.AxisFault(
                       JavaUtils.getMessage("mimeErrorParsing", e.getMessage()));
  -        }
  -        catch ( java.io.IOException e) {
  +        } catch (java.io.IOException e) {
               throw new org.apache.axis.AxisFault(
                       JavaUtils.getMessage("readError", e.getMessage()));
  -        }
  -        catch ( javax.mail.MessagingException e) {
  +        } catch (javax.mail.MessagingException e) {
               throw new org.apache.axis.AxisFault(
                       JavaUtils.getMessage("readError", e.getMessage()));
           }
       }
   
  -    public Part getAttachmentByReference( final String[] id ) throws org.apache.axis.AxisFault {  // if CID should still have CID: prefix.  
  -        //First see if we have read it in yet.
  -        Part ret = null; 
  -        for(int i= id.length -1; ret== null && i > -1; --i){
  -             ret=(AttachmentPart) parts.get(id[i]);
  +    /**
  +     * Method getAttachmentByReference
  +     *
  +     * @param id
  +     *
  +     * @return
  +     *
  +     * @throws org.apache.axis.AxisFault
  +     */
  +    public Part getAttachmentByReference(final String[] id)
  +            throws org.apache.axis.AxisFault {    // if CID should still have CID: prefix.
  +
  +        // First see if we have read it in yet.
  +        Part ret = null;
  +
  +        for (int i = id.length - 1; (ret == null) && (i > -1); --i) {
  +            ret = (AttachmentPart) parts.get(id[i]);
           }
   
  -        if ( null == ret) {
  +        if (null == ret) {
               ret = readTillFound(id);
           }
  +
           log.debug(JavaUtils.getMessage("return02",
  -                "getAttachmentByReference(\"" + id + "\"",
  -                (ret == null ? "null" : ret.toString())));
  +                "getAttachmentByReference(\"" + id
  +                + "\"", ((ret == null)
  +                ? "null"
  +                : ret.toString())));
  +
           return ret;
       }
   
  -    protected void addPart(String contentId, String locationId, AttachmentPart  ap) {
  -        if (contentId != null && contentId.trim().length() != 0) parts.put(contentId, ap);
  -        if (locationId != null && locationId.trim().length() != 0)parts.put(locationId, ap);
  -        orderedParts.add(ap); 
  +    /**
  +     * Method addPart
  +     *
  +     * @param contentId
  +     * @param locationId
  +     * @param ap
  +     */
  +    protected void addPart(String contentId, String locationId,
  +                           AttachmentPart ap) {
  +
  +        if ((contentId != null) && (contentId.trim().length() != 0)) {
  +            parts.put(contentId, ap);
  +        }
  +
  +        if ((locationId != null) && (locationId.trim().length() != 0)) {
  +            parts.put(locationId, ap);
  +        }
  +
  +        orderedParts.add(ap);
       }
   
  -    protected final static String[] READ_ALL= { " * \0 ".intern()}; //Shouldn't never match
  +    /** Field READ_ALL           */
  +    protected final static String[] READ_ALL = {
  +        " * \0 ".intern()};    // Shouldn't never match
   
  -    protected void readAll( ) throws org.apache.axis.AxisFault {
  -       readTillFound(READ_ALL ); 
  +    /**
  +     * Method readAll
  +     *
  +     * @throws org.apache.axis.AxisFault
  +     */
  +    protected void readAll() throws org.apache.axis.AxisFault {
  +        readTillFound(READ_ALL);
       }
   
  -    public java.util.Collection getAttachments() throws org.apache.axis.AxisFault {
  -       readAll();
  -       return orderedParts; 
  +    /**
  +     * Method getAttachments
  +     *
  +     * @return
  +     *
  +     * @throws org.apache.axis.AxisFault
  +     */
  +    public java.util.Collection getAttachments()
  +            throws org.apache.axis.AxisFault {
  +
  +        readAll();
  +
  +        return orderedParts;
       }
  -    /** 
  +
  +    /**
        * This will read streams in till the one that is needed is found.
        * @param The id is the stream being sought. TODO today its only handles CID. all ContentId streams
        *         should be prefixed by "cid:"
  +     *
  +     * @param id
  +     *
  +     * @return
  +     *
  +     * @throws org.apache.axis.AxisFault
        */
  +    protected Part readTillFound(final String[] id)
  +            throws org.apache.axis.AxisFault {
  +
  +        if (boundaryDelimitedStream == null) {
  +            return null;    // The whole stream has been consumed already
  +        }
   
  -    protected Part readTillFound( final String[] id) throws org.apache.axis.AxisFault {
  -        if (boundaryDelimitedStream == null) return null; //The whole stream has been consumed already
           Part ret = null;
   
           try {
  -            if ( soapStreamBDS == boundaryDelimitedStream ) { //Still on the SOAP stream.
  -                if (!eos) { //The SOAP packet has not been fully read yet. Need to store it away.
  -
  -                    java.io.ByteArrayOutputStream soapdata = new java.io.ByteArrayOutputStream(1024 * 8);
  -                    byte[] buf = new byte[1024 * 16];
  +            if (soapStreamBDS
  +                    == boundaryDelimitedStream) {    // Still on the SOAP stream.
  +                if (!eos) {    // The SOAP packet has not been fully read yet. Need to store it away.
  +                    java.io.ByteArrayOutputStream soapdata =
  +                            new java.io.ByteArrayOutputStream(1024 * 8);
  +                    byte[] buf =
  +                            new byte[1024 * 16];
                       int byteread = 0;
   
                       do {
                           byteread = soapStream.read(buf);
  -                        if (byteread > 0) soapdata.write(buf, 0, byteread);
  -                    }
  -                    while (byteread > -1);
  +
  +                        if (byteread > 0) {
  +                            soapdata.write(buf, 0, byteread);
  +                        }
  +                    } while (byteread > -1);
  +
                       soapdata.close();
  -                    soapStream = new java.io.ByteArrayInputStream( soapdata.toByteArray());
  +
  +                    soapStream = new java.io.ByteArrayInputStream(
  +                            soapdata.toByteArray());
                   }
  -                boundaryDelimitedStream = boundaryDelimitedStream.getNextStream();
  +
  +                boundaryDelimitedStream =
  +                        boundaryDelimitedStream.getNextStream();
               }
  -               //Now start searching for the data.
   
  -            if(null!= boundaryDelimitedStream )
  -            do {
  -                String contentType = null;
  -                String contentId = null;
  -                String contentTransferEncoding = null;
  -                String contentLocation = null;
  +            // Now start searching for the data.
  +            if (null != boundaryDelimitedStream) {
  +                do {
  +                    String contentType = null;
  +                    String contentId = null;
  +                    String contentTransferEncoding = null;
  +                    String contentLocation = null;
  +
  +                    // Read this attachments headers from the stream.
  +                    javax.mail.internet.InternetHeaders headers =
  +                            new javax.mail.internet.InternetHeaders(
  +                                    boundaryDelimitedStream);
  +
  +                    contentId = headers.getHeader("Content-ID", null);
  +
  +                    if (contentId != null) {
  +                        contentId = contentId.trim();
  +
  +                        if (contentId.startsWith("<")) {
  +                            contentId = contentId.substring(1);
  +                        }
  +
  +                        if (contentId.endsWith(">")) {
  +                            contentId =
  +                                    contentId.substring(0, contentId.length() - 1);
  +                        }
  +
  +                        if (!contentId.startsWith("cid:")) {
  +                            contentId = "cid:" + contentId;
  +                        }
   
  -                //Read this attachments headers from the stream.  
  -                javax.mail.internet.InternetHeaders headers = new javax.mail.internet.InternetHeaders(boundaryDelimitedStream);
  +                        contentId = contentId.trim();
  +                    }
   
  -                contentId = headers.getHeader("Content-ID", null);
  -                if (contentId != null) {
  -                    contentId = contentId.trim();
  -                    if (contentId.startsWith("<")) contentId = contentId.substring(1);
  -                    if (contentId.endsWith(">")) contentId = contentId.substring(0, contentId.length() - 1);
  -                    if (!contentId.startsWith("cid:")) contentId = "cid:" + contentId;
  -                    contentId = contentId.trim();
  -                }
  -                contentType = headers.getHeader(HTTPConstants.HEADER_CONTENT_TYPE, null);
  -                if (contentType != null) contentType = contentType.trim();
  -                contentLocation = headers.getHeader(HTTPConstants.HEADER_CONTENT_LOCATION, null);
  -                if (contentLocation != null) contentLocation = contentLocation.trim();
  -                contentTransferEncoding = headers.getHeader(HTTPConstants.HEADER_CONTENT_TRANSFER_ENCODING , null);
  -                if (contentTransferEncoding != null ) contentTransferEncoding = contentTransferEncoding.trim();
  -
  -                java.io.InputStream decodedStream=  boundaryDelimitedStream;
  -                if(contentTransferEncoding != null && 0 != contentTransferEncoding.length()){
  -                    decodedStream= MimeUtility.decode(decodedStream, contentTransferEncoding);
  -                }
  -
  -                DataHandler dh= new DataHandler(new ManagedMemoryDataSource(decodedStream, 1024, contentType, true));
  -
  -                AttachmentPart ap= new AttachmentPart(dh);
  -                if(contentId != null) 
  -                    ap.addMimeHeader(HTTPConstants.HEADER_CONTENT_ID, contentId); 
  -
  -                if (contentLocation != null)
  -                    ap.addMimeHeader(HTTPConstants.HEADER_CONTENT_LOCATION, contentLocation); 
  -                
  -
  -                for( java.util.Enumeration en= headers.getNonMatchingHeaders(
  -                        new String[]{HTTPConstants.HEADER_CONTENT_ID,
  -                         HTTPConstants.HEADER_CONTENT_LOCATION,
  -                         HTTPConstants.HEADER_CONTENT_TYPE }); en.hasMoreElements(); ){
  -                         javax.mail.Header header= (javax.mail.Header) en.nextElement();
  -                         String name= header.getName();
  -                         String value= header.getValue();
  -                         if(name != null && value != null){
  -                             name= name.trim();
  -                             if(name.length() != 0)
  -                                 ap.addMimeHeader(name , value); 
  -                         }
  -                }         
  -
  -                addPart(contentId, contentLocation, ap);
  -
  -                for(int i= id.length -1; ret== null && i > -1; --i){
  -                    if (contentId != null && id[i].equals( contentId)) { //This is the part being sought
  -                        ret = ap;
  -                    }else if(contentLocation != null && id[i].equals( contentLocation)){
  -                        ret = ap;
  +                    contentType =
  +                            headers.getHeader(HTTPConstants.HEADER_CONTENT_TYPE,
  +                                    null);
  +
  +                    if (contentType != null) {
  +                        contentType = contentType.trim();
                       }
  -                }
   
  -                boundaryDelimitedStream = boundaryDelimitedStream.getNextStream();
  +                    contentLocation =
  +                            headers.getHeader(HTTPConstants.HEADER_CONTENT_LOCATION,
  +                                    null);
  +
  +                    if (contentLocation != null) {
  +                        contentLocation = contentLocation.trim();
  +                    }
  +
  +                    contentTransferEncoding = headers.getHeader(
  +                            HTTPConstants.HEADER_CONTENT_TRANSFER_ENCODING, null);
  +
  +                    if (contentTransferEncoding != null) {
  +                        contentTransferEncoding =
  +                                contentTransferEncoding.trim();
  +                    }
  +
  +                    java.io.InputStream decodedStream = boundaryDelimitedStream;
  +
  +                    if ((contentTransferEncoding != null)
  +                            && (0 != contentTransferEncoding.length())) {
  +                        decodedStream =
  +                                MimeUtility.decode(decodedStream,
  +                                        contentTransferEncoding);
  +                    }
  +
  +                    DataHandler dh = new DataHandler(
  +                            new ManagedMemoryDataSource(
  +                                    decodedStream, 1024, contentType, true));
  +                    AttachmentPart ap = new AttachmentPart(dh);
  +
  +                    if (contentId != null) {
  +                        ap.addMimeHeader(HTTPConstants.HEADER_CONTENT_ID,
  +                                contentId);
  +                    }
   
  +                    if (contentLocation != null) {
  +                        ap.addMimeHeader(HTTPConstants.HEADER_CONTENT_LOCATION,
  +                                contentLocation);
  +                    }
  +
  +                    for (java.util.Enumeration en =
  +                            headers.getNonMatchingHeaders(new String[]{
  +                                HTTPConstants.HEADER_CONTENT_ID,
  +                                HTTPConstants.HEADER_CONTENT_LOCATION,
  +                                HTTPConstants.HEADER_CONTENT_TYPE}); en.hasMoreElements();) {
  +                        javax.mail.Header header =
  +                                (javax.mail.Header) en.nextElement();
  +                        String name = header.getName();
  +                        String value = header.getValue();
  +
  +                        if ((name != null) && (value != null)) {
  +                            name = name.trim();
  +
  +                            if (name.length() != 0) {
  +                                ap.addMimeHeader(name, value);
  +                            }
  +                        }
  +                    }
  +
  +                    addPart(contentId, contentLocation, ap);
  +
  +                    for (int i = id.length - 1; (ret == null) && (i > -1);
  +                         --i) {
  +                        if ((contentId != null) && id[i].equals(
  +                                contentId)) {    // This is the part being sought
  +                            ret = ap;
  +                        } else if ((contentLocation != null)
  +                                && id[i].equals(contentLocation)) {
  +                            ret = ap;
  +                        }
  +                    }
  +
  +                    boundaryDelimitedStream =
  +                            boundaryDelimitedStream.getNextStream();
  +                } while ((null == ret) && (null != boundaryDelimitedStream));
               }
  -            while (null == ret && null != boundaryDelimitedStream);
  -        }
  -        catch (Exception e) {
  +        } catch (Exception e) {
               throw org.apache.axis.AxisFault.makeFault(e);
           }
   
  @@ -381,62 +618,101 @@
       }
   
       /**
  -     * Return the content location. 
  +     * Return the content location.
        * @return the Content-Location of the stream.
        *   Null if no content-location specified.
        */
  -    public String getContentLocation(){
  +    public String getContentLocation() {
           return contentLocation;
       }
   
       /**
  -     * Return the content id of the stream 
  +     * Return the content id of the stream
        * @return the Content-Location of the stream.
        *   Null if no content-location specified.
        */
  -    public String getContentId(){
  +    public String getContentId() {
           return contentId;
       }
   
       /**
  -     * Read the root stream. 
  +     * Read the root stream.
  +     *
  +     * @param b
  +     * @param off
  +     * @param len
  +     *
  +     * @return
  +     *
  +     * @throws java.io.IOException
        */
  -
       public int read(byte[] b, int off, int len) throws java.io.IOException {
  +
           if (closed) {
               throw new java.io.IOException(JavaUtils.getMessage("streamClosed"));
           }
  +
           if (eos) {
               return -1;
           }
  +
           int read = soapStream.read(b, off, len);
   
           if (read < 0) {
               eos = true;
           }
  +
           return read;
       }
   
  +    /**
  +     * Method read
  +     *
  +     * @param b
  +     *
  +     * @return
  +     *
  +     * @throws java.io.IOException
  +     */
       public int read(byte[] b) throws java.io.IOException {
           return read(b, 0, b.length);
       }
   
  +    /**
  +     * Method read
  +     *
  +     * @return
  +     *
  +     * @throws java.io.IOException
  +     */
       public int read() throws java.io.IOException {
  +
           if (closed) {
               throw new java.io.IOException(JavaUtils.getMessage("streamClosed"));
           }
  +
           if (eos) {
               return -1;
           }
  +
           int ret = soapStream.read();
  +
           if (ret < 0) {
               eos = true;
           }
  +
           return ret;
       }
   
  +    /**
  +     * Method close
  +     *
  +     * @throws java.io.IOException
  +     */
       public void close() throws java.io.IOException {
  +
           closed = true;
  +
           soapStream.close();
       }
   }
  
  
  

Mime
View raw message