edu.columbia.ee.flavor
Class Bitstream

java.lang.Object
  extended byedu.columbia.ee.flavor.Bitstream
All Implemented Interfaces:
IBitstream

public class Bitstream
extends java.lang.Object
implements IBitstream

Implementation of class to access a bitstream.


Field Summary
protected  byte[] buf
           
protected  int buf_len
           
static int BUF_LEN
           
protected  boolean close_fd
           
static int[] cmask
           
protected  int cur_bit
           
protected  boolean eof
           
protected  java.io.InputStream in
           
static long LONG_SIGN
           
static int[] mask
           
static int MAX_SIZE_OF_BITS
           
protected  java.io.OutputStream out
           
static int[] smask
           
protected  int total_bits
           
protected  int type
           
 
Fields inherited from interface edu.columbia.ee.flavor.IBitstream
BS_INPUT, BS_OUTPUT
 
Constructor Summary
Bitstream(java.io.InputStream input)
          Constructs input bitstream.
Bitstream(java.io.InputStream input, int _buf_len)
          Constructs input bitstream with the given buffer length.
Bitstream(java.io.OutputStream output)
          Constructs output bitstream.
Bitstream(java.io.OutputStream output, int _buf_len)
          Constructs an output bitstream with the given buffer length.
Bitstream(java.lang.String filename, int _type)
          Constructs either an output or an input stream, depending on the type
Bitstream(java.lang.String filename, int _type, int _buf_len)
          Constructs either an output or an input stream, depending on the type, with the given buffer length.
 
Method Summary
 int align(int n)
          Align bitstream
 boolean atend()
          Check eof-of-file flag
 void close()
          close file
protected  void finalize()
          close opened files
 void flushbits()
          Flush all content in the buffer
 int getbits(int n)
          Get next n bits
 int getCurrentBit()
          Return current bit position
 double getdouble()
          Get double value(64 bits) from bistream
 float getfloat()
          Get float value(32 bits) from the bistream
 int getmode()
          Return mode(BS_INPUT or BS_OUTPUT)
 int getpos()
          Current bit position
 int little_getbits(int n)
          Gets bits in little order.
 double little_getdouble()
          Gets next double value in next 32 bits using the little-endian method (output only)
 float little_getfloat()
          Gets next float value in next 32 bits using the little-endian method (input only)
 int little_nextbits(int n)
          Probes 'n' bits as unsigned value using the little-endian method (input only)
 double little_nextdouble()
          Probes next double value in next 32 bits using the little-endian method (input only)
 float little_nextfloat()
          Probes next float value in next 32 bits using the little-endian method (input only)
 int little_putbits(int y, int n)
          Puts 'n' bits using the little-endian method (output only)
 double little_putdouble(double d)
          Puts double value into next 32 bits using the little-endian method (output only)
 float little_putfloat(float f)
          Puts float value into next 32 bits using the little-endian method (input only)
 int little_sgetbits(int n)
          Gets next 'n' bits as signed value using the little-endian method (input only)
 int little_snextbits(int n)
          Probes 'n' bits as signed value using the little-endian method (input only)
static void main(java.lang.String[] args)
           
 int nextbits(int n)
          Peek next n bits
 double nextdouble()
          Get next double value from bistream
 float nextfloat()
          Peak float value(32 bits) from the bistream
 int putbits(int y, int n)
          Put n bits
 double putdouble(double d)
          Put a double value into bitstream
 float putfloat(float f)
          Put float value(32 bits) into bistream
 int sgetbits(int n)
          Get next n bits Java does not support unsigned type Remains only for compatibility with C++ language Blindly calls sgetbits
 void skipbits(int n)
          Skip n bits
 int snextbits(int n)
          Peek next n bits - signed value
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

BUF_LEN

public static final int BUF_LEN
See Also:
Constant Field Values

LONG_SIGN

public static long LONG_SIGN

MAX_SIZE_OF_BITS

public static int MAX_SIZE_OF_BITS

mask

public static final int[] mask

cmask

public static final int[] cmask

smask

public static final int[] smask

close_fd

protected boolean close_fd

buf_len

protected int buf_len

buf

protected byte[] buf

cur_bit

protected int cur_bit

total_bits

protected int total_bits

eof

protected boolean eof

in

protected java.io.InputStream in

out

protected java.io.OutputStream out

type

protected int type
Constructor Detail

Bitstream

public Bitstream(java.io.InputStream input)
          throws FlIOException
Constructs input bitstream.

Parameters:
input -
Throws:
FlIOException

Bitstream

public Bitstream(java.io.OutputStream output)
          throws FlIOException
Constructs output bitstream.

Parameters:
output -
Throws:
FlIOException

Bitstream

public Bitstream(java.io.InputStream input,
                 int _buf_len)
          throws FlIOException
Constructs input bitstream with the given buffer length.

Parameters:
input -
_buf_len -
Throws:
FlIOException

Bitstream

public Bitstream(java.io.OutputStream output,
                 int _buf_len)
          throws FlIOException
Constructs an output bitstream with the given buffer length.

Parameters:
output -
_buf_len -
Throws:
FlIOException

Bitstream

public Bitstream(java.lang.String filename,
                 int _type)
          throws FlIOException
Constructs either an output or an input stream, depending on the type

Parameters:
filename - file name to open
_type - I/O type( BS_INPUT or BS_OUTPUT )
Throws:
FlIOException

Bitstream

public Bitstream(java.lang.String filename,
                 int _type,
                 int _buf_len)
          throws FlIOException
Constructs either an output or an input stream, depending on the type, with the given buffer length.

Parameters:
filename - file name to open
_type - I/O type( BS_INPUT or BS_OUTPUT )
_buf_len - buffer size
Throws:
FlIOException
Method Detail

finalize

protected void finalize()
                 throws java.lang.Throwable
close opened files

Throws:
java.lang.Throwable
See Also:
Object.finalize()

close

public void close()
           throws FlIOException
close file

Throws:
FlIOException

atend

public boolean atend()
Check eof-of-file flag

Specified by:
atend in interface IBitstream
Returns:
true if at end of file

getpos

public int getpos()
Current bit position

Specified by:
getpos in interface IBitstream
Returns:
the count of bits so far

getbits

public int getbits(int n)
            throws FlIOException
Get next n bits

Specified by:
getbits in interface IBitstream
Parameters:
n - number of bits to be fetched
Returns:
the value of the fetched bits
Throws:
FlIOException - when n > 32

sgetbits

public int sgetbits(int n)
             throws FlIOException
Get next n bits Java does not support unsigned type Remains only for compatibility with C++ language Blindly calls sgetbits

Specified by:
sgetbits in interface IBitstream
Parameters:
n - The number of bits to get
Returns:
The value of next n bits
Throws:
FlIOException - if an I/O error occurs
See Also:
throws FlIOException

nextbits

public int nextbits(int n)
             throws FlIOException
Peek next n bits

Specified by:
nextbits in interface IBitstream
Parameters:
n - number of bits to peek
Returns:
the value of the peeked bits
Throws:
FlIOException - when n > 32 eof-of-file not enough data

snextbits

public int snextbits(int n)
              throws FlIOException
Peek next n bits - signed value

Specified by:
snextbits in interface IBitstream
Parameters:
n - number of bits to peek
Returns:
the signed value of the peeked bits
Throws:
FlIOException - when n > 32 eof-of-file not enough data

getfloat

public float getfloat()
               throws FlIOException
Get float value(32 bits) from the bistream

Specified by:
getfloat in interface IBitstream
Returns:
float value
Throws:
FlIOException

nextfloat

public float nextfloat()
                throws FlIOException
Peak float value(32 bits) from the bistream

Specified by:
nextfloat in interface IBitstream
Returns:
float value
Throws:
FlIOException

getdouble

public double getdouble()
                 throws FlIOException
Get double value(64 bits) from bistream

Specified by:
getdouble in interface IBitstream
Returns:
double value
Throws:
FlIOException

nextdouble

public double nextdouble()
                  throws FlIOException
Get next double value from bistream

Specified by:
nextdouble in interface IBitstream
Returns:
double value
Throws:
FlIOException

putbits

public int putbits(int y,
                   int n)
            throws FlIOException
Put n bits

Specified by:
putbits in interface IBitstream
Parameters:
y - value to put
n - number of bits to put ( <= 32 bits)
Returns:
y
Throws:
FlIOException

putfloat

public float putfloat(float f)
               throws FlIOException
Put float value(32 bits) into bistream

Specified by:
putfloat in interface IBitstream
Parameters:
f - float value
Returns:
float value
Throws:
FlIOException

putdouble

public double putdouble(double d)
                 throws FlIOException
Put a double value into bitstream

Specified by:
putdouble in interface IBitstream
Parameters:
d - double variable
Returns:
the double value
Throws:
FlIOException - if putbits() fails

little_getbits

public int little_getbits(int n)
                   throws FlIOException
Gets bits in little order.

Specified by:
little_getbits in interface IBitstream
Parameters:
n - bits to get
Returns:
value
Throws:
FlIOException

little_sgetbits

public int little_sgetbits(int n)
                    throws FlIOException
Description copied from interface: IBitstream
Gets next 'n' bits as signed value using the little-endian method (input only)

Specified by:
little_sgetbits in interface IBitstream
Parameters:
n - The number of bits to get
Returns:
The value of next n bits
Throws:
FlIOException - if an I/O error occurs

little_nextbits

public int little_nextbits(int n)
                    throws FlIOException
Description copied from interface: IBitstream
Probes 'n' bits as unsigned value using the little-endian method (input only)

Specified by:
little_nextbits in interface IBitstream
Parameters:
n - The number of bits to get
Returns:
The value of next n bits
Throws:
FlIOException - if an I/O error occurs

little_snextbits

public int little_snextbits(int n)
                     throws FlIOException
Description copied from interface: IBitstream
Probes 'n' bits as signed value using the little-endian method (input only)

Specified by:
little_snextbits in interface IBitstream
Parameters:
n - The number of bits to get
Returns:
The value of next n bits
Throws:
FlIOException - if an I/O error occurs

little_getfloat

public float little_getfloat()
                      throws FlIOException
Description copied from interface: IBitstream
Gets next float value in next 32 bits using the little-endian method (input only)

Specified by:
little_getfloat in interface IBitstream
Returns:
The float value
Throws:
FlIOException - if an I/O error occurs

little_nextfloat

public float little_nextfloat()
                       throws FlIOException
Description copied from interface: IBitstream
Probes next float value in next 32 bits using the little-endian method (input only)

Specified by:
little_nextfloat in interface IBitstream
Returns:
The float value
Throws:
FlIOException - if an I/O error occurs

little_getdouble

public double little_getdouble()
                        throws FlIOException
Description copied from interface: IBitstream
Gets next double value in next 32 bits using the little-endian method (output only)

Specified by:
little_getdouble in interface IBitstream
Returns:
The double value
Throws:
FlIOException - if an I/O error occurs

little_nextdouble

public double little_nextdouble()
                         throws FlIOException
Description copied from interface: IBitstream
Probes next double value in next 32 bits using the little-endian method (input only)

Specified by:
little_nextdouble in interface IBitstream
Returns:
The double value
Throws:
FlIOException - if an I/O error occurs

little_putbits

public int little_putbits(int y,
                          int n)
                   throws FlIOException
Description copied from interface: IBitstream
Puts 'n' bits using the little-endian method (output only)

Specified by:
little_putbits in interface IBitstream
Parameters:
y - The value to put
n - The number of bits to put
Returns:
The value put into the bitstream
Throws:
FlIOException - if an I/O error occurs

little_putfloat

public float little_putfloat(float f)
                      throws FlIOException
Description copied from interface: IBitstream
Puts float value into next 32 bits using the little-endian method (input only)

Specified by:
little_putfloat in interface IBitstream
Parameters:
f - The float value to put
Returns:
The value put into the bit stream
Throws:
FlIOException - if an I/O error occurs

little_putdouble

public double little_putdouble(double d)
                        throws FlIOException
Description copied from interface: IBitstream
Puts double value into next 32 bits using the little-endian method (output only)

Specified by:
little_putdouble in interface IBitstream
Parameters:
d - The double value to put
Returns:
value put into the bit stream
Throws:
FlIOException - if an I/O error occurs

skipbits

public void skipbits(int n)
              throws FlIOException
Skip n bits

Specified by:
skipbits in interface IBitstream
Parameters:
n - number of bits to skip
Throws:
FlIOException

align

public int align(int n)
          throws FlIOException
Align bitstream

Specified by:
align in interface IBitstream
Parameters:
n - number of bits to align on
Returns:
the number of skipped bits
Throws:
FlIOException

flushbits

public void flushbits()
               throws FlIOException
Flush all content in the buffer

Throws:
FlIOException

getCurrentBit

public int getCurrentBit()
Return current bit position

Returns:
current bit position

main

public static void main(java.lang.String[] args)

getmode

public int getmode()
Return mode(BS_INPUT or BS_OUTPUT)

Specified by:
getmode in interface IBitstream
Returns:
BS_INPUT or BS_OUPUT