Package ej.ecom.io
Interface BitsInput
-
public interface BitsInputThis interface defines methods for reading data bits.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description intgetLength()Returns the data length in bits (1 to 32 bits).intreadBits(boolean signExtends)Reads the next value of data from the input stream.intreadBits(byte[] data, boolean signExtends)Reads some number of values from the input stream and stores them into the buffer arraydata.intreadBits(byte[] data, int off, int len, boolean signExtends)Reads up tolenvalues of data from the input stream into an array of values.intreadBits(int[] data, boolean signExtends)Reads some number of values from the input stream and stores them into the buffer arraydata.intreadBits(int[] data, int off, int len, boolean signExtends)Reads up tolenvalues of data from the input stream into an array of values.intreadBits(short[] data, boolean signExtends)Reads some number of values from the input stream and stores them into the buffer arraydata.intreadBits(short[] data, int off, int len, boolean signExtends)Reads up tolenvalues of data from the input stream into an array of values.
-
-
-
Method Detail
-
getLength
int getLength()
Returns the data length in bits (1 to 32 bits).- Returns:
- the data length in bits (1 to 32 bits).
-
readBits
int readBits(boolean signExtends) throws IOException, EOFExceptionReads the next value of data from the input stream. The value is returned as anintin the range0to(1 << getLength) - 1. If no value is available because the end of the stream has been reached, the value an EOFException is thrown. This method blocks until input data is available, the end of the stream is detected, or an exception is thrown.
A subclass must provide an implementation of this method.- Parameters:
signExtends- true to sign-extends the result using the formularet = (ret << (32-getLength())) >> (32-getLength())- Returns:
- the next value
- Throws:
IOException- if an I/O error occurs. In particular, an IOException may be thrown if the input stream has been closed.EOFException- if the end of stream is reached
-
readBits
int readBits(int[] data, boolean signExtends) throws IOExceptionReads some number of values from the input stream and stores them into the buffer arraydata. The number of values actually read is returned as an integer. This method blocks until input value is available, end of file is detected, or an exception is thrown.
Ifdatais null, aNullPointerExceptionis thrown. If the length ofdatais zero, then no value are read and0is returned; otherwise, there is an attempt to read at least one value. If no value is available because the stream is at end of file, anEOFExceptionis thrown; otherwise, at least one value is read and stored intodata.
The first value read is stored into elementdata[0], the next one intodata[1], and so on. The number of value read is, at most, equal to the length ofdata. Letkbe the number of values actually read; these values will be stored in elementsdata[0]throughdata[k-1], leaving elementsdata[k]throughdata[data.length-1]unaffected.
If the first value cannot be read for any reason other than end of file, then an IOException is thrown. In particular, an IOException is thrown if the input stream has been closed.
ThereadBits(data, signExtends)method for classBitsInputhas the same effect as:
readBits(data, 0, data.length, signExtends)- Parameters:
data- the buffer into which the values are read.signExtends- true to sign-extends the result.- Returns:
- the total number of values read into the buffer, or -1 is there is no more data because the end of the stream has been reached.
- Throws:
IOException- if an I/O error occurs.
-
readBits
int readBits(int[] data, int off, int len, boolean signExtends) throws IOExceptionReads up tolenvalues of data from the input stream into an array of values. An attempt is made to read as many aslenvalues, but a smaller number may be read, possibly zero. The number of values actually read is returned as an integer.
This method blocks until input data is available, end of file is detected, or an exception is thrown.
Ifdatais null, a NullPointerException is thrown.
Ifoffis negative, orlenis negative, oroff+lenis greater than the length of the arrayb, then an IndexOutOfBoundsException is thrown.
Iflenis zero, then no values are read and 0 is returned; otherwise, there is an attempt to read at least one value. If no value is available because the stream is at end of file, the value -1 is returned; otherwise, at least one value is read and stored intodata.
The first value read is stored into elementdata[off], the next one intodata[off+1], and so on. The number of values read is, at most, equal tolen. Letkbe the number of values actually read; these values will be stored in elementsdata[off]throughdata[off+k-1], leaving elementsdata[off+k]throughdata[off+len-1]unaffected.
In every case, elementsdata[0]throughdata[off]and elementsdata[off+len]throughdata[b.length-1]are unaffected.
If the first value cannot be read for any reason other than end of file, then an IOException is thrown. In particular, an IOException is thrown if the input stream has been closed.
ThereadBits(data, off, len, signExtends)method for class BitsInput simply calls the methodreadBits(signExtends)repeatedly. If the first such call results in an IOException, that exception is returned from the call to thereadBits(data, off, len, signExte,ds)method. If any subsequent call toreadBits(boolean)results in a IOException, the exception is caught and treated as if it were end of file; the values read up to that point are stored intodataand the number of values read before the exception occurred is returned. Subclasses are encouraged to provide a more efficient implementation of this method.- Parameters:
data- the buffer into which the data is read.off- the start offset in arraydataat which the data is written.len- the maximum number of values to read.signExtends- true to sign-extends the result.- Returns:
- the total number of bytes read into the buffer, or -1 if there is no more data because the end of the stream has been reached.
- Throws:
IOException- if an I/O error occurs.
-
readBits
int readBits(short[] data, boolean signExtends) throws IOExceptionReads some number of values from the input stream and stores them into the buffer arraydata. The number of values actually read is returned as an integer. This method blocks until input value is available, end of file is detected, or an exception is thrown.
Ifdatais null, aNullPointerExceptionis thrown. If the length ofdatais zero, then no value are read and0is returned; otherwise, there is an attempt to read at least one value. If no value is available because the stream is at end of file, anEOFExceptionis thrown; otherwise, at least one value is read and stored intodata.
The first value read is stored into elementdata[0], the next one intodata[1], and so on. The number of value read is, at most, equal to the length ofdata. Letkbe the number of values actually read; these values will be stored in elementsdata[0]throughdata[k-1], leaving elementsdata[k]throughdata[data.length-1]unaffected.
If the first value cannot be read for any reason other than end of file, then an IOException is thrown. In particular, an IOException is thrown if the input stream has been closed.
ThereadBits(data, signExtends)method for classBitsInputhas the same effect as:
readBits(data, 0, data.length, signExtends)- Parameters:
data- the buffer into which the values are read.signExtends- true to sign-extends the result.- Returns:
- the total number of values read into the buffer, or -1 is there is no more data because the end of the stream has been reached.
- Throws:
IOException- if an I/O error occurs.
-
readBits
int readBits(short[] data, int off, int len, boolean signExtends) throws IOExceptionReads up tolenvalues of data from the input stream into an array of values. An attempt is made to read as many aslenvalues, but a smaller number may be read, possibly zero. The number of values actually read is returned as an integer.
This method blocks until input data is available, end of file is detected, or an exception is thrown.
Ifdatais null, a NullPointerException is thrown.
Ifoffis negative, orlenis negative, oroff+lenis greater than the length of the arrayb, then an IndexOutOfBoundsException is thrown.
Iflenis zero, then no values are read and 0 is returned; otherwise, there is an attempt to read at least one value. If no value is available because the stream is at end of file, the value -1 is returned; otherwise, at least one value is read and stored intodata.
The first value read is stored into elementdata[off], the next one intodata[off+1], and so on. The number of values read is, at most, equal tolen. Letkbe the number of values actually read; these values will be stored in elementsdata[off]throughdata[off+k-1], leaving elementsdata[off+k]throughdata[off+len-1]unaffected.
In every case, elementsdata[0]throughdata[off]and elementsdata[off+len]throughdata[b.length-1]are unaffected.
If the first value cannot be read for any reason other than end of file, then an IOException is thrown. In particular, an IOException is thrown if the input stream has been closed.
ThereadBits(data, off, len, signExtends)method for class BitsInput simply calls the methodreadBits(signExtends)repeatedly. If the first such call results in an IOException, that exception is returned from the call to thereadBits(data, off, len, signExte,ds)method. If any subsequent call toreadBits(boolean)results in a IOException, the exception is caught and treated as if it were end of file; the values read up to that point are stored intodataand the number of values read before the exception occurred is returned. Subclasses are encouraged to provide a more efficient implementation of this method.- Parameters:
data- the buffer into which the data is read.off- the start offset in arraydataat which the data is written.len- the maximum number of values to read.signExtends- true to sign-extends the result.- Returns:
- the total number of bytes read into the buffer, or -1 if there is no more data because the end of the stream has been reached.
- Throws:
IOException- if an I/O error occurs.
-
readBits
int readBits(byte[] data, boolean signExtends) throws IOExceptionReads some number of values from the input stream and stores them into the buffer arraydata. The number of values actually read is returned as an integer. This method blocks until input value is available, end of file is detected, or an exception is thrown.
Ifdatais null, aNullPointerExceptionis thrown. If the length ofdatais zero, then no value are read and0is returned; otherwise, there is an attempt to read at least one value. If no value is available because the stream is at end of file, anEOFExceptionis thrown; otherwise, at least one value is read and stored intodata.
The first value read is stored into elementdata[0], the next one intodata[1], and so on. The number of value read is, at most, equal to the length ofdata. Letkbe the number of values actually read; these values will be stored in elementsdata[0]throughdata[k-1], leaving elementsdata[k]throughdata[data.length-1]unaffected.
If the first value cannot be read for any reason other than end of file, then an IOException is thrown. In particular, an IOException is thrown if the input stream has been closed.
ThereadBits(data, signExtends)method for classBitsInputhas the same effect as:
readBits(data, 0, data.length, signExtends)- Parameters:
data- the buffer into which the values are read.signExtends- true to sign-extends the result.- Returns:
- the total number of values read into the buffer, or -1 is there is no more data because the end of the stream has been reached.
- Throws:
IOException- if an I/O error occurs.
-
readBits
int readBits(byte[] data, int off, int len, boolean signExtends) throws IOExceptionReads up tolenvalues of data from the input stream into an array of values. An attempt is made to read as many aslenvalues, but a smaller number may be read, possibly zero. The number of values actually read is returned as an integer.
This method blocks until input data is available, end of file is detected, or an exception is thrown.
Ifdatais null, a NullPointerException is thrown.
Ifoffis negative, orlenis negative, oroff+lenis greater than the length of the arrayb, then an IndexOutOfBoundsException is thrown.
Iflenis zero, then no values are read and 0 is returned; otherwise, there is an attempt to read at least one value. If no value is available because the stream is at end of file, the value -1 is returned; otherwise, at least one value is read and stored intodata.
The first value read is stored into elementdata[off], the next one intodata[off+1], and so on. The number of values read is, at most, equal tolen. Letkbe the number of values actually read; these values will be stored in elementsdata[off]throughdata[off+k-1], leaving elementsdata[off+k]throughdata[off+len-1]unaffected.
In every case, elementsdata[0]throughdata[off]and elementsdata[off+len]throughdata[b.length-1]are unaffected.
If the first value cannot be read for any reason other than end of file, then an IOException is thrown. In particular, an IOException is thrown if the input stream has been closed.
ThereadBits(data, off, len, signExtends)method for class BitsInput simply calls the methodreadBits(signExtends)repeatedly. If the first such call results in an IOException, that exception is returned from the call to thereadBits(data, off, len, signExte,ds)method. If any subsequent call toreadBits(boolean)results in a IOException, the exception is caught and treated as if it were end of file; the values read up to that point are stored intodataand the number of values read before the exception occurred is returned. Subclasses are encouraged to provide a more efficient implementation of this method.- Parameters:
data- the buffer into which the data is read.off- the start offset in arraydataat which the data is written.len- the maximum number of values to read.signExtends- true to sign-extends the result.- Returns:
- the total number of bytes read into the buffer, or -1 if there is no more data because the end of the stream has been reached.
- Throws:
IOException- if an I/O error occurs.
-
-