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 71d16d9ba Add GzipCompressorInputStreamTest
71d16d9ba is described below

commit 71d16d9ba578995b989834af9b5c39b4023a653e
Author: Gary Gregory <garydgreg...@gmail.com>
AuthorDate: Wed Jan 1 13:10:13 2025 -0500

    Add GzipCompressorInputStreamTest
---
 .../gzip/GzipCompressorInputStreamTest.java        |  61 +++++++++++++++++++++
 .../org/apache/commons/compress/gzip/members.gz    | Bin 0 -> 76 bytes
 2 files changed, 61 insertions(+)

diff --git 
a/src/test/java/org/apache/commons/compress/compressors/gzip/GzipCompressorInputStreamTest.java
 
b/src/test/java/org/apache/commons/compress/compressors/gzip/GzipCompressorInputStreamTest.java
new file mode 100644
index 000000000..8869eb91a
--- /dev/null
+++ 
b/src/test/java/org/apache/commons/compress/compressors/gzip/GzipCompressorInputStreamTest.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
+ *
+ *   https://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.gzip;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+
+import org.apache.commons.io.IOUtils;
+import org.junit.jupiter.api.Test;
+
+/**
+ * Tests {@link GzipCompressorInputStream}.
+ */
+public class GzipCompressorInputStreamTest {
+
+    /**
+     * Tests file from gzip 1.13.
+     *
+     * <pre>{@code
+     * gzip --keep --name --best -c hello1.txt >members.gz
+     * gzip --keep --name --best -c hello2.txt >>members.gz
+     * }</pre>
+     */
+    @Test
+    public void testReadGzipFileCreatedByCli() throws IOException {
+        // First member only
+        try (GzipCompressorInputStream gis = 
GzipCompressorInputStream.builder().setFile("src/test/resources/org/apache/commons/compress/gzip/members.gz")
+                .get()) {
+            assertEquals("hello1.txt", gis.getMetaData().getFileName());
+            assertEquals("Hello1\n", IOUtils.toString(gis, 
StandardCharsets.ISO_8859_1));
+            assertEquals("hello1.txt", gis.getMetaData().getFileName());
+        }
+        // Concatenated members, same file
+        try (GzipCompressorInputStream gis = 
GzipCompressorInputStream.builder().setFile("src/test/resources/org/apache/commons/compress/gzip/members.gz")
+                .setDecompressConcatenated(true).get()) {
+            assertEquals("hello1.txt", gis.getMetaData().getFileName());
+            assertEquals("Hello1\nHello2\n", IOUtils.toString(gis, 
StandardCharsets.ISO_8859_1));
+            assertEquals("hello2.txt", gis.getMetaData().getFileName());
+        }
+    }
+
+}
diff --git a/src/test/resources/org/apache/commons/compress/gzip/members.gz 
b/src/test/resources/org/apache/commons/compress/gzip/members.gz
new file mode 100644
index 000000000..74f1800b0
Binary files /dev/null and 
b/src/test/resources/org/apache/commons/compress/gzip/members.gz differ

Reply via email to