### Question:
LzssCodec { public static void compress(OutputStream dst, InputStream src) throws IOException { EncodeState sp; int i, c, len, r, s, lastMatchLength; ByteBuffer codeBuf = ByteBuffer.allocate(17); byte mask; sp = new EncodeState(); codeBuf.put((byte) 0); mask = 1; s = 0; r = N - F; for (len = 0; len < F; len++) { int b = src.read(); if (b == -1) { break; } sp.textBuf.put(r + len, (byte) b); } if (len == 0) { return; } for (i = 1; i <= F; i++) { sp.insertNode(r - i); } sp.insertNode(r); do { if (sp.matchLength > len) { sp.matchLength = len; } if (sp.matchLength <= THRESHOLD) { sp.matchLength = 1; codeBuf.put(0, (byte) (codeBuf.get(0) | mask)); codeBuf.put(sp.textBuf.get(r)); } else { codeBuf.put((byte) sp.matchPosition); codeBuf.put((byte) (((sp.matchPosition >> 4) & 0xF0) | (sp.matchLength - (THRESHOLD + 1))) ); } if ((mask <<= 1) == 0) { dst.write(codeBuf.array(), 0, codeBuf.position()); codeBuf.clear(); codeBuf.put((byte) 0); mask = 1; } lastMatchLength = sp.matchLength; for (i = 0; i < lastMatchLength; i++) { c = src.read(); if (c == -1) { break; } sp.deleteNode(s); sp.textBuf.put(s, (byte) c); if (s < F - 1) { sp.textBuf.put(s + N, (byte) c); } s = (s + 1) & (N - 1); r = (r + 1) & (N - 1); sp.insertNode(r); } while (i++ < lastMatchLength) { sp.deleteNode(s); s = (s + 1) & (N - 1); r = (r + 1) & (N - 1); if (--len != 0) { sp.insertNode(r); } } } while (len > 0); if (codeBuf.position() > 1) { dst.write(codeBuf.array(), 0, codeBuf.position()); } dst.flush(); }  static void decompress(OutputStream dst, InputStream src); static void compress(OutputStream dst, InputStream src); static final int N; static final int F; static final int THRESHOLD; static final int NIL; }### Answer:
@Test public void testCompress() throws Exception { ByteArrayOutputStream dst = new ByteArrayOutputStream(); InputStream src = new ByteArrayInputStream(TEST_TEXT.getBytes()); LzssCodec.compress(dst, src); byte[] out = dst.toByteArray(); assertArrayEquals(TEST_COMPRESSED, out); }