16
16
17
17
package com .igormaznitsa .jbbp .io ;
18
18
19
+ import static java .util .Objects .requireNonNull ;
20
+
19
21
import com .igormaznitsa .jbbp .utils .JBBPUtils ;
20
22
import java .io .FilterOutputStream ;
21
23
import java .io .IOException ;
28
30
*/
29
31
public class JBBPBitOutputStream extends FilterOutputStream implements JBBPCountableBitStream {
30
32
/**
31
- * Flag shows that bit operations must be processed for MSB0 (most significant
32
- * bit 0) mode.
33
+ * Contains bit mode for bit operations.
33
34
*/
34
- private final boolean msb0 ;
35
+ private final JBBPBitOrder bitOrderMode ;
35
36
/**
36
37
* Inside bit buffer.
37
38
*/
@@ -58,13 +59,13 @@ public JBBPBitOutputStream(final OutputStream out) {
58
59
* A Constructor.
59
60
*
60
61
* @param out an output stream to be filtered.
61
- * @param order a bit writing mode to used for writing operations.
62
+ * @param bitOrderMode a bit writing mode to used for writing operations.
62
63
* @see JBBPBitOrder#LSB0
63
64
* @see JBBPBitOrder#MSB0
64
65
*/
65
- public JBBPBitOutputStream (final OutputStream out , final JBBPBitOrder order ) {
66
+ public JBBPBitOutputStream (final OutputStream out , final JBBPBitOrder bitOrderMode ) {
66
67
super (out );
67
- this .msb0 = order == JBBPBitOrder . MSB0 ;
68
+ this .bitOrderMode = requireNonNull ( bitOrderMode , "Bit order mode must not be null" ) ;
68
69
}
69
70
70
71
/**
@@ -76,7 +77,7 @@ public JBBPBitOutputStream(final OutputStream out, final JBBPBitOrder order) {
76
77
*/
77
78
@ Override
78
79
public JBBPBitOrder getBitOrder () {
79
- return this .msb0 ? JBBPBitOrder . MSB0 : JBBPBitOrder . LSB0 ;
80
+ return this .bitOrderMode ;
80
81
}
81
82
82
83
/**
@@ -249,7 +250,7 @@ public void flush() throws IOException {
249
250
250
251
@ Override
251
252
public void write (final byte [] b , final int off , final int len ) throws IOException {
252
- if (this .msb0 || this .bitBufferCount != 0 ) {
253
+ if (this .bitOrderMode == JBBPBitOrder . MSB0 || this .bitBufferCount != 0 ) {
253
254
int i = off ;
254
255
int cnt = len ;
255
256
while (cnt > 0 ) {
@@ -333,7 +334,7 @@ public void align(final long alignByteNumber) throws IOException {
333
334
* @throws IOException it will be thrown for transport problems
334
335
*/
335
336
private void writeByte (int value ) throws IOException {
336
- if (this .msb0 ) {
337
+ if (this .bitOrderMode == JBBPBitOrder . MSB0 ) {
337
338
value = JBBPUtils .reverseBitsInByte ((byte ) value ) & 0xFF ;
338
339
}
339
340
this .out .write (value );
0 commit comments