You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2024/12/13 23:15:03 UTC
(commons-compress) branch master updated (286de7837 -> 248b191c2)
This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/commons-compress.git
from 286de7837 Add ZipFile.stream()
new 6f8e33e88 ArchiveOutputStream.isClosed() is now public, was protected
new 248b191c2 ZipArchiveOutputStream.close() does not close its underlying output stream
The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
src/changes/changes.xml | 2 ++
.../compress/archivers/ArchiveOutputStream.java | 2 +-
.../archivers/zip/ZipArchiveOutputStream.java | 2 +-
.../archivers/ar/ArArchiveOutputStreamTest.java | 20 ++++++++++----------
.../archivers/cpio/CpioArchiveOutputStreamTest.java | 15 ++++++++-------
.../archivers/tar/TarArchiveOutputStreamTest.java | 12 +++++++-----
.../archivers/zip/ZipArchiveOutputStreamTest.java | 21 ++++++++++++---------
7 files changed, 41 insertions(+), 33 deletions(-)
(commons-compress) 01/02: ArchiveOutputStream.isClosed() is now public, was protected
Posted by gg...@apache.org.
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
commit 6f8e33e881746f52fd406957e09bb11952aa22c9
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Fri Dec 13 18:13:15 2024 -0500
ArchiveOutputStream.isClosed() is now public, was protected
---
src/changes/changes.xml | 1 +
.../compress/archivers/ArchiveOutputStream.java | 2 +-
.../archivers/ar/ArArchiveOutputStreamTest.java | 20 ++++++++++----------
.../archivers/cpio/CpioArchiveOutputStreamTest.java | 15 ++++++++-------
.../archivers/tar/TarArchiveOutputStreamTest.java | 12 +++++++-----
5 files changed, 27 insertions(+), 23 deletions(-)
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 66d83bf49..85e1eb105 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -64,6 +64,7 @@ The <action> type attribute can be add,update,fix,remove.
<action type="add" dev="ggregory" due-to="ddeschenes-1, Gary Gregory">Add support for gzip extra subfields, see GzipParameters.setExtra(HeaderExtraField) #604.</action>
<action type="add" dev="ggregory" due-to="Gary Gregory">Add CompressFilterOutputStream and refactor to use.</action>
<action type="add" dev="ggregory" due-to="Gary Gregory">Add ZipFile.stream().</action>
+ <action type="add" dev="ggregory" due-to="Gary Gregory">ArchiveOutputStream.isClosed() is now public, was protected.</action>
<!-- UPDATE -->
<action type="update" dev="ggregory" due-to="Dependabot, Gary Gregory">Bump org.apache.commons:commons-parent from 72 to 78 #563, #567, #574, #582, #587, #595.</action>
<action type="update" dev="ggregory" due-to="Dependabot, Gary Gregory">Bump com.github.luben:zstd-jni from 1.5.6-4 to 1.5.6-8 #565, #578, #601, #616.</action>
diff --git a/src/main/java/org/apache/commons/compress/archivers/ArchiveOutputStream.java b/src/main/java/org/apache/commons/compress/archivers/ArchiveOutputStream.java
index 2534ac12b..576d173f0 100644
--- a/src/main/java/org/apache/commons/compress/archivers/ArchiveOutputStream.java
+++ b/src/main/java/org/apache/commons/compress/archivers/ArchiveOutputStream.java
@@ -235,7 +235,7 @@ public abstract class ArchiveOutputStream<E extends ArchiveEntry> extends Compre
* @return whether this instance was successfully closed.
* @since 1.27.0
*/
- protected boolean isClosed() {
+ public boolean isClosed() {
return closed;
}
diff --git a/src/test/java/org/apache/commons/compress/archivers/ar/ArArchiveOutputStreamTest.java b/src/test/java/org/apache/commons/compress/archivers/ar/ArArchiveOutputStreamTest.java
index 4759df672..d3e2d0382 100644
--- a/src/test/java/org/apache/commons/compress/archivers/ar/ArArchiveOutputStreamTest.java
+++ b/src/test/java/org/apache/commons/compress/archivers/ar/ArArchiveOutputStreamTest.java
@@ -23,7 +23,6 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
-import java.io.OutputStream;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.List;
@@ -35,24 +34,25 @@ public class ArArchiveOutputStreamTest extends AbstractTest {
@Test
public void testLongFileNamesCauseExceptionByDefault() throws IOException {
- try (ArArchiveOutputStream os = new ArArchiveOutputStream(new ByteArrayOutputStream())) {
+ ArArchiveOutputStream ref;
+ try (ArArchiveOutputStream outputStream = new ArArchiveOutputStream(new ByteArrayOutputStream())) {
+ ref = outputStream;
final ArArchiveEntry ae = new ArArchiveEntry("this_is_a_long_name.txt", 0);
- final IOException ex = assertThrows(IOException.class, () -> os.putArchiveEntry(ae));
+ final IOException ex = assertThrows(IOException.class, () -> outputStream.putArchiveEntry(ae));
assertTrue(ex.getMessage().startsWith("File name too long"));
}
+ assertTrue(ref.isClosed());
}
@Test
public void testLongFileNamesWorkUsingBSDDialect() throws Exception {
final File file = createTempFile();
- try (OutputStream fos = Files.newOutputStream(file.toPath());
- ArArchiveOutputStream os = new ArArchiveOutputStream(fos)) {
- os.setLongFileMode(ArArchiveOutputStream.LONGFILE_BSD);
+ try (ArArchiveOutputStream outputStream = new ArArchiveOutputStream(Files.newOutputStream(file.toPath()))) {
+ outputStream.setLongFileMode(ArArchiveOutputStream.LONGFILE_BSD);
final ArArchiveEntry ae = new ArArchiveEntry("this_is_a_long_name.txt", 14);
- os.putArchiveEntry(ae);
- os.write(new byte[] { 'H', 'e', 'l', 'l', 'o', ',', ' ', 'w', 'o', 'r', 'l', 'd', '!', '\n' });
- os.closeArchiveEntry();
-
+ outputStream.putArchiveEntry(ae);
+ outputStream.write(new byte[] { 'H', 'e', 'l', 'l', 'o', ',', ' ', 'w', 'o', 'r', 'l', 'd', '!', '\n' });
+ outputStream.closeArchiveEntry();
final List<String> expected = new ArrayList<>();
expected.add("this_is_a_long_name.txt");
checkArchiveContent(file, expected);
diff --git a/src/test/java/org/apache/commons/compress/archivers/cpio/CpioArchiveOutputStreamTest.java b/src/test/java/org/apache/commons/compress/archivers/cpio/CpioArchiveOutputStreamTest.java
index da955278e..090211caf 100644
--- a/src/test/java/org/apache/commons/compress/archivers/cpio/CpioArchiveOutputStreamTest.java
+++ b/src/test/java/org/apache/commons/compress/archivers/cpio/CpioArchiveOutputStreamTest.java
@@ -20,9 +20,9 @@ package org.apache.commons.compress.archivers.cpio;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.File;
-import java.io.OutputStream;
import java.nio.file.Files;
import org.apache.commons.compress.AbstractTest;
@@ -34,13 +34,14 @@ public class CpioArchiveOutputStreamTest extends AbstractTest {
public void testWriteOldBinary() throws Exception {
final File file = getFile("test1.xml");
final File output = newTempFile("test.cpio");
- try (OutputStream outputStream = Files.newOutputStream(output.toPath());
- CpioArchiveOutputStream os = new CpioArchiveOutputStream(outputStream, CpioConstants.FORMAT_OLD_BINARY)) {
- os.putArchiveEntry(new CpioArchiveEntry(CpioConstants.FORMAT_OLD_BINARY, file, "test1.xml"));
- os.write(file);
- os.closeArchiveEntry();
+ CpioArchiveOutputStream ref;
+ try (CpioArchiveOutputStream outputStream = new CpioArchiveOutputStream(Files.newOutputStream(output.toPath()), CpioConstants.FORMAT_OLD_BINARY)) {
+ ref = outputStream;
+ outputStream.putArchiveEntry(new CpioArchiveEntry(CpioConstants.FORMAT_OLD_BINARY, file, "test1.xml"));
+ outputStream.write(file);
+ outputStream.closeArchiveEntry();
}
-
+ assertTrue(ref.isClosed());
try (CpioArchiveInputStream in = new CpioArchiveInputStream(Files.newInputStream(output.toPath()))) {
final CpioArchiveEntry e = in.getNextCPIOEntry();
assertEquals("test1.xml", e.getName());
diff --git a/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveOutputStreamTest.java b/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveOutputStreamTest.java
index e1fd352a1..e2fdd3d69 100644
--- a/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveOutputStreamTest.java
+++ b/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveOutputStreamTest.java
@@ -56,17 +56,19 @@ public class TarArchiveOutputStreamTest extends AbstractTest {
private static byte[] createTarArchiveContainingOneDirectory(final String fileName, final Date modificationDate) throws IOException {
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
- try (TarArchiveOutputStream tarOut = new TarArchiveOutputStream(baos, 1024)) {
- tarOut.setLongFileMode(TarArchiveOutputStream.LONGFILE_GNU);
+ TarArchiveOutputStream ref;
+ try (TarArchiveOutputStream outputStream = new TarArchiveOutputStream(baos, 1024)) {
+ ref = outputStream;
+ outputStream.setLongFileMode(TarArchiveOutputStream.LONGFILE_GNU);
final TarArchiveEntry tarEntry = new TarArchiveEntry("d");
tarEntry.setModTime(modificationDate);
tarEntry.setMode(TarArchiveEntry.DEFAULT_DIR_MODE);
tarEntry.setModTime(modificationDate.getTime());
tarEntry.setName(fileName);
- tarOut.putArchiveEntry(tarEntry);
- tarOut.closeArchiveEntry();
+ outputStream.putArchiveEntry(tarEntry);
+ outputStream.closeArchiveEntry();
}
-
+ assertTrue(ref.isClosed());
return baos.toByteArray();
}
(commons-compress) 02/02: ZipArchiveOutputStream.close() does not close its underlying output stream
Posted by gg...@apache.org.
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
commit 248b191c24c7640899af47c33f79c017f1970c87
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Fri Dec 13 18:14:57 2024 -0500
ZipArchiveOutputStream.close() does not close its underlying output
stream
---
src/changes/changes.xml | 1 +
.../archivers/zip/ZipArchiveOutputStream.java | 2 +-
.../archivers/zip/ZipArchiveOutputStreamTest.java | 21 ++++++++++++---------
3 files changed, 14 insertions(+), 10 deletions(-)
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 85e1eb105..2ea89793a 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -55,6 +55,7 @@ The <action> type attribute can be add,update,fix,remove.
<action type="fix" dev="ggregory" due-to="ddeschenes-1, Gary Gregory">Throw an IllegalArgumentException when a file name or comment in gzip parameters encodes to a byte array with a 0 byte #618.</action>
<action type="fix" dev="ggregory" due-to="Glavo">Update outdated links in ZipMethod Javadoc #619.</action>
<action type="fix" dev="ggregory" due-to="Gary Gregory">Deprecate ZipUtil.signedByteToUnsignedInt(byte) in favor of Byte.toUnsignedInt(byte).</action>
+ <action type="fix" dev="ggregory" due-to="Gary Gregory">ZipArchiveOutputStream.close() does not close its underlying output stream.</action>
<!-- ADD -->
<action type="add" dev="ggregory" due-to="Gary Gregory">Add GzipParameters.getModificationInstant().</action>
<action type="add" dev="ggregory" due-to="Gary Gregory">Add GzipParameters.setModificationInstant(Instant).</action>
diff --git a/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveOutputStream.java b/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveOutputStream.java
index d22bbeaf0..979f174b1 100644
--- a/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveOutputStream.java
+++ b/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveOutputStream.java
@@ -904,7 +904,7 @@ public class ZipArchiveOutputStream extends ArchiveOutputStream<ZipArchiveEntry>
*/
void destroy() throws IOException {
if (out != null) {
- out.close();
+ super.close();
}
}
diff --git a/src/test/java/org/apache/commons/compress/archivers/zip/ZipArchiveOutputStreamTest.java b/src/test/java/org/apache/commons/compress/archivers/zip/ZipArchiveOutputStreamTest.java
index 9bba9c0f9..28bb325f3 100644
--- a/src/test/java/org/apache/commons/compress/archivers/zip/ZipArchiveOutputStreamTest.java
+++ b/src/test/java/org/apache/commons/compress/archivers/zip/ZipArchiveOutputStreamTest.java
@@ -35,25 +35,28 @@ public class ZipArchiveOutputStreamTest extends AbstractTempDirTest {
@Test
public void testFileBasics() throws IOException {
- try (ZipArchiveOutputStream stream = new ZipArchiveOutputStream(createTempFile())) {
- assertTrue(stream.isSeekable());
+ ZipArchiveOutputStream ref;
+ try (ZipArchiveOutputStream outputStream = new ZipArchiveOutputStream(createTempFile())) {
+ ref = outputStream;
+ assertTrue(outputStream.isSeekable());
}
+ assertTrue(ref.isClosed());
}
@Test
public void testOutputStreamBasics() throws IOException {
- try (ZipArchiveOutputStream stream = new ZipArchiveOutputStream(new ByteArrayOutputStream())) {
- assertFalse(stream.isSeekable());
+ try (ZipArchiveOutputStream outputStream = new ZipArchiveOutputStream(new ByteArrayOutputStream())) {
+ assertFalse(outputStream.isSeekable());
}
}
@Test
public void testSetEncoding() throws IOException {
- try (ZipArchiveOutputStream stream = new ZipArchiveOutputStream(createTempFile())) {
- stream.setEncoding(StandardCharsets.UTF_8.name());
- assertEquals(StandardCharsets.UTF_8.name(), stream.getEncoding());
- stream.setEncoding(null);
- assertEquals(Charset.defaultCharset().name(), stream.getEncoding());
+ try (ZipArchiveOutputStream outputStream = new ZipArchiveOutputStream(createTempFile())) {
+ outputStream.setEncoding(StandardCharsets.UTF_8.name());
+ assertEquals(StandardCharsets.UTF_8.name(), outputStream.getEncoding());
+ outputStream.setEncoding(null);
+ assertEquals(Charset.defaultCharset().name(), outputStream.getEncoding());
}
}
}