Author: veithen
Date: Sat May 15 09:04:25 2010
New Revision: 944599

URL: http://svn.apache.org/viewvc?rev=944599&view=rev
Log:
Breaking the remaining cyclic package dependencies involving 
org.apache.axiom.util + some minor fixes.

Added:
    
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/activation/EmptyDataSource.java
   (with props)
Modified:
    
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/stax/XMLStreamReaderUtils.java

Added: 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/activation/EmptyDataSource.java
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/activation/EmptyDataSource.java?rev=944599&view=auto
==============================================================================
--- 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/activation/EmptyDataSource.java
 (added)
+++ 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/activation/EmptyDataSource.java
 Sat May 15 09:04:25 2010
@@ -0,0 +1,63 @@
+/*
+ * 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.activation;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+import org.apache.axiom.ext.activation.SizeAwareDataSource;
+
+/**
+ * A data source with empty (zero length) content.
+ */
+public class EmptyDataSource implements SizeAwareDataSource {
+    private static final InputStream emptyInputStream = new InputStream() {
+        public int read() throws IOException {
+            return -1;
+        }
+    };
+    
+    private final String contentType;
+    
+    public EmptyDataSource(String contentType) {
+        this.contentType = contentType;
+    }
+
+    public String getContentType() {
+        return contentType;
+    }
+
+    public String getName() {
+        return null;
+    }
+
+    public long getSize() {
+        return 0;
+    }
+
+    public InputStream getInputStream() throws IOException {
+        return emptyInputStream;
+    }
+
+    public OutputStream getOutputStream() throws IOException {
+        throw new UnsupportedOperationException();
+    }
+}

Propchange: 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/activation/EmptyDataSource.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=944599&r1=944598&r2=944599&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
 Sat May 15 09:04:25 2010
@@ -25,11 +25,11 @@ import java.io.OutputStream;
 import java.util.ArrayList;
 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;
+    // TODO: this should be configurable
+    final static int BUFFER_SIZE = 4096;
     
     class OutputStreamImpl extends BlobOutputStream {
         public WritableBlob getBlob() {

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=944599&r1=944598&r2=944599&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
 Sat May 15 09:04:25 2010
@@ -26,7 +26,7 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
 
-import org.apache.axiom.attachments.impl.BufferUtils;
+import org.apache.axiom.ext.io.ReadFromSupport;
 import org.apache.axiom.ext.io.StreamCopyException;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -336,18 +336,35 @@ public class OverflowBlob implements Wri
                 chunkIndex++;
                 chunkOffset = 0;
                 if (chunkIndex == chunks.length) {
+                    FileOutputStream fileOutputStream;
                     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();
+                        fileOutputStream = switchToTempFile();
                     } catch (IOException ex) {
-                        if (ex instanceof StreamCopyException) {
-                            throw (StreamCopyException)ex;
-                        } else {
+                        throw new 
StreamCopyException(StreamCopyException.WRITE, ex);
+                    }
+                    byte[] buf = new byte[4096];
+                    while (true) {
+                        int c2;
+                        try {
+                            c2 = in.read(buf, 0, (int)Math.min(toRead, 4096));
+                        } catch (IOException ex) {
+                            throw new 
StreamCopyException(StreamCopyException.READ, ex);
+                        }
+                        if (c2 == -1) {
+                            break;
+                        }
+                        try {
+                            fileOutputStream.write(buf, 0, c2);
+                        } catch (IOException ex) {
                             throw new 
StreamCopyException(StreamCopyException.WRITE, ex);
                         }
+                        read += c2;
+                        toRead -= c2;
+                    }
+                    try {
+                        fileOutputStream.close();
+                    } catch (IOException ex) {
+                        throw new 
StreamCopyException(StreamCopyException.WRITE, ex);
                     }
                     break;
                 }
@@ -375,7 +392,15 @@ public class OverflowBlob implements Wri
         if (temporaryFile != null) {
             FileInputStream in = new FileInputStream(temporaryFile);
             try {
-                BufferUtils.inputStream2OutputStream(in, out);
+                if (out instanceof ReadFromSupport) {
+                    ((ReadFromSupport)out).readFrom(in, -1);
+                } else {
+                    byte[] buf = new byte[4096];
+                    int c;
+                    while ((c = in.read(buf)) != -1) {
+                        out.write(buf, 0, c);
+                    }
+                }
             } finally {
                 in.close();
             }

Modified: 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/XMLStreamReaderUtils.java
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/XMLStreamReaderUtils.java?rev=944599&r1=944598&r2=944599&view=diff
==============================================================================
--- 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/XMLStreamReaderUtils.java
 (original)
+++ 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/XMLStreamReaderUtils.java
 Sat May 15 09:04:25 2010
@@ -27,9 +27,9 @@ import javax.xml.stream.XMLStreamConstan
 import javax.xml.stream.XMLStreamException;
 import javax.xml.stream.XMLStreamReader;
 
-import org.apache.axiom.attachments.ByteArrayDataSource;
 import org.apache.axiom.ext.stax.CharacterDataReader;
 import org.apache.axiom.ext.stax.datahandler.DataHandlerReader;
+import org.apache.axiom.util.activation.EmptyDataSource;
 import org.apache.axiom.util.base64.Base64DecodingOutputStreamWriter;
 import org.apache.axiom.util.blob.BlobDataSource;
 import org.apache.axiom.util.blob.MemoryBlob;
@@ -81,7 +81,7 @@ public class XMLStreamReaderUtils {
         int event = reader.next();
         if (event == XMLStreamConstants.END_ELEMENT) {
             // This means that the element is actually empty -> return empty 
DataHandler
-            return new DataHandler(new ByteArrayDataSource(new byte[0]));
+            return new DataHandler(new 
EmptyDataSource("application/octet-stream"));
         } else if (event != XMLStreamConstants.CHARACTERS) {
             throw new XMLStreamException("Expected a CHARACTER event");
         }


Reply via email to