jinahya / bit-io

A library for reading/writing arbitrary length of bits.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add a flush operation, to write last octet to underlying without advancing

Jan-M opened this issue · comments

Great stuff, but sadly I do now miss the "flush()" that basically writes through to byte buffer without advancing the position. As I do have a concurrent read on the ByteBuffer I need all Bits also in the last octet filled (padded with 0)

I don't want to call align(8) after every write as my data consumes only 2 bits in many cases.

    private void flush() throws IOException {
        long padded = output.align(1);
        if (padded == 0) return;

        byte cb = data.get(data.position() - 1);
        data.position(data.position() - 1);
        output.writeByte(false, 8 - (int) padded, (byte)(cb>>padded));
    }

Fixed this myself on my end. Need some more understanding on how stuff works first.

Moin moin. Thanks for the issue. Please let me know if there is anything that I can do for you.