Fix issues with JNI getAllBytes function.
Shrink the read cache if the filtered size result is smaller than the buffer size.