summaryrefslogtreecommitdiffstats
path: root/luni
diff options
context:
space:
mode:
Diffstat (limited to 'luni')
-rw-r--r--luni/src/main/java/java/nio/charset/CharsetEncoder.java25
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);