/** * Flushes this output stream and forces any buffered output bytes * to be written out to the stream. * * @throws IOException if an I/O error occurs. */ @Override public void flush() throws IOException { flush(true); }
/** * Closes this output stream, flushing any remaining bytes that must be encoded. The * underlying stream is flushed but not closed. */ @Override public void close() throws IOException { // Notify encoder of EOF (-1). if (doEncode) { base64.encode(singleByte, 0, -1); } else { base64.decode(singleByte, 0, -1); } flush(); }
/** * Writes <code>len</code> bytes from the specified * <code>b</code> array starting at <code>offset</code> to * this output stream. * * @param b source byte array * @param offset where to start reading the bytes * @param len maximum number of bytes to write * * @throws IOException if an I/O error occurs. * @throws NullPointerException if the byte array parameter is null * @throws IndexOutOfBoundsException if offset, len or buffer size are invalid */ @Override public void write(byte b[], int offset, int len) throws IOException { if (b == null) { throw new NullPointerException(); } else if (offset < 0 || len < 0 || offset + len < 0) { throw new IndexOutOfBoundsException(); } else if (offset > b.length || offset + len > b.length) { throw new IndexOutOfBoundsException(); } else if (len > 0) { if (doEncode) { base64.encode(b, offset, len); } else { base64.decode(b, offset, len); } flush(false); } }