public void writeBit(final int bit) {
        if (bit != 0) {
            cache |= cacheMask;
        }
        cacheMask >>>= 1;
        if (cacheMask == 0) {
            flush();
        }
    }
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