This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-compress.git


The following commit(s) were added to refs/heads/master by this push:
     new e4a131b90 [COMPRESS-687] Add Compress687Test
     new cf33cb227 Merge branch 'master' of 
https://gitbox.apache.org/repos/asf/commons-compress.git
e4a131b90 is described below

commit e4a131b907bf323016331f5bcb44b94a0e9d3c6f
Author: Gary Gregory <garydgreg...@gmail.com>
AuthorDate: Sun Sep 15 11:10:16 2024 -0400

    [COMPRESS-687] Add Compress687Test
    
    - Tests OK
    - https://issues.apache.org/jira/browse/COMPRESS-687
---
 .../harmony/unpack200/Pack200UnpackerAdapter.java  |  15 +++--
 .../compressors/pack200/Compress687Test.java       |  61 +++++++++++++++++++++
 .../commons/compress/COMPRESS-687/test-issue.7z    | Bin 0 -> 1008 bytes
 3 files changed, 71 insertions(+), 5 deletions(-)

diff --git 
a/src/main/java/org/apache/commons/compress/harmony/unpack200/Pack200UnpackerAdapter.java
 
b/src/main/java/org/apache/commons/compress/harmony/unpack200/Pack200UnpackerAdapter.java
index ffbc355e3..83f5c7367 100644
--- 
a/src/main/java/org/apache/commons/compress/harmony/unpack200/Pack200UnpackerAdapter.java
+++ 
b/src/main/java/org/apache/commons/compress/harmony/unpack200/Pack200UnpackerAdapter.java
@@ -159,15 +159,17 @@ public class Pack200UnpackerAdapter extends 
Pack200Adapter implements Unpacker {
      * @param filterInputStream The FilterInputStream to unwrap.
      * @return The wrapped InputStream
      */
-    @SuppressWarnings("resource")
     static InputStream unwrap(final InputStream inputStream) {
         return inputStream instanceof FilterInputStream ? 
unwrap((FilterInputStream) inputStream) : inputStream;
     }
 
     @Override
     public void unpack(final File file, final JarOutputStream out) throws 
IOException {
-        if (file == null || out == null) {
-            throw new IllegalArgumentException("Must specify both input and 
output streams");
+        if (file == null) {
+            throw new IllegalArgumentException("Must specify input file.");
+        }
+        if (out == null) {
+            throw new IllegalArgumentException("Must specify output stream.");
         }
         final long size = file.length();
         final int bufferSize = size > 0 && size < DEFAULT_BUFFER_SIZE ? (int) 
size : DEFAULT_BUFFER_SIZE;
@@ -178,8 +180,11 @@ public class Pack200UnpackerAdapter extends Pack200Adapter 
implements Unpacker {
 
     @Override
     public void unpack(final InputStream in, final JarOutputStream out) throws 
IOException {
-        if (in == null || out == null) {
-            throw new IllegalArgumentException("Must specify both input and 
output streams");
+        if (in == null) {
+            throw new IllegalArgumentException("Must specify input stream.");
+        }
+        if (out == null) {
+            throw new IllegalArgumentException("Must specify output stream.");
         }
         completed(0);
         try {
diff --git 
a/src/test/java/org/apache/commons/compress/compressors/pack200/Compress687Test.java
 
b/src/test/java/org/apache/commons/compress/compressors/pack200/Compress687Test.java
new file mode 100644
index 000000000..d8eff5d0e
--- /dev/null
+++ 
b/src/test/java/org/apache/commons/compress/compressors/pack200/Compress687Test.java
@@ -0,0 +1,61 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.compress.compressors.pack200;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+import org.apache.commons.io.IOUtils;
+import org.apache.commons.io.output.NullOutputStream;
+import org.junit.jupiter.api.Test;
+
+public class Compress687Test {
+
+    private static final int DEFAULT_BUFFER_SIZE = 16_384;
+
+    @Test
+    public void testTransferTo() throws Exception {
+        try (InputStream inputStream = 
Compress687Test.class.getClassLoader().getResourceAsStream("org/apache/commons/compress/COMPRESS-687/test-issue.7z");
+                Pack200CompressorInputStream compressInputStream = new 
Pack200CompressorInputStream(inputStream)) {
+            transferTo(compressInputStream, NullOutputStream.INSTANCE);
+        }
+        try (InputStream inputStream = 
Compress687Test.class.getClassLoader().getResourceAsStream("org/apache/commons/compress/COMPRESS-687/test-issue.7z");
+                Pack200CompressorInputStream compressInputStream = new 
Pack200CompressorInputStream(inputStream)) {
+            IOUtils.copy(compressInputStream, NullOutputStream.INSTANCE);
+        }
+        // System.out.println("Done.");
+    }
+
+    private long transferTo(final InputStream in, final OutputStream out) 
throws IOException {
+        long transferred = 0;
+        final byte[] buffer = new byte[DEFAULT_BUFFER_SIZE];
+        int read;
+        while ((read = in.read(buffer, 0, DEFAULT_BUFFER_SIZE)) >= 0) {
+            out.write(buffer, 0, read);
+            if (transferred < Long.MAX_VALUE) {
+                try {
+                    transferred = Math.addExact(transferred, read);
+                } catch (final ArithmeticException ignore) {
+                    transferred = Long.MAX_VALUE;
+                }
+            }
+        }
+        return transferred;
+    }
+}
diff --git 
a/src/test/resources/org/apache/commons/compress/COMPRESS-687/test-issue.7z 
b/src/test/resources/org/apache/commons/compress/COMPRESS-687/test-issue.7z
new file mode 100644
index 000000000..b6509558e
Binary files /dev/null and 
b/src/test/resources/org/apache/commons/compress/COMPRESS-687/test-issue.7z 
differ

Reply via email to