aboutsummaryrefslogtreecommitdiff
path: root/java/org/brotli/dec/TestUtils.java
diff options
context:
space:
mode:
Diffstat (limited to 'java/org/brotli/dec/TestUtils.java')
-rw-r--r--java/org/brotli/dec/TestUtils.java35
1 files changed, 35 insertions, 0 deletions
diff --git a/java/org/brotli/dec/TestUtils.java b/java/org/brotli/dec/TestUtils.java
new file mode 100644
index 0000000..797c1d1
--- /dev/null
+++ b/java/org/brotli/dec/TestUtils.java
@@ -0,0 +1,35 @@
+package org.brotli.dec;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.lang.reflect.Constructor;
+
+/**
+ * Common utility methods.
+ */
+public final class TestUtils {
+
+ public static InputStream newBrotliInputStream(InputStream input) throws IOException {
+ String brotliClass = System.getProperty("BROTLI_INPUT_STREAM");
+ if (brotliClass == null) {
+ return new BrotliInputStream(input);
+ }
+ try {
+ Class<?> clazz = Class.forName(brotliClass);
+ Constructor<?> ctor = clazz.getConstructor(InputStream.class);
+ return (InputStream) ctor.newInstance(new Object[] { input });
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ static byte[] readUniBytes(String uniBytes) {
+ byte[] result = new byte[uniBytes.length()];
+ for (int i = 0; i < result.length; ++i) {
+ result[i] = (byte) uniBytes.charAt(i);
+ }
+ return result;
+ }
+
+private TestUtils() {}
+}