src/share/classes/sun/nio/cs/StreamEncoder.java

Print this page

        

*** 257,266 **** --- 257,280 ---- cr.throwException(); } haveLeftoverChar = false; } + private void flushEncoder() throws IOException { + for (;;) { + CoderResult cr = encoder.flush(bb); + if (cr.isUnderflow()) + break; + if (cr.isOverflow()) { + assert bb.position() > 0; + writeBytes(); + continue; + } + cr.throwException(); + } + } + void implWrite(char cbuf[], int off, int len) throws IOException { CharBuffer cb = CharBuffer.wrap(cbuf, off, len);
*** 285,294 **** --- 299,317 ---- cr.throwException(); } } void implFlushBuffer() throws IOException { + try { + // flush underlying encoder + flushLeftoverChar(null, true); + flushEncoder(); + encoder.reset(); + } catch (IOException x) { + encoder.reset(); + throw x; + } if (bb.position() > 0) writeBytes(); } void implFlush() throws IOException {
*** 298,319 **** } void implClose() throws IOException { flushLeftoverChar(null, true); try { ! for (;;) { ! CoderResult cr = encoder.flush(bb); ! if (cr.isUnderflow()) ! break; ! if (cr.isOverflow()) { ! assert bb.position() > 0; ! writeBytes(); ! continue; ! } ! cr.throwException(); ! } ! if (bb.position() > 0) writeBytes(); if (ch != null) ch.close(); else --- 321,331 ---- } void implClose() throws IOException { flushLeftoverChar(null, true); try { ! flushEncoder(); if (bb.position() > 0) writeBytes(); if (ch != null) ch.close(); else