Skip to content

jinahya/bit-io2

Folders and files

NameName
Last commit message
Last commit date

Latest commit

99984d7 · Oct 30, 2022
Oct 10, 2022
Dec 31, 2021
May 28, 2022
Oct 30, 2022
Apr 22, 2020
Dec 31, 2021
Apr 22, 2020
Oct 10, 2022
May 18, 2020
May 28, 2022
May 28, 2022
Oct 30, 2022

Repository files navigation

bit-io2

GitHub Action Quality Gate Status Maven Central javadoc

A Java 8+ flavored version of bit-io.

How to use?

Add this module as a dependency. Check the central for the current version.

<dependency>
  <groupId>com.github.jinahya</groupId>
  <artifactId>bit-io2</artifactId>
</dependency>
OutputStream stream = open();
BitOutput output = BitOutputAdapter.from(stream);
output.writeBoolean(true);       // 1 bit   1
output.writeInt(true, 3, 1);     // 3 bits  4
output writeLong(false, 37, 0L); // 37 bits 41        
long padded = output.align(1);
assert padded == 7L;
assert (padded + 41) % Byte.SIZE == 0;

InputStream stream = open();
BitInput input = BitInputAdapter.from(stream);
boolean v1 = input.readBoolean();    // 1 bit   1
int v2 = input.readInt(true, 3);     // 3 bits  4
assert v2 == 1;
long v3 = input.readLong(false, 37); // 37 bits 41
assert v3 == 0L;        
long discarded = input.align(1);
assert discarded == 7L;
assert (discarded + 41) % Byte.SIZE == 0;

See Specifications and Recipes for more information.