// post: output is closed public void close() { if (numDigits > 0) flush(); try { output.close(); } catch (IOException e) { throw new RuntimeException(e.toString()); } }
// post: writes given bit to output public void writeBit(int bit) { if (bit < 0 || bit > 1) throw new IllegalArgumentException("Illegal bit: " + bit); digits += bit << numDigits; numDigits++; if (numDigits == BYTE_SIZE) flush(); }