DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG 
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://nagoya.apache.org/bugzilla/show_bug.cgi?id=15593>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND 
INSERTED IN THE BUG DATABASE.

http://nagoya.apache.org/bugzilla/show_bug.cgi?id=15593

AttachmentPart.getSize() reports wrong value

           Summary: AttachmentPart.getSize() reports wrong value
           Product: Axis
           Version: current (nightly)
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: Normal
          Priority: Other
         Component: Serialization/Deserialization
        AssignedTo: [EMAIL PROTECTED]
        ReportedBy: [EMAIL PROTECTED]


There is an inner class ByteBuffer that provides direct access to the 
ByteArrayOutputStream's buffer. The problem is that no modification is made 
even if that buffer is not full. In a simple example when you have 5 bytes in 
your attachment, size will be reported as 32.

Since there is no clear reason to use ByteBuffer in that code, my patch 
replaces it with ByteArrayOutputStream

JUnit test case:
        public void testBadAttSize() throws Exception{
                SOAPEnvelope env=new SOAPEnvelope();
                Message msg=new Message(env);
                class Src implements DataSource{
                        InputStream m_src;
                        String m_type;

                        public Src(InputStream data, String type){
                                m_src=data;
                                m_type=type;
                        }
                        public String getContentType(){
                                return m_type;
                        }
                        public InputStream getInputStream() throws IOException{
                                m_src.reset();
                                return m_src;
                        }
                        public String getName(){
                                return "Some-Data";
                        }
                        public OutputStream getOutputStream(){
                                throw new UnsupportedOperationException("I 
don't give output streams");
                        }
                }
                ByteArrayInputStream ins=new ByteArrayInputStream(new byte[5]);
                DataHandler dh=new DataHandler(new Src(ins,"text/plain"));
                AttachmentPart part=(AttachmentPart)msg.createAttachmentPart
(dh);
                assertEquals("Size should match",5,part.getSize());
        }


Patch to the AttachmentPart.java#1.32
Index: AttachmentPart.java
===================================================================
RCS file: /home/cvspublic/xml-
axis/java/src/org/apache/axis/attachments/AttachmentPart.java,v
retrieving revision 1.32
diff -r1.32 AttachmentPart.java
454c454
<         ByteBuffer bout = new ByteBuffer();
---
>         java.io.ByteArrayOutputStream bout = new java.io.ByteArrayOutputStream
();
461,464c461
<         byte bytes[] = bout.getBytes();
<         if (bytes != null)
<             return bytes.length;
<         return -1;
---
>         return bout.size();
480,484d476
<     private class ByteBuffer extends java.io.ByteArrayOutputStream {
<         byte[] getBytes() {
<             return super.buf;
<         }
<     }

Reply via email to