You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commons-dev@ws.apache.org by ve...@apache.org on 2009/07/13 00:00:58 UTC
svn commit: r793414 - in
/webservices/commons/trunk/modules/axiom/modules/axiom-api/src:
main/java/org/apache/axiom/util/blob/ test/java/org/apache/axiom/util/blob/
Author: veithen
Date: Sun Jul 12 22:00:57 2009
New Revision: 793414
URL: http://svn.apache.org/viewvc?rev=793414&view=rev
Log:
Copied over a piece of code from Synapse. This will be useful later.
Added:
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/blob/
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/blob/Blob.java (with props)
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/blob/OverflowBlob.java
- copied, changed from r793412, synapse/trunk/java/modules/commons/src/main/java/org/apache/synapse/commons/util/TemporaryData.java
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/blob/
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/blob/OverflowBlobTest.java
- copied, changed from r793412, synapse/trunk/java/modules/commons/src/test/java/org/apache/synapse/util/TemporaryDataTest.java
Added: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/blob/Blob.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/blob/Blob.java?rev=793414&view=auto
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/blob/Blob.java (added)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/blob/Blob.java Sun Jul 12 22:00:57 2009
@@ -0,0 +1,59 @@
+/*
+ * 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.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+public interface Blob {
+ OutputStream getOutputStream();
+
+ /**
+ * Fill this object with data read from a given InputStream.
+ * <p>
+ * A call <code>tmp.readFrom(in)</code> has the same effect as the
+ * following code:
+ * <pre>
+ * OutputStream out = tmp.getOutputStream();
+ * IOUtils.copy(in, out);
+ * out.close();
+ * </pre>
+ * However it does so in a more efficient way.
+ *
+ * @param in An InputStream to read data from. This method will not
+ * close the stream.
+ * @throws IOException
+ */
+ void readFrom(InputStream in) throws IOException;
+
+ InputStream getInputStream() throws IOException;
+
+ /**
+ * Write the data to a given output stream.
+ *
+ * @param out The output stream to write the data to. This method will
+ * not close the stream.
+ * @throws IOException
+ */
+ void writeTo(OutputStream out) throws IOException;
+
+ long getLength();
+}
\ No newline at end of file
Propchange: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/blob/Blob.java
------------------------------------------------------------------------------
svn:eol-style = native
Copied: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/blob/OverflowBlob.java (from r793412, synapse/trunk/java/modules/commons/src/main/java/org/apache/synapse/commons/util/TemporaryData.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?p2=webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/blob/OverflowBlob.java&p1=synapse/trunk/java/modules/commons/src/main/java/org/apache/synapse/commons/util/TemporaryData.java&r1=793412&r2=793414&rev=793414&view=diff
==============================================================================
--- synapse/trunk/java/modules/commons/src/main/java/org/apache/synapse/commons/util/TemporaryData.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/blob/OverflowBlob.java Sun Jul 12 22:00:57 2009
@@ -1,11 +1,16 @@
-package org.apache.synapse.commons.util;
+package org.apache.axiom.util.blob;
-import org.apache.commons.io.IOUtils;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+import org.apache.axiom.attachments.impl.BufferUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import java.io.*;
-
/**
* Class representing some temporary data in the form of a byte stream.
* <p>
@@ -18,9 +23,9 @@
* on demand. Since a temporary file may be created it is mandatory to
* call {@link #release()} to discard the temporary data.
*/
-public class TemporaryData {
+public class OverflowBlob implements Blob {
- private static final Log log = LogFactory.getLog(TemporaryData.class);
+ private static final Log log = LogFactory.getLog(OverflowBlob.class);
class OutputStreamImpl extends OutputStream {
@@ -211,7 +216,7 @@
*/
File temporaryFile;
- public TemporaryData(int numberOfChunks, int chunkSize, String tempPrefix, String tempSuffix) {
+ public OverflowBlob(int numberOfChunks, int chunkSize, String tempPrefix, String tempSuffix) {
this.chunkSize = chunkSize;
this.tempPrefix = tempPrefix;
this.tempSuffix = tempSuffix;
@@ -268,22 +273,6 @@
return new OutputStreamImpl();
}
- /**
- * Fill this object with data read from a given InputStream.
- * <p>
- * A call <code>tmp.readFrom(in)</code> has the same effect as the
- * following code:
- * <pre>
- * OutputStream out = tmp.getOutputStream();
- * IOUtils.copy(in, out);
- * out.close();
- * </pre>
- * However it does so in a more efficient way.
- *
- * @param in An InputStream to read data from. This method will not
- * close the stream.
- * @throws IOException
- */
public void readFrom(InputStream in) throws IOException {
while (true) {
int c = in.read(getCurrentChunk(), chunkOffset, chunkSize-chunkOffset);
@@ -296,7 +285,7 @@
chunkOffset = 0;
if (chunkIndex == chunks.length) {
FileOutputStream fileOutputStream = switchToTempFile();
- IOUtils.copy(in, fileOutputStream);
+ BufferUtils.inputStream2OutputStream(in, fileOutputStream);
fileOutputStream.close();
break;
}
@@ -312,18 +301,11 @@
}
}
- /**
- * Write the data to a given output stream.
- *
- * @param out The output stream to write the data to. This method will
- * not close the stream.
- * @throws IOException
- */
public void writeTo(OutputStream out) throws IOException {
if (temporaryFile != null) {
FileInputStream in = new FileInputStream(temporaryFile);
try {
- IOUtils.copy(in, out);
+ BufferUtils.inputStream2OutputStream(in, out);
} finally {
in.close();
}
Copied: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/blob/OverflowBlobTest.java (from r793412, synapse/trunk/java/modules/commons/src/test/java/org/apache/synapse/util/TemporaryDataTest.java)
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/blob/OverflowBlobTest.java?p2=webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/blob/OverflowBlobTest.java&p1=synapse/trunk/java/modules/commons/src/test/java/org/apache/synapse/util/TemporaryDataTest.java&r1=793412&r2=793414&rev=793414&view=diff
==============================================================================
--- synapse/trunk/java/modules/commons/src/test/java/org/apache/synapse/util/TemporaryDataTest.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/blob/OverflowBlobTest.java Sun Jul 12 22:00:57 2009
@@ -17,7 +17,7 @@
* under the License.
*/
-package org.apache.synapse.util;
+package org.apache.axiom.util.blob;
import java.io.ByteArrayInputStream;
import java.io.DataInputStream;
@@ -28,17 +28,16 @@
import java.util.Random;
import org.apache.commons.io.IOUtils;
-import org.apache.synapse.commons.util.TemporaryData;
import junit.framework.TestCase;
-public class TemporaryDataTest extends TestCase {
+public class OverflowBlobTest extends TestCase {
private final static Random random = new Random();
private void doTestRandomReadWrite(int size) throws IOException {
byte[] data = new byte[size];
random.nextBytes(data);
- TemporaryData tmp = new TemporaryData(16, 1024, "test", ".dat");
+ OverflowBlob tmp = new OverflowBlob(16, 1024, "test", ".dat");
try {
OutputStream out = tmp.getOutputStream();
// Write the test data in chunks with random size
@@ -89,7 +88,7 @@
byte[] sourceData2 = new byte[2000];
random.nextBytes(sourceData1);
random.nextBytes(sourceData2);
- TemporaryData tmp = new TemporaryData(16, 512, "test", ".dat");
+ OverflowBlob tmp = new OverflowBlob(16, 512, "test", ".dat");
OutputStream out = tmp.getOutputStream();
out.write(sourceData1);
out.write(sourceData2);
@@ -109,7 +108,7 @@
private void testReadFrom(int size) throws IOException {
byte[] data = new byte[size];
random.nextBytes(data);
- TemporaryData tmp = new TemporaryData(16, 1024, "test", ".dat");
+ OverflowBlob tmp = new OverflowBlob(16, 1024, "test", ".dat");
try {
tmp.readFrom(new ByteArrayInputStream(data));
InputStream in = tmp.getInputStream();