cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject cxf git commit: Minor updates to JAXRS String and InputStream writers
Date Thu, 05 Mar 2015 13:11:30 GMT
Repository: cxf
Updated Branches:
  refs/heads/3.0.x-fixes 8edfe4abc -> e163f8a5d


Minor updates to JAXRS String and InputStream writers


Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/e163f8a5
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/e163f8a5
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/e163f8a5

Branch: refs/heads/3.0.x-fixes
Commit: e163f8a5d347abf183d8fe406db826118838fa1e
Parents: 8edfe4a
Author: Sergey Beryozkin <sberyozkin@talend.com>
Authored: Thu Mar 5 13:09:41 2015 +0000
Committer: Sergey Beryozkin <sberyozkin@talend.com>
Committed: Thu Mar 5 13:10:56 2015 +0000

----------------------------------------------------------------------
 .../cxf/jaxrs/provider/BinaryDataProvider.java    | 18 +++++++++++-------
 .../cxf/jaxrs/provider/PrimitiveTextProvider.java | 15 ++++++++++++---
 2 files changed, 23 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/e163f8a5/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/BinaryDataProvider.java
----------------------------------------------------------------------
diff --git a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/BinaryDataProvider.java
b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/BinaryDataProvider.java
index 2a72839..41a45eb 100644
--- a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/BinaryDataProvider.java
+++ b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/BinaryDataProvider.java
@@ -58,7 +58,7 @@ public class BinaryDataProvider<T> extends AbstractConfigurableProvider
     private static final String HTTP_RANGE_PROPERTY = "http.range.support";
     private static final Logger LOG = LogUtils.getL7dLogger(BinaryDataProvider.class);
     
-    private static final int BUFFER_SIZE = 4096;
+    private int bufferSize = IOUtils.DEFAULT_BUFFER_SIZE;
     private boolean reportByteArraySize;
     private boolean closeResponseInputStream = true;
     public boolean isReadable(Class<?> type, Type genericType, Annotation[] annotations,
MediaType mt) {
@@ -94,7 +94,7 @@ public class BinaryDataProvider<T> extends AbstractConfigurableProvider
                 if (enc == null) {
                     return clazz.cast(IOUtils.readBytesFromStream(is));
                 } else {
-                    return clazz.cast(IOUtils.toString(is, enc).getBytes(enc));
+                    return clazz.cast(IOUtils.toString(is, bufferSize, enc).getBytes(enc));
                 }
             }
             if (File.class.isAssignableFrom(clazz)) {
@@ -106,7 +106,7 @@ public class BinaryDataProvider<T> extends AbstractConfigurableProvider
                                                   null,
                                                   true);
                 FileOutputStream fos = new FileOutputStream(f);
-                IOUtils.copy(is, fos);
+                IOUtils.copy(is, fos, bufferSize);
                 fos.close();
                 return clazz.cast(f);
             }
@@ -154,7 +154,7 @@ public class BinaryDataProvider<T> extends AbstractConfigurableProvider
                 Writer writer = new OutputStreamWriter(os, getEncoding(type));
                 IOUtils.copy((Reader)o, 
                               writer,
-                              BUFFER_SIZE);
+                              bufferSize);
                 writer.flush();
             } finally {
                 ((Reader)o).close();
@@ -183,9 +183,9 @@ public class BinaryDataProvider<T> extends AbstractConfigurableProvider
             handleRangeRequest(is, os, new HttpHeadersImpl(inMessage), outHeaders);
         } else {
             if (closeResponseInputStream) {
-                IOUtils.copyAndCloseInput(is, os);
+                IOUtils.copyAndCloseInput(is, os, bufferSize);
             } else {
-                IOUtils.copy(is, os);
+                IOUtils.copy(is, os, bufferSize);
             }
         }
     }
@@ -196,7 +196,7 @@ public class BinaryDataProvider<T> extends AbstractConfigurableProvider
                                       MultivaluedMap<String, Object> outHeaders) throws
IOException {
         String range = inHeaders.getRequestHeaders().getFirst("Range"); 
         if (range == null) {
-            IOUtils.copyAndCloseInput(is, os);    
+            IOUtils.copyAndCloseInput(is, os, bufferSize);    
         } else {
             // implement
         }
@@ -219,4 +219,8 @@ public class BinaryDataProvider<T> extends AbstractConfigurableProvider
     public void setCloseResponseInputStream(boolean closeResponseInputStream) {
         this.closeResponseInputStream = closeResponseInputStream;
     }
+
+    public void setBufferSize(int bufferSize) {
+        this.bufferSize = bufferSize;
+    }
 }

http://git-wip-us.apache.org/repos/asf/cxf/blob/e163f8a5/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/PrimitiveTextProvider.java
----------------------------------------------------------------------
diff --git a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/PrimitiveTextProvider.java
b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/PrimitiveTextProvider.java
index b552d93..392c36d 100644
--- a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/PrimitiveTextProvider.java
+++ b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/PrimitiveTextProvider.java
@@ -18,6 +18,7 @@
  */
 package org.apache.cxf.jaxrs.provider;
 
+import java.io.ByteArrayInputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
@@ -37,7 +38,8 @@ import org.apache.cxf.jaxrs.utils.InjectionUtils;
 
 public class PrimitiveTextProvider<T> 
     implements MessageBodyReader<T>, MessageBodyWriter<T> {
-
+    private int bufferSize = IOUtils.DEFAULT_BUFFER_SIZE;
+    
     private static boolean isSupported(Class<?> type) { 
         return InjectionUtils.isPrimitive(type);
     }
@@ -75,7 +77,14 @@ public class PrimitiveTextProvider<T>
                         MediaType mt, MultivaluedMap<String, Object> headers,
                         OutputStream os) throws IOException {
         String encoding = HttpUtils.getSetEncoding(mt, headers, "UTF-8");
-        os.write(obj.toString().getBytes(encoding));
+        byte[] bytes = obj.toString().getBytes(encoding);
+        if (bytes.length > bufferSize) {
+            IOUtils.copy(new ByteArrayInputStream(bytes), os, bufferSize);
+        } else {
+            os.write(bytes);
+        }
+    }
+    public void setBufferSize(int bufferSize) {
+        this.bufferSize = bufferSize;
     }
-
 }


Mime
View raw message