Return-Path: Delivered-To: apmail-ws-axis-dev-archive@www.apache.org Received: (qmail 42357 invoked from network); 4 Jul 2007 04:15:48 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 4 Jul 2007 04:15:48 -0000 Received: (qmail 76300 invoked by uid 500); 4 Jul 2007 04:15:50 -0000 Delivered-To: apmail-ws-axis-dev-archive@ws.apache.org Received: (qmail 76053 invoked by uid 500); 4 Jul 2007 04:15:49 -0000 Mailing-List: contact axis-cvs-help@ws.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: List-Id: Delivered-To: mailing list axis-cvs@ws.apache.org Received: (qmail 76042 invoked by uid 500); 4 Jul 2007 04:15:49 -0000 Delivered-To: apmail-ws-axis2-cvs@ws.apache.org Received: (qmail 76039 invoked by uid 99); 4 Jul 2007 04:15:49 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 03 Jul 2007 21:15:49 -0700 X-ASF-Spam-Status: No, hits=-99.5 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 03 Jul 2007 21:15:46 -0700 Received: by eris.apache.org (Postfix, from userid 65534) id C22AD1A981D; Tue, 3 Jul 2007 21:15:25 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r553066 - /webservices/axis2/trunk/java/modules/saaj/src/org/apache/axis2/saaj/AttachmentPartImpl.java Date: Wed, 04 Jul 2007 04:15:25 -0000 To: axis2-cvs@ws.apache.org From: gawor@apache.org X-Mailer: svnmailer-1.1.0 Message-Id: <20070704041525.C22AD1A981D@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: gawor Date: Tue Jul 3 21:15:24 2007 New Revision: 553066 URL: http://svn.apache.org/viewvc?view=rev&rev=553066 Log: implement setBase64Content/getBase64Content properly Modified: webservices/axis2/trunk/java/modules/saaj/src/org/apache/axis2/saaj/AttachmentPartImpl.java Modified: webservices/axis2/trunk/java/modules/saaj/src/org/apache/axis2/saaj/AttachmentPartImpl.java URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/saaj/src/org/apache/axis2/saaj/AttachmentPartImpl.java?view=diff&rev=553066&r1=553065&r2=553066 ============================================================================== --- webservices/axis2/trunk/java/modules/saaj/src/org/apache/axis2/saaj/AttachmentPartImpl.java (original) +++ webservices/axis2/trunk/java/modules/saaj/src/org/apache/axis2/saaj/AttachmentPartImpl.java Tue Jul 3 21:15:24 2007 @@ -33,11 +33,11 @@ import javax.xml.soap.SOAPException; import javax.xml.transform.stream.StreamSource; import java.awt.image.BufferedImage; +import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; -import java.io.PushbackInputStream; import java.util.Iterator; /** @@ -390,11 +390,11 @@ } public InputStream getBase64Content() throws SOAPException { + byte[] rawData = getRawContentBytes(); + ByteArrayOutputStream out = new ByteArrayOutputStream(); try { - if (dataHandler == null) { - throw new SOAPException(); - } - return dataHandler.getInputStream(); + Base64.encode(rawData, 0, rawData.length, out); + return new ByteArrayInputStream(out.toByteArray()); } catch (IOException e) { throw new SOAPException(e); } @@ -465,47 +465,21 @@ if (content == null) { throw new SOAPException("Content is null"); } + OutputStream outputStream = new ByteArrayOutputStream(); + byte[] buffer = new byte[1024]; + int read; try { - int size = content.available(); - PushbackInputStream pushbackInputStream; - if (size > 0) { - pushbackInputStream = new PushbackInputStream(content, size); - } else { - pushbackInputStream = new PushbackInputStream(content); + while ((read = content.read(buffer, 0, buffer.length)) > 0) { + outputStream.write(buffer, 0, read); } - - if (isValidBase64Encoding(pushbackInputStream)) { - setContent(pushbackInputStream, contentType); + String contentString = outputStream.toString(); + if (Base64.isValidBase64Encoding(contentString)) { + setContent(Base64.decode(contentString), contentType); } else { throw new SOAPException("Not a valid Base64 encoding"); } - } catch (Exception ex) { + } catch (IOException ex) { throw new SOAPException(ex); - } - } - - /* - * check if the given InputStream contains valid Base64 Encoding - */ - private boolean isValidBase64Encoding(PushbackInputStream pushbackInputStream) { - int size; - try { - size = pushbackInputStream.available(); - if (size == 0) { - return true; - } - byte[] buffer = new byte[size]; - int read = pushbackInputStream.read(buffer, 0, size); - - OutputStream outputStream = new ByteArrayOutputStream(); - outputStream.write(buffer); - String contentString = outputStream.toString(); - outputStream.close(); - pushbackInputStream.unread(buffer, 0, read); - - return Base64.isValidBase64Encoding(contentString); - } catch (Exception e) { - return false; } } --------------------------------------------------------------------- To unsubscribe, e-mail: axis-cvs-unsubscribe@ws.apache.org For additional commands, e-mail: axis-cvs-help@ws.apache.org