Package ej.ecom.io

Interface BitsInput


  • public interface BitsInput
    This interface defines methods for reading data bits.
    • Method Summary

      All Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      int getLength()
      Returns the data length in bits (1 to 32 bits).
      int readBits​(boolean signExtends)
      Reads the next value of data from the input stream.
      int readBits​(byte[] data, boolean signExtends)
      Reads some number of values from the input stream and stores them into the buffer array data.
      int readBits​(byte[] data, int off, int len, boolean signExtends)
      Reads up to len values of data from the input stream into an array of values.
      int readBits​(int[] data, boolean signExtends)
      Reads some number of values from the input stream and stores them into the buffer array data.
      int readBits​(int[] data, int off, int len, boolean signExtends)
      Reads up to len values of data from the input stream into an array of values.
      int readBits​(short[] data, boolean signExtends)
      Reads some number of values from the input stream and stores them into the buffer array data.
      int readBits​(short[] data, int off, int len, boolean signExtends)
      Reads up to len values 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,
                     EOFException
        Reads the next value of data from the input stream. The value is returned as an int in the range 0 to (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 formula ret = (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 IOException
        Reads some number of values from the input stream and stores them into the buffer array data. 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.

        If data is null, a NullPointerException is thrown. If the length of data is zero, then no value 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, an EOFException is thrown; otherwise, at least one value is read and stored into data.

        The first value read is stored into element data[0], the next one into data[1], and so on. The number of value read is, at most, equal to the length of data. Let k be the number of values actually read; these values will be stored in elements data[0] through data[k-1], leaving elements data[k] through data[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.

        The readBits(data, signExtends) method for class BitsInput has 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 IOException
        Reads up to len values of data from the input stream into an array of values. An attempt is made to read as many as len values, 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.

        If data is null, a NullPointerException is thrown.

        If off is negative, or len is negative, or off+len is greater than the length of the array b, then an IndexOutOfBoundsException is thrown.

        If len is 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 into data.

        The first value read is stored into element data[off], the next one into data[off+1], and so on. The number of values read is, at most, equal to len. Let k be the number of values actually read; these values will be stored in elements data[off] through data[off+k-1], leaving elements data[off+k] through data[off+len-1] unaffected.

        In every case, elements data[0] through data[off] and elements data[off+len] through data[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.

        The readBits(data, off, len, signExtends) method for class BitsInput simply calls the method readBits(signExtends) repeatedly. If the first such call results in an IOException, that exception is returned from the call to the readBits(data, off, len, signExte,ds) method. If any subsequent call to readBits(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 into data and 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 array data at 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 IOException
        Reads some number of values from the input stream and stores them into the buffer array data. 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.

        If data is null, a NullPointerException is thrown. If the length of data is zero, then no value 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, an EOFException is thrown; otherwise, at least one value is read and stored into data.

        The first value read is stored into element data[0], the next one into data[1], and so on. The number of value read is, at most, equal to the length of data. Let k be the number of values actually read; these values will be stored in elements data[0] through data[k-1], leaving elements data[k] through data[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.

        The readBits(data, signExtends) method for class BitsInput has 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 IOException
        Reads up to len values of data from the input stream into an array of values. An attempt is made to read as many as len values, 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.

        If data is null, a NullPointerException is thrown.

        If off is negative, or len is negative, or off+len is greater than the length of the array b, then an IndexOutOfBoundsException is thrown.

        If len is 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 into data.

        The first value read is stored into element data[off], the next one into data[off+1], and so on. The number of values read is, at most, equal to len. Let k be the number of values actually read; these values will be stored in elements data[off] through data[off+k-1], leaving elements data[off+k] through data[off+len-1] unaffected.

        In every case, elements data[0] through data[off] and elements data[off+len] through data[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.

        The readBits(data, off, len, signExtends) method for class BitsInput simply calls the method readBits(signExtends) repeatedly. If the first such call results in an IOException, that exception is returned from the call to the readBits(data, off, len, signExte,ds) method. If any subsequent call to readBits(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 into data and 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 array data at 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 IOException
        Reads some number of values from the input stream and stores them into the buffer array data. 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.

        If data is null, a NullPointerException is thrown. If the length of data is zero, then no value 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, an EOFException is thrown; otherwise, at least one value is read and stored into data.

        The first value read is stored into element data[0], the next one into data[1], and so on. The number of value read is, at most, equal to the length of data. Let k be the number of values actually read; these values will be stored in elements data[0] through data[k-1], leaving elements data[k] through data[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.

        The readBits(data, signExtends) method for class BitsInput has 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 IOException
        Reads up to len values of data from the input stream into an array of values. An attempt is made to read as many as len values, 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.

        If data is null, a NullPointerException is thrown.

        If off is negative, or len is negative, or off+len is greater than the length of the array b, then an IndexOutOfBoundsException is thrown.

        If len is 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 into data.

        The first value read is stored into element data[off], the next one into data[off+1], and so on. The number of values read is, at most, equal to len. Let k be the number of values actually read; these values will be stored in elements data[off] through data[off+k-1], leaving elements data[off+k] through data[off+len-1] unaffected.

        In every case, elements data[0] through data[off] and elements data[off+len] through data[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.

        The readBits(data, off, len, signExtends) method for class BitsInput simply calls the method readBits(signExtends) repeatedly. If the first such call results in an IOException, that exception is returned from the call to the readBits(data, off, len, signExte,ds) method. If any subsequent call to readBits(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 into data and 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 array data at 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.