Class BitInputStream

java.lang.Object
AEDs3.Compression.Compressors.BitInputStream

class BitInputStream extends Object
Classe auxiliar para leitura de bits de uma stream de entrada. Permite ler exatamente o número de bits solicitados, carregando apenas um byte de cada vez em memória.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private int
    Byte atual em leitura.
    private final InputStream
    Stream de entrada para leitura de bits.
    private int
    Número de bits restantes no byte atual.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Construtor para inicializar o BitInputStream com uma stream de entrada.
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    read(int numBits)
    Lê 'numBits' bits da stream e retorna o valor correspondente.
    private int
    Lê um único bit da stream.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • in

      private final InputStream in
      Stream de entrada para leitura de bits.
    • currentByte

      private int currentByte
      Byte atual em leitura.
    • numBitsRemaining

      private int numBitsRemaining
      Número de bits restantes no byte atual.
  • Constructor Details

    • BitInputStream

      public BitInputStream(InputStream in)
      Construtor para inicializar o BitInputStream com uma stream de entrada.
      Parameters:
      in - Stream de entrada para leitura de bits.
  • Method Details

    • read

      public int read(int numBits) throws IOException
      Lê 'numBits' bits da stream e retorna o valor correspondente. Retorna -1 se não houver bits suficientes (fim da stream).
      Parameters:
      numBits - Número de bits a serem lidos.
      Returns:
      Valor lido ou -1 se o fim da stream for atingido.
      Throws:
      IOException - Se ocorrer um erro de I/O.
    • readBit

      private int readBit() throws IOException
      Lê um único bit da stream.
      Returns:
      O bit lido (0 ou 1) ou -1 se o fim da stream for atingido.
      Throws:
      IOException - Se ocorrer um erro de I/O.