1616
1717package com .igormaznitsa .jbbp .io ;
1818
19+ import static java .util .Objects .requireNonNull ;
20+ 1921import com .igormaznitsa .jbbp .utils .JBBPUtils ;
2022import java .io .FilterOutputStream ;
2123import java .io .IOException ;
2830 */
2931public class JBBPBitOutputStream extends FilterOutputStream implements JBBPCountableBitStream {
3032 /**
31- * Flag shows that bit operations must be processed for MSB0 (most significant
32- * bit 0) mode.
33+ * Contains bit mode for bit operations.
3334 */
34- private final boolean msb0 ;
35+ private final JBBPBitOrder bitOrderMode ;
3536 /**
3637 * Inside bit buffer.
3738 */
@@ -58,13 +59,13 @@ public JBBPBitOutputStream(final OutputStream out) {
5859 * A Constructor.
5960 *
6061 * @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.
6263 * @see JBBPBitOrder#LSB0
6364 * @see JBBPBitOrder#MSB0
6465 */
65- public JBBPBitOutputStream (final OutputStream out , final JBBPBitOrder order ) {
66+ public JBBPBitOutputStream (final OutputStream out , final JBBPBitOrder bitOrderMode ) {
6667 super (out );
67- this .msb0 = order == JBBPBitOrder . MSB0 ;
68+ this .bitOrderMode = requireNonNull ( bitOrderMode , "Bit order mode must not be null" ) ;
6869 }
6970
7071 /**
@@ -76,7 +77,7 @@ public JBBPBitOutputStream(final OutputStream out, final JBBPBitOrder order) {
7677 */
7778 @ Override
7879 public JBBPBitOrder getBitOrder () {
79- return this .msb0 ? JBBPBitOrder . MSB0 : JBBPBitOrder . LSB0 ;
80+ return this .bitOrderMode ;
8081 }
8182
8283 /**
@@ -249,7 +250,7 @@ public void flush() throws IOException {
249250
250251 @ Override
251252 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 ) {
253254 int i = off ;
254255 int cnt = len ;
255256 while (cnt > 0 ) {
@@ -333,7 +334,7 @@ public void align(final long alignByteNumber) throws IOException {
333334 * @throws IOException it will be thrown for transport problems
334335 */
335336 private void writeByte (int value ) throws IOException {
336- if (this .msb0 ) {
337+ if (this .bitOrderMode == JBBPBitOrder . MSB0 ) {
337338 value = JBBPUtils .reverseBitsInByte ((byte ) value ) & 0xFF ;
338339 }
339340 this .out .write (value );
0 commit comments