Author: ningjiang
Date: Wed Sep 20 01:10:07 2006
New Revision: 448120
URL: http://svn.apache.org/viewvc?view=rev&rev=448120
Log:
[JIRA CXF-99] Fixed the sending data more than 8K broken issue
Added:
incubator/cxf/trunk/rt/core/src/test/java/org/apache/cxf/transport/
incubator/cxf/trunk/rt/core/src/test/java/org/apache/cxf/transport/CachedOutputStream.java
incubator/cxf/trunk/rt/core/src/test/java/org/apache/cxf/transport/CachedOutputStreamTest.java
Modified:
incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/transport/AbstractCachedOutputStream.java
Modified:
incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/transport/AbstractCachedOutputStream.java
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/transport/AbstractCachedOutputStream.java?view=diff&rev=448120&r1=448119&r2=448120
==============================================================================
---
incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/transport/AbstractCachedOutputStream.java
(original)
+++
incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/transport/AbstractCachedOutputStream.java
Wed Sep 20 01:10:07 2006
@@ -91,10 +91,30 @@
* the real output stream
* @throws IOException
*/
- public void resetOut(OutputStream out, boolean copyOldContent) throws
IOException {
- ByteArrayOutputStream bout = (ByteArrayOutputStream) currentStream;
- if (copyOldContent && bout.size() > 0) {
- bout.writeTo(out);
+ public void resetOut(OutputStream out, boolean copyOldContent) throws
IOException {
+ if (inmem) {
+ ByteArrayOutputStream byteOut = (ByteArrayOutputStream)
currentStream;
+ if (copyOldContent && byteOut.size() > 0) {
+ byteOut.writeTo(out);
+ }
+ } else {
+ //read the file
+ currentStream.close();
+ FileInputStream fin = new FileInputStream(tempFile);
+ if (copyOldContent) {
+ byte[] buffer = new byte[4096];
+ int len = 0;
+ int pos = 0;
+ while (true) {
+ len = fin.read(buffer, 0, 4096);
+ if (len != -1) {
+ out.write(buffer, 0, len);
+ pos += len;
+ } else {
+ break;
+ }
+ }
+ }
}
currentStream = out;
}
Added:
incubator/cxf/trunk/rt/core/src/test/java/org/apache/cxf/transport/CachedOutputStream.java
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/core/src/test/java/org/apache/cxf/transport/CachedOutputStream.java?view=auto&rev=448120
==============================================================================
---
incubator/cxf/trunk/rt/core/src/test/java/org/apache/cxf/transport/CachedOutputStream.java
(added)
+++
incubator/cxf/trunk/rt/core/src/test/java/org/apache/cxf/transport/CachedOutputStream.java
Wed Sep 20 01:10:07 2006
@@ -0,0 +1,46 @@
+/**
+ * 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.cxf.transport;
+
+import java.io.IOException;
+
+public class CachedOutputStream extends AbstractCachedOutputStream {
+ CachedOutputStream() {
+ super();
+ }
+
+ @Override
+ protected void doClose() throws IOException {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ protected void doFlush() throws IOException {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ protected void onWrite() throws IOException {
+ // TODO Auto-generated method stub
+
+ }
+
+}
Added:
incubator/cxf/trunk/rt/core/src/test/java/org/apache/cxf/transport/CachedOutputStreamTest.java
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/core/src/test/java/org/apache/cxf/transport/CachedOutputStreamTest.java?view=auto&rev=448120
==============================================================================
---
incubator/cxf/trunk/rt/core/src/test/java/org/apache/cxf/transport/CachedOutputStreamTest.java
(added)
+++
incubator/cxf/trunk/rt/core/src/test/java/org/apache/cxf/transport/CachedOutputStreamTest.java
Wed Sep 20 01:10:07 2006
@@ -0,0 +1,51 @@
+/**
+ * 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.cxf.transport;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+
+
+import junit.framework.TestCase;
+
+public class CachedOutputStreamTest extends TestCase {
+
+ public void testResetOut() throws IOException {
+ CachedOutputStream cos = new CachedOutputStream();
+ String result = initTestData(16);
+ cos.write(result.getBytes());
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ cos.resetOut(out, true);
+ String test = out.toString();
+ assertEquals("The test stream content isn't same ", test , result);
+ }
+
+ String initTestData(int packetSize) {
+ String temp = "[EMAIL PROTECTED]&*()_+?><[]/0123456789";
+ String result = new String();
+ for (int i = 0; i < 1024 * packetSize / temp.length(); i++) {
+ result = result + temp;
+ }
+ return result;
+ }
+
+
+}
+
+