Top Description Inners Fields Constructors Methods
com.jogamp.common.util

public Class Bitstream<T>

extends Object
Class Inheritance
Imports
java.io.BufferedInputStream, .BufferedOutputStream, .IOException, .InputStream, .OutputStream, java.nio.ByteBuffer, jogamp.common.Debug

Versatile Bitstream implementation supporting:

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
public static class
public static class
public static class
public static interface
Bitstream.ByteStream<T>

General byte stream.

Field Summary

Modifier and TypeField and Description
private int
bitBuffer

8-bit cache of byte stream

private int
private int
private int
private Bitstream.ByteStream<T>
private static final boolean
public static final int
EOS

End of stream marker, or 0xFFFFFFFF

private boolean
private static final String
private boolean
private static final boolean
private static final boolean

Constructor Summary

AccessConstructor and Description
public
Bitstream(final Bitstream.ByteStream<T> stream, final boolean outputMode)

Method Summary

Modifier and TypeMethod and Description
public final boolean
canInput()

Return true if stream can handle input, i.e. readBit(boolean).

public final boolean
canOutput()

Return true if stream can handle output, i.e. writeBit(boolean, int).

public static void
checkBounds(final byte[] sb, final int offset, final int remaining)

public final void
close()

Closing the underlying stream, implies flush().

public final int

Returns:

EOS caused by writing, otherwise zero.
flush
()

Synchronizes all underlying output stream operations, or do nothing.

public final int
getBitBuffer()

Returns the current bit buffer.

public final int
getBitCount()

Number of remaining bits in cache to read before next byte-read (input mode) or number of remaining bits to be cached before next byte-write (output mode).

public final int
getBitPosition()

Return the next bit number to be read or write counting from [0..7].

public final int
getLastBitPos()

Return the last bit number read or written counting from [0..7].

public final Bitstream.ByteStream<T>
getStream()

Returns the currently used ByteStream.

public final T
getSubStream()

Returns the currently used ByteStream's ByteStream#getStream().

public final boolean
getThrowIOExceptionOnEOF()

Returns true if I/O methods throw an IOException if EOS appears, otherwise false (default).

public final void
mark(final int
maximum number of bytes able to read before invalidating the markpos.
readLimit
)

Set markpos to current position, allowing the stream to be reset().

public final long
position()

Returns the bit position in the stream.

public final long

Returns:

The new set position or Bitstream#EOS if end-of-stream is reached.
position
(final long
The new positive position.
newPosition
)

Sets this stream's bit position.

public final int

Returns:

the read bit or EOS if end-of-stream is reached.
readBit
(final boolean
if true incoming stream bit order is MSB to LSB, otherwise LSB to MSB.
msbFirst
)

public int

Returns:

the read bits from 0-n in the given order or EOS.
readBits31
(final int
number of bits, maximum 31 bits
n
)

Return incoming bits as read via readBit(boolean) LSB-first as little-endian.

public final int

Returns:

EOS or the 16bit unsigned value within the lower bits.
readUInt16
(final boolean
if true, swap incoming bytes to little-endian, otherwise leave them as little-endian.
bigEndian
)

Return incoming uint16_t as read via readBits31(int) LSB-first as little-endian, hence bytes are swapped if bigEndian.

public static final int

Returns:

the 16bit unsigned value within the lower bits.
readUInt16
(final boolean
if false, swap incoming bytes to little-endian, otherwise leave them as big-endian.
bigEndian
,
final byte[] bytes, final int offset)

Return incoming uint16_t value and swap bytes according to bigEndian.

public final long

Returns:

EOS or the 32bit unsigned value within the lower bits.
readUInt32
(final boolean
if true, swap incoming bytes to little-endian, otherwise leave them as little-endian.
bigEndian
)

Return incoming uint32_t as read via readBits31(int) LSB-first as little-endian, hence bytes are swapped if bigEndian.

public static final long

Returns:

the 32bit unsigned value within the lower bits.
readUInt32
(final boolean
if false, swap incoming bytes to little-endian, otherwise leave them as big-endian.
bigEndian
,
final byte[] bytes, final int offset)

Return incoming uint32_t and swap bytes according to bigEndian.

public final int

Returns:

EOS or the 8bit unsigned value within the lower bits.
readUInt8
()

Return incoming uint8_t as read via readBits31(int).

public final void
reset()

Reset stream position to markpos as set via mark(int).

private final void
public final void
setStream(final T stream, final boolean outputMode)

Sets the underlying stream, without close()ing the previous one.

public final void
setThrowIOExceptionOnEOF(final boolean enable)

Enables or disables throwing an IOException in case EOS appears.

public long

Returns:

actual skipped bits
skip
(final long
number of bits to skip
n
)

It is implementation dependent, whether backward skip giving a negative number is supported or not.

public static String
toBinString(final boolean msbFirst, final int v, final int bitCount)

public static String
toHexBinString(final boolean msbFirst, final int v, final int bitCount)

public static final String
toHexBinString(final boolean msbFirst, final byte[] data, final int offset, final int len)

public static final String
toHexBinString(final boolean msbFirst, final ByteBuffer data, final int offset, final int len)

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
protected String
public static final int
toUInt32Int(final int int32)

Returns the reinterpreted given int32_t value as uint32_t if ≤ Integer#MAX_VALUE as within an int storage.

public static final long
toUInt32Long(final int int32)

Reinterpret the given int32_t value as uint32_t, i.e. perform the following cast to long:

  final long l = 0xffffffffL & int32;
public static final int
uint32LongToInt(final long uint32)

Returns the given uint32_t value long value as int if ≤ Integer#MAX_VALUE.

private final void
public final int

Returns:

the currently written byte or EOS if end-of-stream is reached.
writeBit
(final boolean
if true outgoing stream bit order is MSB to LSB, otherwise LSB to MSB.
msbFirst
,
final int bit)

public int

Returns:

the written bits or EOS.
writeBits31
(final int
number of bits, maximum 31 bits
n
,
final int
the bits to write
bits
)

Write the given bits via writeBit(boolean, int) LSB-first as little-endian.

public final int

Returns:

EOS or the written 16bit value.
writeInt16
(final boolean
if true, swap given bytes to little-endian, otherwise leave them as little-endian.
bigEndian
,
final short int16)

Write the given 16 bits via writeBits31(int, int) LSB-first as little-endian, hence bytes are swapped if bigEndian.

public final int

Returns:

EOS or the written 32bit value.
writeInt32
(final boolean
if true, swap given bytes to little-endian, otherwise leave them as little-endian.
bigEndian
,
final int int32)

Write the given 32 bits via writeBits31(int, int) LSB-first as little-endian, hence bytes are swapped if bigEndian.

public final int

Returns:

EOS or the written 8bit value.
writeInt8
(final byte int8)

Write the given 8 bits via writeBits31(int, int).

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait