fix reader index
authorVladimir Krivosheev <vladimir.krivosheev@jetbrains.com>
Fri, 10 Jun 2016 16:29:45 +0000 (18:29 +0200)
committerVladimir Krivosheev <vladimir.krivosheev@jetbrains.com>
Fri, 10 Jun 2016 16:32:05 +0000 (18:32 +0200)
platform/platform-impl/src/org/jetbrains/io/MessageDecoder.java

index dca61410e12ec36de67772ef394cb1edc432577b..1020b5708b76fbd85a9702cd18b965e03a14e51a 100644 (file)
@@ -56,14 +56,19 @@ public abstract class MessageDecoder extends Decoder {
     }
     else {
       CharBuffer charBuffer = chunkedContent;
-      if (charBuffer == null) {
-        return input.toString(input.readerIndex(), required, StandardCharsets.UTF_8);
+      CharSequence result;
+      if (charBuffer != null) {
+        chunkedContent = null;
+        consumedContentByteCount = 0;
+        ChannelBufferToStringKt.readIntoCharBuffer(input, required, charBuffer);
+        result = new CharSequenceBackedByChars(charBuffer);
+      }
+      else {
+        result = input.toString(input.readerIndex(), required, StandardCharsets.UTF_8);
       }
 
-      chunkedContent = null;
-      consumedContentByteCount = 0;
-      ChannelBufferToStringKt.readIntoCharBuffer(input, required, charBuffer);
-      return new CharSequenceBackedByChars(charBuffer);
+      input.readerIndex(input.readerIndex() + required);
+      return result;
     }
   }