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.
()
| 177 | * if an error occurs while flushing this writer. |
| 178 | */ |
| 179 | @Override |
| 180 | public void flush() throws IOException { |
| 181 | synchronized (lock) { |
| 182 | checkStatus(); |
| 183 | int position; |
| 184 | if ((position = bytes.position()) > 0) { |
| 185 | bytes.flip(); |
| 186 | out.write(bytes.array(), 0, position); |
| 187 | bytes.clear(); |
| 188 | } |
| 189 | out.flush(); |
| 190 | } |
| 191 | } |
| 192 | |
| 193 | private void checkStatus() throws IOException { |
| 194 | if (encoder == null) { |