cz.cuni.jagrlib.iface
Interface BitStream

All Superinterfaces:
Property
All Known Implementing Classes:
BufferedBitStream, JavaBitStream

public interface BitStream
extends Property

Abstract sequential bit-input/output.

Since:
0.04
See Also:
BitStream.java

Field Summary
static java.lang.String DEFAULT_STREAM_NAME
          Default file name.
static java.lang.String STREAM_NAME
          Stream-name property (String): file-name etc.
 
Fields inherited from interface cz.cuni.jagrlib.iface.Property
LOGGING, STATISTICS, TEXT_DESCRIPTION
 
Method Summary
 long available()
          How many bits are available to read (or skip).
 boolean canRead()
          Stream is able to read data.
 void close()
          Stream close.
 void flush()
          Stream flush.
 java.io.InputStream getInputStream()
          Retrieves the associated input stream (non-mandatory).
 java.io.OutputStream getOutputStream()
          Retrieves the associated output stream (non-mandatory).
 void open(boolean output, java.lang.String name, java.lang.String detail)
          Stream initialization.
 long position()
          Actual stream position in bits.
 long read(int length)
          Reads a bunch of bits from the stream.
 void readBytes(byte[] data, int start, int length)
          Reads a bunch of bytes from the stream.
 void reOpen(boolean output, java.lang.String detail)
          Stream re-initialization.
 long seek(long pos)
          Sets actual position of the stream in bits.
 long skip(long length)
          Skips the given number of bits.
 void write(long bits, int length)
          Writes a bunch of bits into the stream.
 void writeBytes(byte[] data, int start, int length)
          Writes a bunch of bytes into the stream.
 
Methods inherited from interface cz.cuni.jagrlib.iface.Property
commit, get, set
 

Field Detail

STREAM_NAME

static final java.lang.String STREAM_NAME
Stream-name property (String): file-name etc.

See Also:
Constant Field Values

DEFAULT_STREAM_NAME

static final java.lang.String DEFAULT_STREAM_NAME
Default file name.

See Also:
Constant Field Values
Method Detail

canRead

boolean canRead()
Stream is able to read data. If true, stream can be opened automatically in the init-phase.


open

void open(boolean output,
          java.lang.String name,
          java.lang.String detail)
          throws java.io.IOException
Stream initialization.

Parameters:
output - Open for output?
name - Stream name (either stream identification e.g. file-name). null for implicit bit-stream (reOpen(boolean, java.lang.String)).
detail - Further implementation-specific information.
Throws:
java.io.IOException
See Also:
reOpen(boolean, java.lang.String)

reOpen

void reOpen(boolean output,
            java.lang.String detail)
            throws java.io.IOException
Stream re-initialization.

Parameters:
output - Open for output?
detail - Further implementation-specific information.
Throws:
java.io.IOException
See Also:
open(boolean, java.lang.String, java.lang.String)

getOutputStream

java.io.OutputStream getOutputStream()
Retrieves the associated output stream (non-mandatory).

Returns:
The associated OutputStream instance or null if not implemented.
See Also:
getInputStream()

getInputStream

java.io.InputStream getInputStream()
Retrieves the associated input stream (non-mandatory).

Returns:
The associated InputStream instance or null if not implemented.
See Also:
getOutputStream()

flush

void flush()
           throws java.io.IOException
Stream flush.

Throws:
java.io.IOException
See Also:
open(boolean, java.lang.String, java.lang.String), close()

close

void close()
           throws java.io.IOException
Stream close. Eventually flushes all written data and disconnects the stream.

Throws:
java.io.IOException
See Also:
open(boolean, java.lang.String, java.lang.String), reOpen(boolean, java.lang.String)

position

long position()
              throws java.io.IOException
Actual stream position in bits. After the output stream is closed, returns maximal written position.

Returns:
Actual (maximal) stream position in bits.
Throws:
java.io.IOException
See Also:
available(), seek(long)

available

long available()
               throws java.io.IOException
How many bits are available to read (or skip).

Returns:
Number of bits available to read (or skip).
Throws:
java.io.IOException
See Also:
position(), seek(long)

seek

long seek(long pos)
          throws java.io.IOException
Sets actual position of the stream in bits. Non mandatory.

Parameters:
pos - Required stream position in bits.
Returns:
New stream position in bits (or -1L if not implemented).
Throws:
java.io.IOException
See Also:
position()

write

void write(long bits,
           int length)
           throws java.io.IOException
Writes a bunch of bits into the stream.

Parameters:
bits - Bits to be written (LSB first).
length - Number of bits to write (negative lengths are ignored).
Throws:
java.io.IOException
See Also:
writeBytes(byte[], int, int), read(int)

writeBytes

void writeBytes(byte[] data,
                int start,
                int length)
                throws java.io.IOException
Writes a bunch of bytes into the stream.

Parameters:
data - Bytes to be written (each byte is written in "LSB first" order).
start - First index to write. Must be less than data.length.
length - Number of bytes to write (start + length > data.length is ignored).
Throws:
java.io.IOException
See Also:
write(long, int), readBytes(byte[], int, int)

read

long read(int length)
          throws java.io.IOException
Reads a bunch of bits from the stream.

Parameters:
length - Number of bits to read (negative lengths are ignored).
Returns:
Read bits (LSB first).
Throws:
java.io.IOException
See Also:
readBytes(byte[], int, int), write(long, int)

readBytes

void readBytes(byte[] data,
               int start,
               int length)
               throws java.io.IOException
Reads a bunch of bytes from the stream.

Parameters:
data - Array holding the read bytes (each byte is read in "LSB first" order).
start - First index to read. Must be less than data.length.
length - Number of bytes to read (start + length > data.length is ignored).
Throws:
java.io.IOException
See Also:
read(int), writeBytes(byte[], int, int)

skip

long skip(long length)
          throws java.io.IOException
Skips the given number of bits.

Parameters:
length - Number of bits to skip (negative lengths are ignored).
Returns:
Number of bits actually skipped.
Throws:
java.io.IOException
See Also:
read(int), seek(long)