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:10:04 GMT
Repository: cxf
Updated Branches:
  refs/heads/master b5da5e89b -> 22b7392c8


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/22b7392c
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/22b7392c
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/22b7392c

Branch: refs/heads/master
Commit: 22b7392c891bcce3f19a1a732c07691b50338172
Parents: b5da5e8
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:09:41 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/22b7392c/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 d430a68..8ba39c4 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);
             }
@@ -156,7 +156,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();
@@ -185,9 +185,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);
             }
         }
     }
@@ -198,7 +198,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
         }
@@ -221,4 +221,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/22b7392c/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