aboutsummaryrefslogtreecommitdiff
path: root/java/org/brotli/wrapper/dec/DecoderJNI.java
diff options
context:
space:
mode:
Diffstat (limited to 'java/org/brotli/wrapper/dec/DecoderJNI.java')
-rw-r--r--java/org/brotli/wrapper/dec/DecoderJNI.java26
1 files changed, 15 insertions, 11 deletions
diff --git a/java/org/brotli/wrapper/dec/DecoderJNI.java b/java/org/brotli/wrapper/dec/DecoderJNI.java
index 3a59053..320705c 100644
--- a/java/org/brotli/wrapper/dec/DecoderJNI.java
+++ b/java/org/brotli/wrapper/dec/DecoderJNI.java
@@ -12,13 +12,13 @@ import java.nio.ByteBuffer;
/**
* JNI wrapper for brotli decoder.
*/
-class DecoderJNI {
+public class DecoderJNI {
private static native ByteBuffer nativeCreate(long[] context);
private static native void nativePush(long[] context, int length);
private static native ByteBuffer nativePull(long[] context);
private static native void nativeDestroy(long[] context);
- enum Status {
+ public enum Status {
ERROR,
DONE,
NEEDS_MORE_INPUT,
@@ -26,12 +26,12 @@ class DecoderJNI {
OK
};
- static class Wrapper {
- private final long[] context = new long[2];
+ public static class Wrapper {
+ private final long[] context = new long[3];
private final ByteBuffer inputBuffer;
private Status lastStatus = Status.NEEDS_MORE_INPUT;
- Wrapper(int inputBufferSize) throws IOException {
+ public Wrapper(int inputBufferSize) throws IOException {
this.context[1] = inputBufferSize;
this.inputBuffer = nativeCreate(this.context);
if (this.context[0] == 0) {
@@ -39,7 +39,7 @@ class DecoderJNI {
}
}
- void push(int length) {
+ public void push(int length) {
if (length < 0) {
throw new IllegalArgumentException("negative block length");
}
@@ -71,19 +71,23 @@ class DecoderJNI {
}
}
- Status getStatus() {
+ public Status getStatus() {
return lastStatus;
}
- ByteBuffer getInputBuffer() {
+ public ByteBuffer getInputBuffer() {
return inputBuffer;
}
- ByteBuffer pull() {
+ public boolean hasOutput() {
+ return context[2] != 0;
+ }
+
+ public ByteBuffer pull() {
if (context[0] == 0) {
throw new IllegalStateException("brotli decoder is already destroyed");
}
- if (lastStatus != Status.NEEDS_MORE_OUTPUT) {
+ if (lastStatus != Status.NEEDS_MORE_OUTPUT && !hasOutput()) {
throw new IllegalStateException("pulling output from decoder in " + lastStatus + " state");
}
ByteBuffer result = nativePull(context);
@@ -94,7 +98,7 @@ class DecoderJNI {
/**
* Releases native resources.
*/
- void destroy() {
+ public void destroy() {
if (context[0] == 0) {
throw new IllegalStateException("brotli decoder is already destroyed");
}