29package com.jogamp.common.util;
31import java.io.IOException;
32import java.nio.ByteBuffer;
34import org.junit.Assert;
37import com.jogamp.common.nio.Buffers;
38import com.jogamp.junit.util.SingletonJunitCase;
40import static com.jogamp.common.util.BitDemoData.*;
42import org.junit.FixMethodOrder;
43import org.junit.runners.MethodSorters;
53@FixMethodOrder(MethodSorters.NAME_ASCENDING)
58 test01Int8BitsAlignedImpl((
byte)0);
59 test01Int8BitsAlignedImpl((
byte)1);
60 test01Int8BitsAlignedImpl((
byte)7);
61 test01Int8BitsAlignedImpl(Byte.MIN_VALUE);
62 test01Int8BitsAlignedImpl(Byte.MAX_VALUE);
63 test01Int8BitsAlignedImpl((
byte)0xff);
65 void test01Int8BitsAlignedImpl(
final byte val8)
throws IOException {
68 System.err.println(
"XXX Test01Int8BitsAligned: value "+val8+
", "+toHexBinaryString(val8, 8));
75 System.err.println(
"Read8.1 "+r8+
", "+toHexBinaryString(r8, 8));
76 Assert.assertEquals(val8, r8);
85 System.err.println(
"Read8.2 "+r8+
", "+toHexBinaryString(r8, 8));
86 Assert.assertEquals(val8, r8);
92 test02Int8BitsUnalignedImpl(0);
93 test02Int8BitsUnalignedImpl(1);
94 test02Int8BitsUnalignedImpl(7);
95 test02Int8BitsUnalignedImpl(8);
96 test02Int8BitsUnalignedImpl(15);
97 test02Int8BitsUnalignedImpl(24);
98 test02Int8BitsUnalignedImpl(25);
100 void test02Int8BitsUnalignedImpl(
final int preBits)
throws IOException {
101 test02Int8BitsUnalignedImpl(preBits, (
byte)0);
102 test02Int8BitsUnalignedImpl(preBits, (
byte)1);
103 test02Int8BitsUnalignedImpl(preBits, (
byte)7);
104 test02Int8BitsUnalignedImpl(preBits, Byte.MIN_VALUE);
105 test02Int8BitsUnalignedImpl(preBits, Byte.MAX_VALUE);
106 test02Int8BitsUnalignedImpl(preBits, (
byte)0xff);
108 void test02Int8BitsUnalignedImpl(
final int preBits,
final byte val8)
throws IOException {
109 final int preBytes = ( preBits + 7 ) >>> 3;
110 final int byteCount = preBytes + Buffers.SIZEOF_BYTE;
111 final ByteBuffer bb = ByteBuffer.allocate(byteCount);
112 System.err.println(
"XXX Test02Int8BitsUnaligned: preBits "+preBits+
", value "+val8+
", "+toHexBinaryString(val8, 8));
115 final Bitstream.ByteBufferStream bbs =
new Bitstream.ByteBufferStream(bb);
116 final Bitstream<ByteBuffer> bs =
new Bitstream<ByteBuffer>(bbs,
true );
117 bs.writeBits31(preBits, 0);
119 bs.setStream(bs.getSubStream(),
false );
121 final int rPre = (short) bs.readBits31(preBits);
122 final byte r8 = (byte) bs.readUInt8();
123 System.err.println(
"ReadPre "+rPre+
", "+toBinaryString(rPre, preBits));
124 System.err.println(
"Read8 "+r8+
", "+toHexBinaryString(r8, 8));
125 Assert.assertEquals(val8, r8);
128 public static void main(
final String args[])
throws IOException {
130 org.junit.runner.JUnitCore.
main(tstname);
Utility methods allowing easy java.nio.Buffer manipulations.
static final int SIZEOF_BYTE
Versatile Bitstream implementation supporting:
final int writeInt8(final byte int8)
Write the given 8 bits via writeBits31(int, int).
final int readUInt8()
Return incoming uint8_t as read via readBits31(int).
final T getSubStream()
Returns the currently used ByteStream's ByteStream#getStream().
final void setStream(final T stream, final boolean outputMode)
Sets the underlying stream, without close()ing the previous one.
Test Bitstream w/ int8 read/write access w/ semantics as well as with aligned and unaligned access.
void test02Int8BitsUnaligned()
void test01Int8BitsAligned()
static void main(final String args[])