From 0300be36ba019c55d2edc48353270fa18008d49c Mon Sep 17 00:00:00 2001 From: Evgenii Kliuchnikov Date: Fri, 28 Jul 2023 01:06:17 -0700 Subject: add "repeat" to Java toy decoder PiperOrigin-RevId: 551770992 --- java/org/brotli/dec/Decoder.java | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/java/org/brotli/dec/Decoder.java b/java/org/brotli/dec/Decoder.java index 599588e..e33f5a9 100644 --- a/java/org/brotli/dec/Decoder.java +++ b/java/org/brotli/dec/Decoder.java @@ -24,21 +24,15 @@ public class Decoder { return totalOut; } - public static void main(String... args) throws IOException { - if (args.length != 2) { - System.out.println("Usage: decoder "); - return; - } - - byte[] buffer = new byte[1024 * 1024]; + private static void decompress(String fromPath, String toPath, byte[] buffer) throws IOException { long start; long bytesDecoded; long end; InputStream in = null; OutputStream out = null; try { - in = new FileInputStream(args[0]); - out = new FileOutputStream(args[1]); + in = new FileInputStream(fromPath); + out = new FileOutputStream(toPath); start = System.nanoTime(); bytesDecoded = decodeBytes(in, out, buffer); end = System.nanoTime(); @@ -58,4 +52,21 @@ public class Decoder { double mbDecoded = bytesDecoded / (1024.0 * 1024.0); System.out.println(mbDecoded / timeDelta + " MiB/s"); } + + public static void main(String... args) throws IOException { + if (args.length != 2 && args.length != 3) { + System.out.println("Usage: decoder [repeat]"); + return; + } + + int repeat = 1; + if (args.length == 3) { + repeat = Integer.parseInt(args[2]); + } + + byte[] buffer = new byte[1024 * 1024]; + for (int i = 0; i < repeat; ++i) { + decompress(args[0], args[1], buffer); + } + } } -- cgit v1.1