aboutsummaryrefslogtreecommitdiff
path: root/java/org/brotli/wrapper/enc/Encoder.java
diff options
context:
space:
mode:
Diffstat (limited to 'java/org/brotli/wrapper/enc/Encoder.java')
-rw-r--r--java/org/brotli/wrapper/enc/Encoder.java23
1 files changed, 23 insertions, 0 deletions
diff --git a/java/org/brotli/wrapper/enc/Encoder.java b/java/org/brotli/wrapper/enc/Encoder.java
index af579a3..2aa9890 100644
--- a/java/org/brotli/wrapper/enc/Encoder.java
+++ b/java/org/brotli/wrapper/enc/Encoder.java
@@ -6,17 +6,20 @@
package org.brotli.wrapper.enc;
+import org.brotli.enc.PreparedDictionary;
import java.io.IOException;
import java.nio.Buffer;
import java.nio.ByteBuffer;
import java.nio.channels.WritableByteChannel;
import java.util.ArrayList;
+import java.util.List;
/**
* Base class for OutputStream / Channel implementations.
*/
public class Encoder {
private final WritableByteChannel destination;
+ private final List<PreparedDictionary> dictionaries;
private final EncoderJNI.Wrapper encoder;
private ByteBuffer buffer;
final ByteBuffer inputBuffer;
@@ -111,6 +114,7 @@ public class Encoder {
if (destination == null) {
throw new NullPointerException("destination can not be null");
}
+ this.dictionaries = new ArrayList<PreparedDictionary>();
this.destination = destination;
this.encoder = new EncoderJNI.Wrapper(inputBufferSize, params.quality, params.lgwin, params.mode);
this.inputBuffer = this.encoder.getInputBuffer();
@@ -125,6 +129,14 @@ public class Encoder {
throw new IOException(message);
}
+ public void attachDictionary(PreparedDictionary dictionary) throws IOException {
+ if (!encoder.attachDictionary(dictionary.getData())) {
+ fail("failed to attach dictionary");
+ }
+ // Reference to native prepared dictionary wrapper should be held till the end of encoding.
+ dictionaries.add(dictionary);
+ }
+
/**
* @param force repeat pushing until all output is consumed
* @return true if all encoder output is consumed
@@ -239,4 +251,15 @@ public class Encoder {
public static byte[] compress(byte[] data) throws IOException {
return compress(data, new Parameters());
}
+
+ /**
+ * Prepares raw or serialized dictionary for being used by encoder.
+ *
+ * @param dictionary raw / serialized dictionary data; MUST be direct
+ * @param sharedDictionaryType dictionary data type
+ */
+ public static PreparedDictionary prepareDictionary(ByteBuffer dictionary,
+ int sharedDictionaryType) {
+ return EncoderJNI.prepareDictionary(dictionary, sharedDictionaryType);
+ }
}