/** * Flushes this writer. This implementation ensures that all buffered bytes * are written to the target stream. After writing the bytes, the target * stream is flushed as well. * * @throws IOException * if an error occurs while flushing this writer. */ @Override public void flush() throws IOException { flushBytes(true); }
private void convert(CharBuffer chars) throws IOException { while (true) { CoderResult result = encoder.encode(chars, bytes, false); if (result.isOverflow()) { // Make room and try again. flushBytes(false); continue; } else if (result.isError()) { result.throwException(); } break; } }
private void drainEncoder() throws IOException { // Strictly speaking, I think it's part of the CharsetEncoder contract that you call // encode with endOfInput true before flushing. Our ICU-based implementations don't // actually need this, and you'd hope that any reasonable implementation wouldn't either. // CharsetEncoder.encode doesn't actually pass the boolean through to encodeLoop anyway! CharBuffer chars = CharBuffer.allocate(0); while (true) { CoderResult result = encoder.encode(chars, bytes, true); if (result.isError()) { result.throwException(); } else if (result.isOverflow()) { flushBytes(false); continue; } break; } // Some encoders (such as ISO-2022-JP) have stuff to write out after all the // characters (such as shifting back into a default state). In our implementation, // this is actually the first time ICU is told that we've run out of input. CoderResult result = encoder.flush(bytes); while (!result.isUnderflow()) { if (result.isOverflow()) { flushBytes(false); result = encoder.flush(bytes); } else { result.throwException(); } } }
/** * Closes this writer. This implementation flushes the buffer as well as the * target stream. The target stream is then closed and the resources for the * buffer and converter are released. * * <p>Only the first invocation of this method has any effect. Subsequent calls * do nothing. * * @throws IOException * if an error occurs while closing this writer. */ @Override public void close() throws IOException { synchronized (lock) { if (encoder != null) { drainEncoder(); flushBytes(false); out.close(); encoder = null; bytes = null; } } }
/** * Flushes this writer. This implementation ensures that all buffered bytes * are written to the target stream. After writing the bytes, the target * stream is flushed as well. * * @throws IOException * if an error occurs while flushing this writer. */ @Override public void flush() throws IOException { flushBytes(true); }
/** * Flushes this writer. This implementation ensures that all buffered bytes * are written to the target stream. After writing the bytes, the target * stream is flushed as well. * * @throws IOException * if an error occurs while flushing this writer. */ @Override public void flush() throws IOException { flushBytes(true); }
/** * Flushes this writer. This implementation ensures that all buffered bytes * are written to the target stream. After writing the bytes, the target * stream is flushed as well. * * @throws IOException * if an error occurs while flushing this writer. */ @Override public void flush() throws IOException { flushBytes(true); }
/** * Flushes this writer. This implementation ensures that all buffered bytes * are written to the target stream. After writing the bytes, the target * stream is flushed as well. * * @throws IOException * if an error occurs while flushing this writer. */ @Override public void flush() throws IOException { flushBytes(true); }
/** * Flushes this writer. This implementation ensures that all buffered bytes * are written to the target stream. After writing the bytes, the target * stream is flushed as well. * * @throws IOException * if an error occurs while flushing this writer. */ @Override public void flush() throws IOException { flushBytes(true); }
/** * Flushes this writer. This implementation ensures that all buffered bytes * are written to the target stream. After writing the bytes, the target * stream is flushed as well. * * @throws IOException * if an error occurs while flushing this writer. */ @Override public void flush() throws IOException { flushBytes(true); }
/** * Flushes this writer. This implementation ensures that all buffered bytes * are written to the target stream. After writing the bytes, the target * stream is flushed as well. * * @throws IOException if an error occurs while flushing this writer. */ @Override public void flush() throws IOException { flushBytes(true); }
private void convert(CharBuffer chars) throws IOException { while (true) { CoderResult result = encoder.encode(chars, bytes, false); if (result.isOverflow()) { // Make room and try again. flushBytes(false); continue; } else if (result.isError()) { result.throwException(); } break; } }
private void convert(CharBuffer chars) throws IOException { while (true) { CoderResult result = encoder.encode(chars, bytes, false); if (result.isOverflow()) { // Make room and try again. flushBytes(false); continue; } else if (result.isError()) { result.throwException(); } break; } }
private void convert(CharBuffer chars) throws IOException { while (true) { CoderResult result = encoder.encode(chars, bytes, false); if (result.isOverflow()) { // Make room and try again. flushBytes(false); continue; } else if (result.isError()) { result.throwException(); } break; } }
private void convert(CharBuffer chars) throws IOException { while (true) { CoderResult result = encoder.encode(chars, bytes, false); if (result.isOverflow()) { // Make room and try again. flushBytes(false); continue; } else if (result.isError()) { result.throwException(); } break; } }
private void convert(CharBuffer chars) throws IOException { while (true) { CoderResult result = encoder.encode(chars, bytes, false); if (result.isOverflow()) { // Make room and try again. flushBytes(false); continue; } else if (result.isError()) { result.throwException(); } break; } }
private void convert(CharBuffer chars) throws IOException { while (true) { CoderResult result = encoder.encode(chars, bytes, false); if (result.isOverflow()) { // Make room and try again. flushBytes(false); continue; } else if (result.isError()) { result.throwException(); } break; } }
private void convert(CharBuffer chars) throws IOException { while (true) { CoderResult result = encoder.encode(chars, bytes, false); if (result.isOverflow()) { // Make room and try again. flushBytes(false); continue; } else if (result.isError()) { result.throwException(); } break; } }
/** * Closes this writer. This implementation flushes the buffer as well as the * target stream. The target stream is then closed and the resources for the * buffer and converter are released. * * <p>Only the first invocation of this method has any effect. Subsequent calls * do nothing. * * @throws IOException * if an error occurs while closing this writer. */ @Override public void close() throws IOException { synchronized (lock) { if (encoder != null) { drainEncoder(); flushBytes(false); out.close(); encoder = null; bytes = null; } } }
/** * Closes this writer. This implementation flushes the buffer as well as the * target stream. The target stream is then closed and the resources for the * buffer and converter are released. * * <p>Only the first invocation of this method has any effect. Subsequent calls * do nothing. * * @throws IOException * if an error occurs while closing this writer. */ @Override public void close() throws IOException { synchronized (lock) { if (encoder != null) { drainEncoder(); flushBytes(false); out.close(); encoder = null; bytes = null; } } }