@Override
    public void flush() {
        if (cacheMask != 0x80) {
            writeByte(cache);
            cache = 0;
            cacheMask = 0x80;
        }
    }
Output stream writing to a byte array, and capable of writing 1 bit at a time, starting from the most significant bit.
src/main/java/org/apache/commons/imaging/formats/tiff/itu_t4/BitArrayOutputStream.java