/** * 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); }
/** * Writes the specified <code>byte</code> to this output stream. */ @Override public void write(int i) throws IOException { singleByte[0] = (byte) i; write(singleByte, 0, 1); }
wrappedOut = new QuotedPrintableOutputStream(out, false); } else if (MimeUtil.ENC_BASE64.equals(encoding)) { wrappedOut = new Base64OutputStream(out); } else { throw new RuntimeException("Target encoding not supported: " + encoding);
@Override public void writeTo(OutputStream outputStream) throws IOException, MessagingException { InputStream in = getInputStream(); if (in != null) { Base64OutputStream base64Out = new Base64OutputStream(outputStream); IOUtils.copy(in, base64Out); base64Out.close(); } else { Log.w(TAG, "input stream is null"); } } }
@Override public void writeTo(OutputStream out) throws IOException, MessagingException { InputStream in = getInputStream(); try { boolean closeStream = false; if (MimeUtil.isBase64Encoding(mEncoding)) { out = new Base64OutputStream(out); closeStream = true; } else if (MimeUtil.isQuotedPrintableEncoded(mEncoding)){ out = new QuotedPrintableOutputStream(out, false); closeStream = true; } try { IOUtils.copy(in, out); } finally { if (closeStream) { out.close(); } } } finally { in.close(); } }
/** * 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); } }