Bzip2BitWriter Class — netty Architecture
Architecture documentation for the Bzip2BitWriter class in Bzip2BitWriter.java from the netty codebase.
Entity Profile
Dependency Diagram
graph TD 31f32361_6352_65c5_783c_9a4bef96677a["Bzip2BitWriter"] 400738df_ef64_d39b_ae15_40c84579b320["Bzip2BitWriter.java"] 31f32361_6352_65c5_783c_9a4bef96677a -->|defined in| 400738df_ef64_d39b_ae15_40c84579b320 0786eee7_4e0c_3f4f_870d_2f59e7bdce79["writeBits()"] 31f32361_6352_65c5_783c_9a4bef96677a -->|method| 0786eee7_4e0c_3f4f_870d_2f59e7bdce79 9b0914d9_a7ef_eafe_50f7_e250ebc0b7e9["writeBoolean()"] 31f32361_6352_65c5_783c_9a4bef96677a -->|method| 9b0914d9_a7ef_eafe_50f7_e250ebc0b7e9 44f18ee1_4616_636b_d261_1720d63087fe["writeUnary()"] 31f32361_6352_65c5_783c_9a4bef96677a -->|method| 44f18ee1_4616_636b_d261_1720d63087fe 1f89857b_deb5_14dc_2930_fb3b01467626["writeInt()"] 31f32361_6352_65c5_783c_9a4bef96677a -->|method| 1f89857b_deb5_14dc_2930_fb3b01467626 c93ca0da_79fe_cbdd_8836_973196204277["flush()"] 31f32361_6352_65c5_783c_9a4bef96677a -->|method| c93ca0da_79fe_cbdd_8836_973196204277
Relationship Graph
Source Code
codec-compression/src/main/java/io/netty/handler/codec/compression/Bzip2BitWriter.java lines 25–120
final class Bzip2BitWriter {
/**
* A buffer of bits waiting to be written to the output stream.
*/
private long bitBuffer;
/**
* The number of bits currently buffered in {@link #bitBuffer}.
*/
private int bitCount;
/**
* Writes up to 32 bits to the output {@link ByteBuf}.
* @param count The number of bits to write (maximum {@code 32} as a size of {@code int})
* @param value The bits to write
*/
void writeBits(ByteBuf out, final int count, final long value) {
if (count < 0 || count > 32) {
throw new IllegalArgumentException("count: " + count + " (expected: 0-32)");
}
int bitCount = this.bitCount;
long bitBuffer = this.bitBuffer | value << 64 - count >>> bitCount;
bitCount += count;
if (bitCount >= 32) {
out.writeInt((int) (bitBuffer >>> 32));
bitBuffer <<= 32;
bitCount -= 32;
}
this.bitBuffer = bitBuffer;
this.bitCount = bitCount;
}
/**
* Writes a single bit to the output {@link ByteBuf}.
* @param value The bit to write
*/
void writeBoolean(ByteBuf out, final boolean value) {
int bitCount = this.bitCount + 1;
long bitBuffer = this.bitBuffer | (value ? 1L << 64 - bitCount : 0L);
if (bitCount == 32) {
out.writeInt((int) (bitBuffer >>> 32));
bitBuffer = 0;
bitCount = 0;
}
this.bitBuffer = bitBuffer;
this.bitCount = bitCount;
}
/**
* Writes a zero-terminated unary number to the output {@link ByteBuf}.
* Example of the output for value = 6: {@code 1111110}
* @param value The number of {@code 1} to write
*/
void writeUnary(ByteBuf out, int value) {
if (value < 0) {
throw new IllegalArgumentException("value: " + value + " (expected 0 or more)");
}
while (value-- > 0) {
writeBoolean(out, true);
}
writeBoolean(out, false);
}
/**
* Writes an integer as 32 bits to the output {@link ByteBuf}.
* @param value The integer to write
*/
void writeInt(ByteBuf out, final int value) {
writeBits(out, 32, value);
}
/**
* Writes any remaining bits to the output {@link ByteBuf},
* zero padding to a whole byte as required.
*/
void flush(ByteBuf out) {
final int bitCount = this.bitCount;
if (bitCount > 0) {
Source
Frequently Asked Questions
What is the Bzip2BitWriter class?
Bzip2BitWriter is a class in the netty codebase, defined in codec-compression/src/main/java/io/netty/handler/codec/compression/Bzip2BitWriter.java.
Where is Bzip2BitWriter defined?
Bzip2BitWriter is defined in codec-compression/src/main/java/io/netty/handler/codec/compression/Bzip2BitWriter.java at line 25.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free