ByteBuffer bbu = bb.duplicate();
ByteBuffer bbc = ByteBuffer.allocateDirect(bbu.limit() + 13);
bbc.order(ByteOrder.LITTLE_ENDIAN);
LzmaEncoder enc = new LzmaEncoder();
if (!enc.setLcLpPb(lc, lp, pb)) {
throw new IOException("Invalid LZMA props");
}
if (!enc.setDictionarySize(dictSize)) {
throw new IOException("Invalid dictionary size");
}
enc.setEndMarkerMode(true);
bbc.put(enc.getCoderProperties());
bbc.putLong(bbu.limit());
ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor();
executor.scheduleAtFixedRate(new ByteBufferProgress(bbu), 2, 2, TimeUnit.SECONDS);
try {
InputStream is = new ByteBufferInputStream(bbu);
OutputStream os = new ByteBufferOutputStream(bbc);
enc.code(is, os);
} finally {
executor.shutdown();
}
bbc.flip();