hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1657868 - /httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/nio/client/methods/AsyncCharConsumer.java
Date Fri, 06 Feb 2015 15:41:51 GMT
Author: olegk
Date: Fri Feb  6 15:41:51 2015
New Revision: 1657868

URL: http://svn.apache.org/r1657868
Log:
Customizable CharsetDecoder in AsyncCharConsumer
Contrubuted by Dmitry Potapov <dpotapov@yandex-team.ru>

Modified:
    httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/nio/client/methods/AsyncCharConsumer.java

Modified: httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/nio/client/methods/AsyncCharConsumer.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/nio/client/methods/AsyncCharConsumer.java?rev=1657868&r1=1657867&r2=1657868&view=diff
==============================================================================
--- httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/nio/client/methods/AsyncCharConsumer.java
(original)
+++ httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/nio/client/methods/AsyncCharConsumer.java
Fri Feb  6 15:41:51 2015
@@ -54,7 +54,6 @@ public abstract class AsyncCharConsumer<
     private final CharBuffer cbuf;
 
     private CharsetDecoder chardecoder;
-    private ContentType contentType;
 
     public AsyncCharConsumer(final int bufSize) {
         super();
@@ -78,15 +77,28 @@ public abstract class AsyncCharConsumer<
     protected abstract void onCharReceived(
             CharBuffer buf, IOControl ioctrl) throws IOException;
 
-    @Override
-    protected final void onEntityEnclosed(
-            final HttpEntity entity, final ContentType contentType) throws IOException {
-        this.contentType = contentType != null ? contentType : ContentType.DEFAULT_TEXT;
-        Charset charset = this.contentType.getCharset();
+    /**
+     * Invoked to create a @{link CharsetDecoder} for contentType.
+     * This allows to use different default charsets for different content
+     * types and set appropriate coding error actions.
+     *
+     * @param contentType response Content-Type or null if not specified.
+     * @return content decoder.
+     *
+     * @since 4.1
+     */
+    protected CharsetDecoder createDecoder(final ContentType contentType) {
+        Charset charset = contentType != null ? contentType.getCharset() : null;
         if (charset == null) {
             charset = HTTP.DEF_CONTENT_CHARSET;
         }
-        this.chardecoder = charset.newDecoder();
+        return charset.newDecoder();
+    }
+
+    @Override
+    protected final void onEntityEnclosed(
+            final HttpEntity entity, final ContentType contentType) throws IOException {
+        this.chardecoder = createDecoder(contentType != null ? contentType : ContentType.DEFAULT_TEXT);
     }
 
     @Override



Mime
View raw message