Skip to content

Commit

Permalink
ArchiveOutputStream.isClosed() is now public, was protected
Browse files Browse the repository at this point in the history
  • Loading branch information
garydgregory committed Dec 13, 2024
1 parent 286de78 commit 6f8e33e
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 23 deletions.
1 change: 1 addition & 0 deletions src/changes/changes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ public int getCount() {
* @return whether this instance was successfully closed.
* @since 1.27.0
*/
protected boolean isClosed() {
public boolean isClosed() {
return closed;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
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;
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@

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;
Expand All @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down

0 comments on commit 6f8e33e

Please sign in to comment.