commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject [6/7] commons-compress git commit: Slight speed up by avoiding writing to disk
Date Thu, 06 Jul 2017 07:07:35 GMT
Slight speed up by avoiding writing to disk

Signed-off-by: Simon Spero <sesuncedu@gmail.com>


Project: http://git-wip-us.apache.org/repos/asf/commons-compress/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-compress/commit/1261172a
Tree: http://git-wip-us.apache.org/repos/asf/commons-compress/tree/1261172a
Diff: http://git-wip-us.apache.org/repos/asf/commons-compress/diff/1261172a

Branch: refs/heads/master
Commit: 1261172afdae9a4b15dc9f691583261a1b020ccc
Parents: 5499fa0
Author: Simon Spero <sesuncedu@gmail.com>
Authored: Sun Jun 25 16:57:16 2017 -0400
Committer: Stefan Bodewig <bodewig@apache.org>
Committed: Thu Jul 6 09:07:16 2017 +0200

----------------------------------------------------------------------
 .../lz4/FramedLZ4CompressorRoundtripTest.java   | 24 ++++++++++++--------
 1 file changed, 14 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-compress/blob/1261172a/src/test/java/org/apache/commons/compress/compressors/lz4/FramedLZ4CompressorRoundtripTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/compress/compressors/lz4/FramedLZ4CompressorRoundtripTest.java
b/src/test/java/org/apache/commons/compress/compressors/lz4/FramedLZ4CompressorRoundtripTest.java
index ea63c1d..29e4443 100644
--- a/src/test/java/org/apache/commons/compress/compressors/lz4/FramedLZ4CompressorRoundtripTest.java
+++ b/src/test/java/org/apache/commons/compress/compressors/lz4/FramedLZ4CompressorRoundtripTest.java
@@ -18,20 +18,20 @@
  */
 package org.apache.commons.compress.compressors.lz4;
 
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
 import java.io.File;
 import java.io.FileInputStream;
-import java.io.FileOutputStream;
 import java.io.IOException;
 import java.util.Arrays;
 import java.util.Collection;
-
 import org.apache.commons.compress.AbstractTestCase;
 import org.apache.commons.compress.utils.IOUtils;
 import org.junit.Assert;
 import org.junit.Test;
+import org.junit.runner.RunWith;
 import org.junit.runners.Parameterized;
 import org.junit.runners.Parameterized.Parameters;
-import org.junit.runner.RunWith;
 
 @RunWith(Parameterized.class)
 public final class FramedLZ4CompressorRoundtripTest extends AbstractTestCase {
@@ -69,20 +69,24 @@ public final class FramedLZ4CompressorRoundtripTest extends AbstractTestCase
{
         File input = getFile(testFile);
         long start = System.currentTimeMillis();
         final File outputSz = new File(dir, input.getName() + ".framed.lz4");
-        try (FileInputStream is = new FileInputStream(input);
-             FileOutputStream os = new FileOutputStream(outputSz);
-             FramedLZ4CompressorOutputStream los = new FramedLZ4CompressorOutputStream(os,
params)) {
-            IOUtils.copy(is, los);
+        byte[] expected;
+        try (FileInputStream is = new FileInputStream(input)) {
+            expected = IOUtils.toByteArray(is);
+        }
+        ByteArrayOutputStream bos = new ByteArrayOutputStream();
+        try (FramedLZ4CompressorOutputStream los = new FramedLZ4CompressorOutputStream(bos,
+            params)) {
+            IOUtils.copy(new ByteArrayInputStream(expected), los);
         }
         System.err.println(input.getName() + " written, uncompressed bytes: " + input.length()
             + ", compressed bytes: " + outputSz.length() + " after " + (System.currentTimeMillis()
- start) + "ms");
         start = System.currentTimeMillis();
-        try (FileInputStream is = new FileInputStream(input);
-             FramedLZ4CompressorInputStream sis = new FramedLZ4CompressorInputStream(new
FileInputStream(outputSz))) {
-            byte[] expected = IOUtils.toByteArray(is);
+        try (FramedLZ4CompressorInputStream sis = new FramedLZ4CompressorInputStream(
+            new ByteArrayInputStream(bos.toByteArray()))) {
             byte[] actual = IOUtils.toByteArray(sis);
             Assert.assertArrayEquals(expected, actual);
         }
+
         System.err.println(outputSz.getName() + " read after " + (System.currentTimeMillis()
- start) + "ms");
     }
 


Mime
View raw message