in src/main/java/com/hadoop/compression/lzo/LzoCompressor.java [239:262]
private ByteBuffer realloc(ByteBuffer buf, int newSize) {
if (buf != null) {
if (buf.capacity() == newSize) {
// Can use existing buffer
buf.clear();
return buf;
}
try {
// Manually free the old buffer using undocumented unsafe APIs.
// If this fails, we'll drop the reference and hope GC finds it
// eventually.
Method cleanerMethod = buf.getClass().getMethod("cleaner");
cleanerMethod.setAccessible(true);
Object cleaner = cleanerMethod.invoke(buf);
Method cleanMethod = cleaner.getClass().getMethod("clean");
cleanMethod.setAccessible(true);
cleanMethod.invoke(cleaner);
} catch (Exception e) {
// Perhaps a non-sun-derived JVM - contributions welcome
LOG.warn("Couldn't realloc bytebuffer", e);
}
}
return ByteBuffer.allocateDirect(newSize);
}