wink-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From b...@apache.org
Subject svn commit: r932520 - /incubator/wink/trunk/wink-common/src/main/java/org/apache/wink/common/internal/providers/entity/StringProvider.java
Date Fri, 09 Apr 2010 17:24:09 GMT
Author: bluk
Date: Fri Apr  9 17:24:09 2010
New Revision: 932520

URL: http://svn.apache.org/viewvc?rev=932520&view=rev
Log:
Update StringProvider to increase performance

Thanks to Doug Larson for performance analysis.

Modified:
    incubator/wink/trunk/wink-common/src/main/java/org/apache/wink/common/internal/providers/entity/StringProvider.java

Modified: incubator/wink/trunk/wink-common/src/main/java/org/apache/wink/common/internal/providers/entity/StringProvider.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-common/src/main/java/org/apache/wink/common/internal/providers/entity/StringProvider.java?rev=932520&r1=932519&r2=932520&view=diff
==============================================================================
--- incubator/wink/trunk/wink-common/src/main/java/org/apache/wink/common/internal/providers/entity/StringProvider.java
(original)
+++ incubator/wink/trunk/wink-common/src/main/java/org/apache/wink/common/internal/providers/entity/StringProvider.java
Fri Apr  9 17:24:09 2010
@@ -19,12 +19,15 @@
  *******************************************************************************/
 package org.apache.wink.common.internal.providers.entity;
 
+import java.io.BufferedWriter;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
+import java.io.OutputStreamWriter;
 import java.io.UnsupportedEncodingException;
 import java.lang.annotation.Annotation;
 import java.lang.reflect.Type;
+import java.nio.charset.Charset;
 
 import javax.ws.rs.Consumes;
 import javax.ws.rs.Produces;
@@ -94,12 +97,16 @@ public class StringProvider implements M
                         MediaType mediaType,
                         MultivaluedMap<String, Object> httpHeaders,
                         OutputStream entityStream) throws IOException, WebApplicationException
{
-        
+
         ProviderUtils.setDefaultCharsetOnMediaTypeHeader(httpHeaders, mediaType);
 
         logger.debug("Writing {} to stream using {}", t, getClass().getName()); //$NON-NLS-1$
 
-        entityStream.write(t.getBytes(ProviderUtils.getCharset(mediaType)));
+        Charset charset = Charset.forName(ProviderUtils.getCharset(mediaType));
+        OutputStreamWriter writer = new OutputStreamWriter(entityStream, charset);
+        BufferedWriter bw = new BufferedWriter(writer);
+        bw.write(t, 0, t.length());
+        bw.flush();
     }
 
 }



Mime
View raw message