diff options
author | Evgenii Kliuchnikov <eustas@google.com> | 2024-02-21 02:32:23 -0800 |
---|---|---|
committer | Copybara-Service <copybara-worker@google.com> | 2024-02-21 02:33:05 -0800 |
commit | ccec9628e49208173c9a8829ff66d0d7f6ceff5f (patch) | |
tree | 2ecfd0bf126476df55f27df320464d8f64845348 /java/org/brotli/dec/TestUtils.java | |
parent | c1362a7903dd6360228d27b703227e20723cf051 (diff) | |
download | brotli-ccec9628e49208173c9a8829ff66d0d7f6ceff5f.zip brotli-ccec9628e49208173c9a8829ff66d0d7f6ceff5f.tar.gz brotli-ccec9628e49208173c9a8829ff66d0d7f6ceff5f.tar.bz2 |
add pure-kotlin decoder
PiperOrigin-RevId: 608917286
Diffstat (limited to 'java/org/brotli/dec/TestUtils.java')
-rw-r--r-- | java/org/brotli/dec/TestUtils.java | 35 |
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() {} +} |