Author: veithen
Date: Sun Jul 19 23:28:29 2009
New Revision: 795660

URL: http://svn.apache.org/viewvc?rev=795660&view=rev
Log:
* Generalized the optimization done by BufferUtils for BAAOutputStream (direct 
copy from input stream to output stream) so that it can be leveraged by other 
OutputStream implementations as well.
* Changed the blob classes to use that optimization.

Added:
    
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/ext/io/
    
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/ext/io/ReadFromSupport.java
   (with props)
    
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/ext/io/StreamCopyException.java
   (with props)
    
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/blob/BlobOutputStream.java
   (with props)
Modified:
    
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/impl/BufferUtils.java
    
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/utils/BAAOutputStream.java
    
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/blob/MemoryBlob.java
    
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/blob/OverflowBlob.java
    
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/blob/WritableBlob.java
    
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/blob/WritableBlobTestBase.java

Modified: 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/impl/BufferUtils.java
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/impl/BufferUtils.java?rev=795660&r1=795659&r2=795660&view=diff
==============================================================================
--- 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/impl/BufferUtils.java
 (original)
+++ 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/impl/BufferUtils.java
 Sun Jul 19 23:28:29 2009
@@ -29,6 +29,7 @@
 import javax.activation.DataHandler;
 
 import org.apache.axiom.attachments.utils.BAAOutputStream;
+import org.apache.axiom.ext.io.ReadFromSupport;
 import org.apache.axiom.util.activation.DataSourceUtils;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -72,7 +73,7 @@
         
         // If this is a BAAOutputStream, use the optimized method
         if (ENABLE_BAAOS_OPT && os instanceof BAAOutputStream) {
-            inputStream2BAAOutputStream(is, (BAAOutputStream) os, 
Long.MAX_VALUE);
+            ((ReadFromSupport)os).readFrom(is, Long.MAX_VALUE);
             return;
         }
         
@@ -108,9 +109,9 @@
                                                 int limit) 
         throws IOException {
         
-        // If this is a BAAOutputStream, use the optimized method
-        if (ENABLE_BAAOS_OPT && os instanceof BAAOutputStream) {
-            return (int) inputStream2BAAOutputStream(is, (BAAOutputStream) os, 
(long) limit);
+        // If the stream implements ReadFromSupport, use the optimized method
+        if (ENABLE_BAAOS_OPT && os instanceof ReadFromSupport) {
+            return (int) ((ReadFromSupport)os).readFrom(is, limit);
         }
             
         byte[] buffer = getTempBuffer();

Modified: 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/utils/BAAOutputStream.java
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/utils/BAAOutputStream.java?rev=795660&r1=795659&r2=795660&view=diff
==============================================================================
--- 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/utils/BAAOutputStream.java
 (original)
+++ 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/utils/BAAOutputStream.java
 Sun Jul 19 23:28:29 2009
@@ -19,6 +19,8 @@
 package org.apache.axiom.attachments.utils;
 
 import org.apache.axiom.attachments.impl.BufferUtils;
+import org.apache.axiom.ext.io.ReadFromSupport;
+import org.apache.axiom.ext.io.StreamCopyException;
 
 import java.io.IOException;
 import java.io.InputStream;
@@ -32,7 +34,7 @@
  * byte[].  Using several non-contiguous chunks reduces 
  * memory copy and resizing.
  */
-public class BAAOutputStream extends OutputStream {
+public class BAAOutputStream extends OutputStream implements ReadFromSupport {
 
     ArrayList data = new ArrayList();
     final static int BUFFER_SIZE = BufferUtils.BUFFER_LEN;
@@ -88,6 +90,13 @@
      * @return bytesReceived
      */
     public long receive(InputStream is, long maxRead) throws IOException {
+        return readFrom(is, maxRead);
+    }
+    
+    public long readFrom(InputStream is, long maxRead) throws 
StreamCopyException {
+        if (maxRead == -1) {
+            maxRead = Long.MAX_VALUE;
+        }
         long bytesReceived = 0;
         
         // Now directly write to the buffers
@@ -98,7 +107,12 @@
             int len = (int) Math.min(BUFFER_SIZE - index, 
maxRead-bytesReceived);
             
             // Now get the bytes
-            int bytesRead = is.read(currBuffer, index, len);
+            int bytesRead;
+            try {
+                bytesRead = is.read(currBuffer, index, len);
+            } catch (IOException ex) {
+                throw new StreamCopyException(StreamCopyException.READ, ex);
+            }
             if (bytesRead >= 0) {
                 bytesReceived += bytesRead;
                 index += bytesRead;

Added: 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/ext/io/ReadFromSupport.java
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/ext/io/ReadFromSupport.java?rev=795660&view=auto
==============================================================================
--- 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/ext/io/ReadFromSupport.java
 (added)
+++ 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/ext/io/ReadFromSupport.java
 Sun Jul 19 23:28:29 2009
@@ -0,0 +1,48 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.axiom.ext.io;
+
+import java.io.InputStream;
+
+/**
+ * Optional interface implemented by {...@link java.io.OutputStream} 
implementations that support
+ * transferring data from an {...@link InputStream}. This interface may be 
used to avoid allocating
+ * a temporary buffer when there is a need to copy data from an input stream 
to an output stream.
+ */
+public interface ReadFromSupport {
+    /**
+     * Read data from the given input stream and write it to this output 
stream.
+     * The method transfers data until one of the following conditions is met:
+     * <ul>
+     *   <li>The end of the input stream is reached.
+     *   <li>The value of the <code>length</code> argument is different from 
<code>-1</code>
+     *       and the number of bytes transferred is equal to 
<code>length</code>.
+     * </ul>
+     * 
+     * @param in
+     *            An input stream to read data from. This method will not 
close the stream.
+     * @param length
+     *            the number of bytes to transfer, or <code>-1</code> if the 
method should
+     *            transfer data until the end of the input stream is reached
+     * @throws StreamCopyException
+     * @return the number of bytes transferred
+     */
+    long readFrom(InputStream inputStream, long length) throws 
StreamCopyException;
+}

Propchange: 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/ext/io/ReadFromSupport.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/ext/io/StreamCopyException.java
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/ext/io/StreamCopyException.java?rev=795660&view=auto
==============================================================================
--- 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/ext/io/StreamCopyException.java
 (added)
+++ 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/ext/io/StreamCopyException.java
 Sun Jul 19 23:28:29 2009
@@ -0,0 +1,74 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.axiom.ext.io;
+
+import java.io.IOException;
+
+/**
+ * Signals that an I/O exception occurred while copying data from an input 
stream (or other data
+ * source) to an output stream (or other data sink). The exception wraps the 
original
+ * {...@link IOException} together with information about the type of 
operation (read or write) that
+ * failed.
+ */
+public class StreamCopyException extends IOException {
+    private static final long serialVersionUID = -6489101119109339448L;
+    
+    /**
+     * Indicates that the wrapped exception was triggered while reading from 
the input stream
+     * (or data source).
+     */
+    public static final int READ = 1;
+    
+    /**
+     * Indicates that the wrapped exception was triggered while writing to the 
output stream
+     * (or data sink).
+     */
+    public static final int WRITE = 2;
+    
+    private final int operation;
+    
+    /**
+     * Constructor.
+     * 
+     * @param operation
+     *            indicates the type of operation that caused the exception; 
must be {...@link #READ}
+     *            or {...@link #WRITE}
+     * @param cause
+     *            the wrapped exception
+     */
+    public StreamCopyException(int operation, IOException cause) {
+        this.operation = operation;
+        initCause(cause);
+    }
+
+    /**
+     * Get information about the type of operation that fails.
+     * 
+     * @return one of {...@link #READ} or {...@link #WRITE}
+     */
+    public int getOperation() {
+        return operation;
+    }
+
+    public String getMessage() {
+        return operation == READ ? "Error reading from source"
+                                 : "Error writing to destination";
+    }
+}

Propchange: 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/ext/io/StreamCopyException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/blob/BlobOutputStream.java
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/blob/BlobOutputStream.java?rev=795660&view=auto
==============================================================================
--- 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/blob/BlobOutputStream.java
 (added)
+++ 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/blob/BlobOutputStream.java
 Sun Jul 19 23:28:29 2009
@@ -0,0 +1,43 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.axiom.util.blob;
+
+import java.io.InputStream;
+import java.io.OutputStream;
+
+import org.apache.axiom.ext.io.ReadFromSupport;
+import org.apache.axiom.ext.io.StreamCopyException;
+
+/**
+ * Output stream that is used to write to a blob. Instances of this class are 
returned by the
+ * {...@link WritableBlob#getOutputStream()} method.
+ */
+public abstract class BlobOutputStream extends OutputStream implements 
ReadFromSupport {
+    /**
+     * Get the blob to which this output stream belongs.
+     * 
+     * @return the blob
+     */
+    public abstract WritableBlob getBlob();
+
+    public long readFrom(InputStream inputStream, long length) throws 
StreamCopyException {
+        return getBlob().readFrom(inputStream, length);
+    }
+}

Propchange: 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/blob/BlobOutputStream.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/blob/MemoryBlob.java
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/blob/MemoryBlob.java?rev=795660&r1=795659&r2=795660&view=diff
==============================================================================
--- 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/blob/MemoryBlob.java
 (original)
+++ 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/blob/MemoryBlob.java
 Sun Jul 19 23:28:29 2009
@@ -26,11 +26,16 @@
 import java.util.List;
 
 import org.apache.axiom.attachments.impl.BufferUtils;
+import org.apache.axiom.ext.io.StreamCopyException;
 
 public class MemoryBlob implements WritableBlob {
     final static int BUFFER_SIZE = BufferUtils.BUFFER_LEN;
     
-    class OutputStreamImpl extends OutputStream {
+    class OutputStreamImpl extends BlobOutputStream {
+        public WritableBlob getBlob() {
+            return MemoryBlob.this;
+        }
+
         public void write(byte[] b, int off, int len) throws IOException {
            int total = 0;
            while (total < len) {
@@ -158,7 +163,7 @@
         return (BUFFER_SIZE * (data.size()-1)) + index;
     }
 
-    public OutputStream getOutputStream() {
+    public BlobOutputStream getOutputStream() {
         if (data != null) {
             throw new IllegalStateException();
         } else {
@@ -167,11 +172,14 @@
         }
     }
 
-    public void readFrom(InputStream in, boolean commit) throws IOException {
+    public long readFrom(InputStream in, long length, boolean commit) throws 
StreamCopyException {
         if (data == null) {
             init();
         }
         
+        if (length == -1) {
+            length = Long.MAX_VALUE;
+        }
         long bytesReceived = 0;
         
         // Now directly write to the buffers
@@ -179,26 +187,36 @@
         while (!done) {
             
             // Don't get more than will fit in the current buffer
-            int len = BUFFER_SIZE - index;
+            int len = (int) Math.min(BUFFER_SIZE - index, 
length-bytesReceived);
             
             // Now get the bytes
-            int bytesRead = in.read(currBuffer, index, len);
+            int bytesRead;
+            try {
+                bytesRead = in.read(currBuffer, index, len);
+            } catch (IOException ex) {
+                throw new StreamCopyException(StreamCopyException.READ, ex);
+            }
             if (bytesRead >= 0) {
                 bytesReceived += bytesRead;
                 index += bytesRead;
                 if (index >= BUFFER_SIZE) {
                     addBuffer();
                 }
+                if (bytesReceived >= length) {
+                    done = true;
+                }
             } else {
                 done = true;
             }
         }
         
         committed = commit;
+        
+        return bytesReceived;
     }
 
-    public void readFrom(InputStream in) throws IOException {
-        readFrom(in, data == null);
+    public long readFrom(InputStream in, long length) throws 
StreamCopyException {
+        return readFrom(in, length, data == null);
     }
 
     public InputStream getInputStream() throws IOException {

Modified: 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/blob/OverflowBlob.java
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/blob/OverflowBlob.java?rev=795660&r1=795659&r2=795660&view=diff
==============================================================================
--- 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/blob/OverflowBlob.java
 (original)
+++ 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/blob/OverflowBlob.java
 Sun Jul 19 23:28:29 2009
@@ -27,6 +27,7 @@
 import java.io.OutputStream;
 
 import org.apache.axiom.attachments.impl.BufferUtils;
+import org.apache.axiom.ext.io.StreamCopyException;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
@@ -49,10 +50,14 @@
     static final int STATE_UNCOMMITTED = 1;
     static final int STATE_COMMITTED = 2;
     
-    class OutputStreamImpl extends OutputStream {
+    class OutputStreamImpl extends BlobOutputStream {
         
         private FileOutputStream fileOutputStream;
         
+        public WritableBlob getBlob() {
+            return OverflowBlob.this;
+        }
+
         public void write(byte[] b, int off, int len) throws IOException {
 
             if (fileOutputStream != null) {
@@ -297,7 +302,7 @@
         return fileOutputStream;
     }
     
-    public OutputStream getOutputStream() {
+    public BlobOutputStream getOutputStream() {
         if (state != STATE_NEW) {
             throw new IllegalStateException();
         } else {
@@ -306,30 +311,54 @@
         }
     }
     
-    public void readFrom(InputStream in, boolean commit) throws IOException {
+    public long readFrom(InputStream in, long length, boolean commit) throws 
StreamCopyException {
         // TODO: this will not work if the blob is in state UNCOMMITTED and we 
have already switched to a temporary file
+        long read = 0;
+        long toRead = length == -1 ? Long.MAX_VALUE : length;
         while (true) {
-            int c = in.read(getCurrentChunk(), chunkOffset, 
chunkSize-chunkOffset);
+            int c;
+            try {
+                int len = chunkSize-chunkOffset;
+                if (len > toRead) {
+                    len = (int)toRead;
+                }
+                c = in.read(getCurrentChunk(), chunkOffset, len);
+            } catch (IOException ex) {
+                throw new StreamCopyException(StreamCopyException.READ, ex);
+            }
             if (c == -1) {
                 break;
             }
+            read += c;
+            toRead -= c;
             chunkOffset += c;
             if (chunkOffset == chunkSize) {
                 chunkIndex++;
                 chunkOffset = 0;
                 if (chunkIndex == chunks.length) {
-                    FileOutputStream fileOutputStream = switchToTempFile();
-                    BufferUtils.inputStream2OutputStream(in, fileOutputStream);
-                    fileOutputStream.close();
+                    try {
+                        FileOutputStream fileOutputStream = switchToTempFile();
+                        // TODO: this will not trigger the FileOutputStream 
optimization!
+                        // TODO: fix the long -> int conversion
+                        read += BufferUtils.inputStream2OutputStream(in, 
fileOutputStream, (int)Math.min(toRead, Integer.MAX_VALUE));
+                        fileOutputStream.close();
+                    } catch (IOException ex) {
+                        if (ex instanceof StreamCopyException) {
+                            throw (StreamCopyException)ex;
+                        } else {
+                            throw new 
StreamCopyException(StreamCopyException.WRITE, ex);
+                        }
+                    }
                     break;
                 }
             }
         }
         state = commit ? STATE_COMMITTED : STATE_UNCOMMITTED;
+        return read;
     }
     
-    public void readFrom(InputStream in) throws IOException {
-        readFrom(in, state == STATE_NEW);
+    public long readFrom(InputStream in, long length) throws 
StreamCopyException {
+        return readFrom(in, length, state == STATE_NEW);
     }
 
     public InputStream getInputStream() throws IOException {

Modified: 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/blob/WritableBlob.java
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/blob/WritableBlob.java?rev=795660&r1=795659&r2=795660&view=diff
==============================================================================
--- 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/blob/WritableBlob.java
 (original)
+++ 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/blob/WritableBlob.java
 Sun Jul 19 23:28:29 2009
@@ -23,6 +23,8 @@
 import java.io.InputStream;
 import java.io.OutputStream;
 
+import org.apache.axiom.ext.io.StreamCopyException;
+
 /**
  * A writable blob.
  * <p>
@@ -63,7 +65,7 @@
      * 
      * @throws IllegalStateException if the blob is not in state NEW
      */
-    OutputStream getOutputStream();
+    BlobOutputStream getOutputStream();
 
     /**
      * Read data from the given input stream and write it to the blob.
@@ -80,15 +82,27 @@
      * The precondition implies that this method may be used after a call to
      * {...@link #getOutputStream()}. In that case it is illegal to set 
<code>commit</code> to
      * <code>true</code> (because this would invalidate the state of the 
output stream).
+     * <p>
+     * The method transfers data from the input stream to the blob until one 
of the following
+     * conditions is met:
+     * <ul>
+     *   <li>The end of the input stream is reached.
+     *   <li>The value of the <code>length</code> argument is different from 
<code>-1</code>
+     *       and the number of bytes transferred is equal to 
<code>length</code>.
+     * </ul>
      * 
      * @param in An input stream to read data from. This method will not
      *           close the stream.
-     * @throws IOException
+     * @param length the number of bytes to transfer, or <code>-1</code> if 
the method should
+     *               transfer data until the end of the input stream is reached
+     * @param commit indicates whether the blob should be in state COMMITTED 
after the operation
+     * @return the number of bytes transferred
+     * @throws StreamCopyException
      * @throws IllegalStateException if the blob is in state COMMITTED or if
      *         {...@link #getOutputStream()} has been called before and 
<code>commit</code> is
      *         <code>true</code>
      */
-    void readFrom(InputStream in, boolean commit) throws IOException;
+    long readFrom(InputStream in, long length, boolean commit) throws 
StreamCopyException;
 
     /**
      * Read data from the given input stream and write it to the blob.
@@ -117,8 +131,13 @@
      *       data is written using this method (for efficiency reasons).
      * </ol>
      * 
-     * @throws IOException
+     * @param in An input stream to read data from. This method will not
+     *           close the stream.
+     * @param length the number of bytes to transfer, or <code>-1</code> if 
the method should
+     *               transfer data until the end of the input stream is reached
+     * @return the number of bytes transferred
+     * @throws StreamCopyException
      * @throws IllegalStateException if the blob is in state COMMITTED
      */
-    void readFrom(InputStream in) throws IOException;
+    long readFrom(InputStream in, long length) throws StreamCopyException;
 }

Modified: 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/blob/WritableBlobTestBase.java
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/blob/WritableBlobTestBase.java?rev=795660&r1=795659&r2=795660&view=diff
==============================================================================
--- 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/blob/WritableBlobTestBase.java
 (original)
+++ 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/blob/WritableBlobTestBase.java
 Sun Jul 19 23:28:29 2009
@@ -117,7 +117,7 @@
         random.nextBytes(data);
         WritableBlob blob = createBlob();
         try {
-            blob.readFrom(new ByteArrayInputStream(data));
+            blob.readFrom(new ByteArrayInputStream(data), -1);
             InputStream in = blob.getInputStream();
             try {
                 assertTrue(Arrays.equals(data, IOUtils.toByteArray(in)));


Reply via email to