Index: C:/Clear/workspace_harmony_M5/nio_char/src/main/java/java/nio/charset/CharsetDecoder.java =================================================================== --- C:/Clear/workspace_harmony_M5/nio_char/src/main/java/java/nio/charset/CharsetDecoder.java (revision 382639) +++ C:/Clear/workspace_harmony_M5/nio_char/src/main/java/java/nio/charset/CharsetDecoder.java (working copy) @@ -128,6 +128,10 @@ private int status; private byte[] remains = null; + + // replaceString should be put into output by next decode invocation + // if OVERFLOW occured in current decode invocation. + private boolean needReplace = false; /* * --------------------------------------- Constructor @@ -375,6 +379,17 @@ throw new IllegalStateException(); } + // the last decode invocation hasn't put replace string into out + // because of OVERFLOW + if(needReplace){ + if(out.remaining() >= replace.length()){ + out.put(replace); + needReplace = false; + }else{ + return CoderResult.OVERFLOW; + } + } + CoderResult result = null; // save old values of remains.length and the position of in. @@ -438,6 +453,7 @@ } else if (action == CodingErrorAction.REPLACE) { if (out.remaining() < replace.length()) { result = CoderResult.OVERFLOW; + needReplace = true; } else { out.put(replace); continue;