Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f13b12d4 authored by Doug Zongker's avatar Doug Zongker
Browse files

add NO_CLOSE flag for use by Base64OutputStream

Change-Id: Ib2884e7b3853e4e4b2e329edf47c6f64c2f165a7
parent a32a6a42
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -51,6 +51,13 @@ public class Base64 {
     */
    public static final int WEB_SAFE = 8;

    /**
     * Flag to pass to Base64OutputStream to indicate that it should
     * not close the output stream it is wrapping when it itself is
     * closed.
     */
    public static final int NO_CLOSE = 16;

    //  --------------------------------------------------------
    //  decoding
    //  --------------------------------------------------------
+7 −1
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@ public class Base64OutputStream extends FilterOutputStream {
    private final boolean encode;
    private final Base64.EncoderState estate;
    private final Base64.DecoderState dstate;
    private final int flags;

    private byte[] buffer = null;
    private int bpos = 0;
@@ -59,6 +60,7 @@ public class Base64OutputStream extends FilterOutputStream {
     */
    public Base64OutputStream(OutputStream out, int flags, boolean encode) {
        super(out);
        this.flags = flags;
        this.encode = encode;
        if (encode) {
            estate = new Base64.EncoderState(flags, null);
@@ -106,7 +108,11 @@ public class Base64OutputStream extends FilterOutputStream {
    public void close() throws IOException {
        flushBuffer();
        internalWrite(EMPTY, 0, 0, true);
        if ((flags & Base64.NO_CLOSE) == 0) {
            out.close();
        } else {
            out.flush();
        }
    }

    /**