private Buffer encode(LZMAOutputState outputState)
throws IOException {
final Encoder encoder = outputState.getEncoder();
Buffer dst = outputState.getMemoryManager().allocate(512);
outputState.setDst(dst);
if (!outputState.isHeaderWritten()) {
// writes a 5-byte header that the decoder will use in order
// to achieve parity with the encoder's properties.
encoder.writeCoderProperties(outputState.getDst());
outputState.setHeaderWritten(true);
}
encoder.code(outputState, -1, -1);
dst = outputState.getDst();
int len = dst.position();
if (len <= 0) {
dst.dispose();
return null;