diff options
author | Elliott Hughes <enh@google.com> | 2011-01-26 11:34:34 -0800 |
---|---|---|
committer | Elliott Hughes <enh@google.com> | 2011-01-26 11:34:34 -0800 |
commit | 30a7ff69872ad0b8de60550a740818b645ba0f29 (patch) | |
tree | 03db49d9d008b1c6f594555d3e8d51d2f7893941 /luni | |
parent | 6a511aeecfb3f0ebf57e2df0d709d7f54fa5c51f (diff) | |
download | libcore-30a7ff69872ad0b8de60550a740818b645ba0f29.zip libcore-30a7ff69872ad0b8de60550a740818b645ba0f29.tar.gz libcore-30a7ff69872ad0b8de60550a740818b645ba0f29.tar.bz2 |
Apply harmony's fix for HARMONY-6594.
Fixes a harmony test.
Bug: https://issues.apache.org/jira/browse/HARMONY-6594
Change-Id: If53c5274400fa7b57a6f4a119e4158bb39ac7681
Diffstat (limited to 'luni')
-rw-r--r-- | luni/src/main/java/java/nio/charset/CharsetEncoder.java | 25 |
1 files changed, 16 insertions, 9 deletions
diff --git a/luni/src/main/java/java/nio/charset/CharsetEncoder.java b/luni/src/main/java/java/nio/charset/CharsetEncoder.java index 739b152..8208a56 100644 --- a/luni/src/main/java/java/nio/charset/CharsetEncoder.java +++ b/luni/src/main/java/java/nio/charset/CharsetEncoder.java @@ -81,13 +81,11 @@ public abstract class CharsetEncoder { /* * internal status consts */ - private static final int INIT = 0; - + private static final int READY = 0; private static final int ONGOING = 1; - private static final int END = 2; - private static final int FLUSH = 3; + private static final int INIT = 4; // the Charset which creates this encoder private Charset cs; @@ -104,6 +102,9 @@ public abstract class CharsetEncoder { // internal status private int status; + // internal status indicates encode(CharBuffer) operation is finished + private boolean finished; + // action for malformed input private CodingErrorAction malformAction; @@ -199,10 +200,10 @@ public abstract class CharsetEncoder { // implementation of canEncode private boolean implCanEncode(CharBuffer cb) { - if (status == FLUSH) { - status = INIT; + if (status == FLUSH || status == INIT) { + status = READY; } - if (status != INIT) { + if (status != READY) { throw new IllegalStateException("encoding already in progress"); } CodingErrorAction malformBak = malformAction; @@ -327,7 +328,8 @@ public abstract class CharsetEncoder { } break; } - status = FLUSH; + status = READY; + finished = true; return output; } @@ -416,6 +418,11 @@ public abstract class CharsetEncoder { * <code>BufferUnderflowException</code>. */ public final CoderResult encode(CharBuffer in, ByteBuffer out, boolean endOfInput) { + // If the previous step is encode(CharBuffer), then no more input is needed + // thus endOfInput should not be false + if (status == READY && finished && !endOfInput) { + throw new IllegalStateException(); + } if ((status == FLUSH) || (!endOfInput && status == END)) { throw new IllegalStateException(); } @@ -531,7 +538,7 @@ public abstract class CharsetEncoder { * for the last boolean parameter. */ public final CoderResult flush(ByteBuffer out) { - if (status != END && status != INIT) { + if (status != END && status != READY) { throw new IllegalStateException(); } CoderResult result = implFlush(out); |