/** * Writes and compresses a single byte to the underlying output stream. * * @param b byte to write * @throws IOException if anything goes wrong */ @Override public void write(int b) throws IOException { if (prefixCode == -1) { prefixCode = b; } else { int newPrefixCode = table.codeValue(prefixCode, (byte) b); if (newPrefixCode != -1) { prefixCode = newPrefixCode; } else { writer.write(prefixCode); boolean added = table.add(prefixCode, (byte) b); if (added && codeWidthNeedsToBeIncreased()) { writer.increaseCodeWidth(); codeWidth++; } prefixCode = b; } } }