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 75cb7770d Sort members 75cb7770d is described below commit 75cb7770dc3784876cf738a279614ad1b56c039e Author: Gary Gregory <garydgreg...@gmail.com> AuthorDate: Fri Nov 10 15:51:34 2023 -0500 Sort members --- .../compress/archivers/examples/ExpanderTest.java | 18 ++-- .../commons/compress/archivers/tar/BigFilesIT.java | 32 +++--- .../archivers/tar/TarMemoryFileSystemTest.java | 60 ++++++------ .../archivers/zip/ZipArchiveInputStreamTest.java | 108 ++++++++++----------- .../compress/archivers/zip/ZipFileTest.java | 14 +-- .../harmony/pack200/tests/PackingOptionsTest.java | 80 +++++++-------- .../MultiReadOnlySeekableByteChannelTest.java | 50 +++++----- .../utils/SeekableInMemoryByteChannelTest.java | 78 +++++++-------- 8 files changed, 220 insertions(+), 220 deletions(-) diff --git a/src/test/java/org/apache/commons/compress/archivers/examples/ExpanderTest.java b/src/test/java/org/apache/commons/compress/archivers/examples/ExpanderTest.java index 07dced361..72c3cb935 100644 --- a/src/test/java/org/apache/commons/compress/archivers/examples/ExpanderTest.java +++ b/src/test/java/org/apache/commons/compress/archivers/examples/ExpanderTest.java @@ -174,15 +174,6 @@ public class ExpanderTest extends AbstractTest { } } - @Test - public void testTarFileVersion() throws IOException, ArchiveException { - setupTar(); - try (TarFile f = new TarFile(archive)) { - new Expander().expand(f, tempResultDir); - } - verifyTargetDir(); - } - @Test public void testCompress603Tar() throws IOException, ArchiveException { setupTarForCompress603(); @@ -270,6 +261,15 @@ public class ExpanderTest extends AbstractTest { verifyTargetDir(); } + @Test + public void testTarFileVersion() throws IOException, ArchiveException { + setupTar(); + try (TarFile f = new TarFile(archive)) { + new Expander().expand(f, tempResultDir); + } + verifyTargetDir(); + } + @Test public void testZipFileVersion() throws IOException, ArchiveException { setupZip(); diff --git a/src/test/java/org/apache/commons/compress/archivers/tar/BigFilesIT.java b/src/test/java/org/apache/commons/compress/archivers/tar/BigFilesIT.java index beaf0f659..2b58c4593 100644 --- a/src/test/java/org/apache/commons/compress/archivers/tar/BigFilesIT.java +++ b/src/test/java/org/apache/commons/compress/archivers/tar/BigFilesIT.java @@ -61,22 +61,6 @@ public class BigFilesIT extends AbstractTest { } } - @Test - public void testTarFileReadFileHeadersOfArchiveBiggerThan8GByte() throws Exception { - final Path file = getPath("8.posix.tar.gz"); - final Path output = tempResultDir.toPath().resolve("8.posix.tar"); - try (InputStream in = new BufferedInputStream(Files.newInputStream(file)); - GzipCompressorInputStream gzin = new GzipCompressorInputStream(in)) { - Files.copy(gzin, output, StandardCopyOption.REPLACE_EXISTING); - } - - try (final TarFile tarFile = new TarFile(output)) { - final List<TarArchiveEntry> entries = tarFile.getEntries(); - assertEquals(1, entries.size()); - assertNotNull(entries.get(0)); - } - } - @Test public void testReadFileBiggerThan8GBytePosix() throws Exception { readFileBiggerThan8GByte("8.posix.tar.gz"); @@ -98,4 +82,20 @@ public class BigFilesIT extends AbstractTest { } } + @Test + public void testTarFileReadFileHeadersOfArchiveBiggerThan8GByte() throws Exception { + final Path file = getPath("8.posix.tar.gz"); + final Path output = tempResultDir.toPath().resolve("8.posix.tar"); + try (InputStream in = new BufferedInputStream(Files.newInputStream(file)); + GzipCompressorInputStream gzin = new GzipCompressorInputStream(in)) { + Files.copy(gzin, output, StandardCopyOption.REPLACE_EXISTING); + } + + try (final TarFile tarFile = new TarFile(output)) { + final List<TarArchiveEntry> entries = tarFile.getEntries(); + assertEquals(1, entries.size()); + assertNotNull(entries.get(0)); + } + } + } diff --git a/src/test/java/org/apache/commons/compress/archivers/tar/TarMemoryFileSystemTest.java b/src/test/java/org/apache/commons/compress/archivers/tar/TarMemoryFileSystemTest.java index 4afe2cebc..78c8194b8 100644 --- a/src/test/java/org/apache/commons/compress/archivers/tar/TarMemoryFileSystemTest.java +++ b/src/test/java/org/apache/commons/compress/archivers/tar/TarMemoryFileSystemTest.java @@ -42,6 +42,36 @@ import com.github.marschall.memoryfilesystem.MemoryFileSystemBuilder; public class TarMemoryFileSystemTest { + @Test + public void testCheckUserInformationInTarEntry() throws IOException, ArchiveException { + final String user = "commons"; + final String group = "compress"; + try (FileSystem fileSystem = MemoryFileSystemBuilder.newLinux().addUser(user).addGroup(group).build()) { + final Path source = fileSystem.getPath("original-file.txt"); + Files.write(source, "Test".getBytes(UTF_8)); + Files.setAttribute(source, "posix:owner", (UserPrincipal) () -> user); + Files.setAttribute(source, "posix:group", (GroupPrincipal) () -> group); + + final Path target = fileSystem.getPath("original-file.tar"); + try (final OutputStream out = Files.newOutputStream(target); + final ArchiveOutputStream<ArchiveEntry> tarOut = ArchiveStreamFactory.DEFAULT.createArchiveOutputStream(ArchiveStreamFactory.TAR, out)) { + final TarArchiveEntry entry = new TarArchiveEntry(source); + tarOut.putArchiveEntry(entry); + + Files.copy(source, tarOut); + tarOut.closeArchiveEntry(); + } + + try (final InputStream input = Files.newInputStream(target); + final TarArchiveInputStream tarIn = new TarArchiveInputStream(input)) { + final TarArchiveEntry nextTarEntry = tarIn.getNextTarEntry(); + + assertEquals(user, nextTarEntry.getUserName()); + assertEquals(group, nextTarEntry.getGroupName()); + } + } + } + @Test public void testTarFromMemoryFileSystem() throws IOException, ArchiveException { try (FileSystem fileSystem = MemoryFileSystemBuilder.newLinux().build()) { @@ -83,34 +113,4 @@ public class TarMemoryFileSystemTest { } } } - - @Test - public void testCheckUserInformationInTarEntry() throws IOException, ArchiveException { - final String user = "commons"; - final String group = "compress"; - try (FileSystem fileSystem = MemoryFileSystemBuilder.newLinux().addUser(user).addGroup(group).build()) { - final Path source = fileSystem.getPath("original-file.txt"); - Files.write(source, "Test".getBytes(UTF_8)); - Files.setAttribute(source, "posix:owner", (UserPrincipal) () -> user); - Files.setAttribute(source, "posix:group", (GroupPrincipal) () -> group); - - final Path target = fileSystem.getPath("original-file.tar"); - try (final OutputStream out = Files.newOutputStream(target); - final ArchiveOutputStream<ArchiveEntry> tarOut = ArchiveStreamFactory.DEFAULT.createArchiveOutputStream(ArchiveStreamFactory.TAR, out)) { - final TarArchiveEntry entry = new TarArchiveEntry(source); - tarOut.putArchiveEntry(entry); - - Files.copy(source, tarOut); - tarOut.closeArchiveEntry(); - } - - try (final InputStream input = Files.newInputStream(target); - final TarArchiveInputStream tarIn = new TarArchiveInputStream(input)) { - final TarArchiveEntry nextTarEntry = tarIn.getNextTarEntry(); - - assertEquals(user, nextTarEntry.getUserName()); - assertEquals(group, nextTarEntry.getGroupName()); - } - } - } } diff --git a/src/test/java/org/apache/commons/compress/archivers/zip/ZipArchiveInputStreamTest.java b/src/test/java/org/apache/commons/compress/archivers/zip/ZipArchiveInputStreamTest.java index 835fa57a6..0189a666a 100644 --- a/src/test/java/org/apache/commons/compress/archivers/zip/ZipArchiveInputStreamTest.java +++ b/src/test/java/org/apache/commons/compress/archivers/zip/ZipArchiveInputStreamTest.java @@ -571,6 +571,60 @@ public class ZipArchiveInputStreamTest extends AbstractTest { } } + @Test + public void testThrowsIfStoredDDIsDifferentFromLengthRead() throws IOException { + try (InputStream fs = newInputStream("bla-stored-dd-contradicts-actualsize.zip"); + ZipArchiveInputStream archive = new ZipArchiveInputStream(fs, "UTF-8", true, true)) { + final ZipArchiveEntry e = archive.getNextZipEntry(); + assertNotNull(e); + assertEquals("test1.xml", e.getName()); + assertEquals(-1, e.getCompressedSize()); + assertEquals(-1, e.getSize()); + assertThrows(ZipException.class, () -> IOUtils.toByteArray(archive)); + } + } + + @Test + public void testThrowsIfStoredDDIsInconsistent() throws IOException { + try (InputStream fs = newInputStream("bla-stored-dd-sizes-differ.zip"); + ZipArchiveInputStream archive = new ZipArchiveInputStream(fs, "UTF-8", true, true)) { + final ZipArchiveEntry e = archive.getNextZipEntry(); + assertNotNull(e); + assertEquals("test1.xml", e.getName()); + assertEquals(-1, e.getCompressedSize()); + assertEquals(-1, e.getSize()); + assertThrows(ZipException.class, () -> IOUtils.toByteArray(archive)); + } + } + + /** + * @see <a href="https://issues.apache.org/jira/browse/COMPRESS-523">COMPRESS-523</a> + */ + @Test + public void testThrowsIfThereIsNoEocd() { + assertThrows(IOException.class, () -> fuzzingTest(new int[] { 0x50, 0x4b, 0x01, 0x02, 0x14, 0x00, 0x14, 0x00, 0x08, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x43, 0xbe, 0x00, 0x00, 0x00, 0xb7, 0xe8, 0x07, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00 })); + } + + /** + * @see <a href="https://issues.apache.org/jira/browse/COMPRESS-518">COMPRESS-518</a> + */ + @Test + public void testThrowsIfZip64ExtraCouldNotBeUnderstood() { + assertThrows(IOException.class, + () -> fuzzingTest(new int[] { 0x50, 0x4b, 0x03, 0x04, 0x2e, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x84, 0xb6, 0xba, 0x46, 0x72, 0xb6, 0xfe, 0x77, 0x63, + 0x00, 0x00, 0x00, 0x6b, 0x00, 0x00, 0x00, 0x03, 0x00, 0x1c, 0x00, 0x62, 0x62, 0x62, 0x01, 0x00, 0x09, 0x00, 0x03, 0xe7, 0xce, 0x64, + 0x55, 0xf3, 0xce, 0x64, 0x55, 0x75, 0x78, 0x0b, 0x00, 0x01, 0x04, 0x5c, 0xf9, 0x01, 0x00, 0x04, 0x88, 0x13, 0x00, 0x00 })); + } + + @Test + public void testThrowsIOExceptionIfThereIsCorruptedZip64Extra() throws IOException { + try (InputStream fis = newInputStream("COMPRESS-546.zip"); + ZipArchiveInputStream zipInputStream = new ZipArchiveInputStream(fis)) { + assertThrows(IOException.class, () -> getAllZipEntries(zipInputStream)); + } + } + @Test public void testUnshrinkEntry() throws Exception { try (ZipArchiveInputStream in = new ZipArchiveInputStream(newInputStream("SHRUNK.ZIP"))) { @@ -655,58 +709,4 @@ public class ZipArchiveInputStreamTest extends AbstractTest { getAllZipEntries(zipInputStream); } } - - @Test - public void testThrowsIfStoredDDIsDifferentFromLengthRead() throws IOException { - try (InputStream fs = newInputStream("bla-stored-dd-contradicts-actualsize.zip"); - ZipArchiveInputStream archive = new ZipArchiveInputStream(fs, "UTF-8", true, true)) { - final ZipArchiveEntry e = archive.getNextZipEntry(); - assertNotNull(e); - assertEquals("test1.xml", e.getName()); - assertEquals(-1, e.getCompressedSize()); - assertEquals(-1, e.getSize()); - assertThrows(ZipException.class, () -> IOUtils.toByteArray(archive)); - } - } - - @Test - public void testThrowsIfStoredDDIsInconsistent() throws IOException { - try (InputStream fs = newInputStream("bla-stored-dd-sizes-differ.zip"); - ZipArchiveInputStream archive = new ZipArchiveInputStream(fs, "UTF-8", true, true)) { - final ZipArchiveEntry e = archive.getNextZipEntry(); - assertNotNull(e); - assertEquals("test1.xml", e.getName()); - assertEquals(-1, e.getCompressedSize()); - assertEquals(-1, e.getSize()); - assertThrows(ZipException.class, () -> IOUtils.toByteArray(archive)); - } - } - - /** - * @see <a href="https://issues.apache.org/jira/browse/COMPRESS-523">COMPRESS-523</a> - */ - @Test - public void testThrowsIfThereIsNoEocd() { - assertThrows(IOException.class, () -> fuzzingTest(new int[] { 0x50, 0x4b, 0x01, 0x02, 0x14, 0x00, 0x14, 0x00, 0x08, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x43, 0xbe, 0x00, 0x00, 0x00, 0xb7, 0xe8, 0x07, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00 })); - } - - /** - * @see <a href="https://issues.apache.org/jira/browse/COMPRESS-518">COMPRESS-518</a> - */ - @Test - public void testThrowsIfZip64ExtraCouldNotBeUnderstood() { - assertThrows(IOException.class, - () -> fuzzingTest(new int[] { 0x50, 0x4b, 0x03, 0x04, 0x2e, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x84, 0xb6, 0xba, 0x46, 0x72, 0xb6, 0xfe, 0x77, 0x63, - 0x00, 0x00, 0x00, 0x6b, 0x00, 0x00, 0x00, 0x03, 0x00, 0x1c, 0x00, 0x62, 0x62, 0x62, 0x01, 0x00, 0x09, 0x00, 0x03, 0xe7, 0xce, 0x64, - 0x55, 0xf3, 0xce, 0x64, 0x55, 0x75, 0x78, 0x0b, 0x00, 0x01, 0x04, 0x5c, 0xf9, 0x01, 0x00, 0x04, 0x88, 0x13, 0x00, 0x00 })); - } - - @Test - public void testThrowsIOExceptionIfThereIsCorruptedZip64Extra() throws IOException { - try (InputStream fis = newInputStream("COMPRESS-546.zip"); - ZipArchiveInputStream zipInputStream = new ZipArchiveInputStream(fis)) { - assertThrows(IOException.class, () -> getAllZipEntries(zipInputStream)); - } - } } diff --git a/src/test/java/org/apache/commons/compress/archivers/zip/ZipFileTest.java b/src/test/java/org/apache/commons/compress/archivers/zip/ZipFileTest.java index 645588f35..77714979c 100644 --- a/src/test/java/org/apache/commons/compress/archivers/zip/ZipFileTest.java +++ b/src/test/java/org/apache/commons/compress/archivers/zip/ZipFileTest.java @@ -887,6 +887,13 @@ public class ZipFileTest extends AbstractTest { assertNotNull(zf.getEntry("test2.xml")); } + @Test + public void testThrowsExceptionWhenWritingPreamble() throws IOException { + final ZipArchiveOutputStream outputStream = new ZipArchiveOutputStream(new ByteArrayOutputStream()); + outputStream.putArchiveEntry(new ZipArchiveEntry()); + assertThrows(IllegalStateException.class, () -> outputStream.writePreamble(ByteUtils.EMPTY_BYTE_ARRAY)); + } + @Test public void testUnixSymlinkSampleFile() throws Exception { final String entryPrefix = "COMPRESS-214_unix_symlinks/"; @@ -965,11 +972,4 @@ public class ZipFileTest extends AbstractTest { assertNull(zf.getEntry("\u00e4\\\u00fc.txt")); assertNotNull(zf.getEntry("\u00e4/\u00fc.txt")); } - - @Test - public void testThrowsExceptionWhenWritingPreamble() throws IOException { - final ZipArchiveOutputStream outputStream = new ZipArchiveOutputStream(new ByteArrayOutputStream()); - outputStream.putArchiveEntry(new ZipArchiveEntry()); - assertThrows(IllegalStateException.class, () -> outputStream.writePreamble(ByteUtils.EMPTY_BYTE_ARRAY)); - } } diff --git a/src/test/java/org/apache/commons/compress/harmony/pack200/tests/PackingOptionsTest.java b/src/test/java/org/apache/commons/compress/harmony/pack200/tests/PackingOptionsTest.java index cdbd1cbfd..d89162f8a 100644 --- a/src/test/java/org/apache/commons/compress/harmony/pack200/tests/PackingOptionsTest.java +++ b/src/test/java/org/apache/commons/compress/harmony/pack200/tests/PackingOptionsTest.java @@ -107,23 +107,6 @@ public class PackingOptionsTest extends AbstractTempDirTest { assertThrows(IllegalArgumentException.class, () -> options.setDeflateHint("hello"), "Should throw IllegalArgumentException for incorrect deflate hint"); } - @Test - public void testPackEffort0() throws Pack200Exception, IOException, URISyntaxException { - final File f1 = new File(Archive.class.getResource("/pack200/jndi.jar").toURI()); - File file = createTempFile("jndiE0", ".pack"); - try (JarFile in = new JarFile(f1); - FileOutputStream out = new FileOutputStream(file)) { - final PackingOptions options = new PackingOptions(); - options.setGzip(false); - options.setEffort(0); - new Archive(in, out, options).pack(); - } - try (JarFile jf1 = new JarFile(f1); - JarFile jf2 = new JarFile(file)) { - compareFiles(jf1, jf2); - } - } - @Test public void testErrorAttributes() throws Exception { File file = createTempFile("unknown", ".pack"); @@ -359,13 +342,6 @@ public class PackingOptionsTest extends AbstractTempDirTest { } } - private void unpackJar(final File sourceFile, final File destFile) throws Pack200Exception, IOException, FileNotFoundException { - try (InputStream in2 = new FileInputStream(sourceFile); - JarOutputStream out2 = new JarOutputStream(new FileOutputStream(destFile))) { - unpack(in2, out2); - } - } - @Test public void testNewAttributes2() throws Exception { File file = createTempFile("unknown", ".pack"); @@ -391,6 +367,23 @@ public class PackingOptionsTest extends AbstractTempDirTest { } } + @Test + public void testPackEffort0() throws Pack200Exception, IOException, URISyntaxException { + final File f1 = new File(Archive.class.getResource("/pack200/jndi.jar").toURI()); + File file = createTempFile("jndiE0", ".pack"); + try (JarFile in = new JarFile(f1); + FileOutputStream out = new FileOutputStream(file)) { + final PackingOptions options = new PackingOptions(); + options.setGzip(false); + options.setEffort(0); + new Archive(in, out, options).pack(); + } + try (JarFile jf1 = new JarFile(f1); + JarFile jf2 = new JarFile(file)) { + compareFiles(jf1, jf2); + } + } + @Test public void testPassAttributes() throws Exception { File file = createTempFile("unknown", ".pack"); @@ -499,22 +492,6 @@ public class PackingOptionsTest extends AbstractTempDirTest { } } - // public void testE0again() throws IOException, Pack200Exception, - // URISyntaxException { - // JarInputStream inputStream = new - // JarInputStream(Archive.class.getResourceAsStream("/pack200/jndi.jar")); - // file = File.createTempFile("jndiE0", ".pack"); - // out = new FileOutputStream(file); - // Archive archive = new Archive(inputStream, out, false); - // archive.setEffort(0); - // archive.pack(); - // inputStream.close(); - // out.close(); - // in = new JarFile(new File(Archive.class.getResource( - // "/pack200/jndi.jar").toURI())); - // compareFiles(in, new JarFile(file)); - // } - @Test public void testStripDebug() throws IOException, Pack200Exception, URISyntaxException { File file = createTempFile("sql", ".pack"); @@ -539,8 +516,31 @@ public class PackingOptionsTest extends AbstractTempDirTest { } } + // public void testE0again() throws IOException, Pack200Exception, + // URISyntaxException { + // JarInputStream inputStream = new + // JarInputStream(Archive.class.getResourceAsStream("/pack200/jndi.jar")); + // file = File.createTempFile("jndiE0", ".pack"); + // out = new FileOutputStream(file); + // Archive archive = new Archive(inputStream, out, false); + // archive.setEffort(0); + // archive.pack(); + // inputStream.close(); + // out.close(); + // in = new JarFile(new File(Archive.class.getResource( + // "/pack200/jndi.jar").toURI())); + // compareFiles(in, new JarFile(file)); + // } + private void unpack(final InputStream inputStream, final JarOutputStream outputStream) throws Pack200Exception, IOException { new org.apache.commons.compress.harmony.unpack200.Archive(inputStream, outputStream).unpack(); } + private void unpackJar(final File sourceFile, final File destFile) throws Pack200Exception, IOException, FileNotFoundException { + try (InputStream in2 = new FileInputStream(sourceFile); + JarOutputStream out2 = new JarOutputStream(new FileOutputStream(destFile))) { + unpack(in2, out2); + } + } + } diff --git a/src/test/java/org/apache/commons/compress/utils/MultiReadOnlySeekableByteChannelTest.java b/src/test/java/org/apache/commons/compress/utils/MultiReadOnlySeekableByteChannelTest.java index 29b758c7c..735c93907 100644 --- a/src/test/java/org/apache/commons/compress/utils/MultiReadOnlySeekableByteChannelTest.java +++ b/src/test/java/org/apache/commons/compress/utils/MultiReadOnlySeekableByteChannelTest.java @@ -299,30 +299,6 @@ public class MultiReadOnlySeekableByteChannelTest { // https://docs.oracle.com/javase/7/docs/api/java/io/Closeable.html#close() - @Test - public void testVerifyGrouped() { - assertArrayEquals(new byte[][] { new byte[] { 1, 2, 3, }, new byte[] { 4, 5, 6, }, new byte[] { 7, }, }, - grouped(new byte[] { 1, 2, 3, 4, 5, 6, 7 }, 3)); - assertArrayEquals(new byte[][] { new byte[] { 1, 2, 3, }, new byte[] { 4, 5, 6, }, }, grouped(new byte[] { 1, 2, 3, 4, 5, 6 }, 3)); - assertArrayEquals(new byte[][] { new byte[] { 1, 2, 3, }, new byte[] { 4, 5, }, }, grouped(new byte[] { 1, 2, 3, 4, 5, }, 3)); - } - - // https://docs.oracle.com/javase/7/docs/api/java/nio/channels/SeekableByteChannel.html#position() - - /* - * <q>ClosedChannelException - If this channel is closed</q> - */ - @Test - @Disabled("we deliberately violate the spec") - public void throwsClosedChannelExceptionWhenPositionIsReadOnClosedChannel() throws Exception { - try (SeekableByteChannel c = testChannel()) { - c.close(); - c.position(); - } - } - - // https://docs.oracle.com/javase/7/docs/api/java/nio/channels/SeekableByteChannel.html#size() - /* * <q>ClosedChannelException - If this channel is closed</q> */ @@ -334,7 +310,7 @@ public class MultiReadOnlySeekableByteChannelTest { } } - // https://docs.oracle.com/javase/7/docs/api/java/nio/channels/SeekableByteChannel.html#position(long) + // https://docs.oracle.com/javase/7/docs/api/java/nio/channels/SeekableByteChannel.html#position() /* * <q>ClosedChannelException - If this channel is closed</q> @@ -347,6 +323,8 @@ public class MultiReadOnlySeekableByteChannelTest { } } + // https://docs.oracle.com/javase/7/docs/api/java/nio/channels/SeekableByteChannel.html#size() + /* * <q>IOException - If the new position is negative</q> */ @@ -357,6 +335,8 @@ public class MultiReadOnlySeekableByteChannelTest { } } + // https://docs.oracle.com/javase/7/docs/api/java/nio/channels/SeekableByteChannel.html#position(long) + @Test public void testTwoEmptyChannelsConcatenateAsEmptyChannel() throws IOException { try (SeekableByteChannel channel = MultiReadOnlySeekableByteChannel.forSeekableByteChannels(makeEmpty(), makeEmpty())) { @@ -364,4 +344,24 @@ public class MultiReadOnlySeekableByteChannelTest { } } + @Test + public void testVerifyGrouped() { + assertArrayEquals(new byte[][] { new byte[] { 1, 2, 3, }, new byte[] { 4, 5, 6, }, new byte[] { 7, }, }, + grouped(new byte[] { 1, 2, 3, 4, 5, 6, 7 }, 3)); + assertArrayEquals(new byte[][] { new byte[] { 1, 2, 3, }, new byte[] { 4, 5, 6, }, }, grouped(new byte[] { 1, 2, 3, 4, 5, 6 }, 3)); + assertArrayEquals(new byte[][] { new byte[] { 1, 2, 3, }, new byte[] { 4, 5, }, }, grouped(new byte[] { 1, 2, 3, 4, 5, }, 3)); + } + + /* + * <q>ClosedChannelException - If this channel is closed</q> + */ + @Test + @Disabled("we deliberately violate the spec") + public void throwsClosedChannelExceptionWhenPositionIsReadOnClosedChannel() throws Exception { + try (SeekableByteChannel c = testChannel()) { + c.close(); + c.position(); + } + } + } diff --git a/src/test/java/org/apache/commons/compress/utils/SeekableInMemoryByteChannelTest.java b/src/test/java/org/apache/commons/compress/utils/SeekableInMemoryByteChannelTest.java index 9dea2c53d..e6071df8d 100644 --- a/src/test/java/org/apache/commons/compress/utils/SeekableInMemoryByteChannelTest.java +++ b/src/test/java/org/apache/commons/compress/utils/SeekableInMemoryByteChannelTest.java @@ -237,20 +237,6 @@ public class SeekableInMemoryByteChannelTest { // https://docs.oracle.com/javase/7/docs/api/java/nio/channels/SeekableByteChannel.html#size() - /* - * <q>ClosedChannelException - If this channel is closed</q> - */ - @Test - @Disabled("we deliberately violate the spec") - public void throwsClosedChannelExceptionWhenPositionIsReadOnClosedChannel() throws Exception { - try (SeekableByteChannel c = new SeekableInMemoryByteChannel()) { - c.close(); - c.position(); - } - } - - // https://docs.oracle.com/javase/7/docs/api/java/nio/channels/SeekableByteChannel.html#position(long) - /* * <q>ClosedChannelException - If this channel is closed</q> */ @@ -262,29 +248,7 @@ public class SeekableInMemoryByteChannelTest { } } - /* - * <q>ClosedChannelException - If this channel is closed</q> - */ - @Test - @Disabled("we deliberately violate the spec") - public void throwsClosedChannelExceptionWhenSizeIsReadOnClosedChannel() throws Exception { - try (SeekableByteChannel c = new SeekableInMemoryByteChannel()) { - c.close(); - c.size(); - } - } - - /* - * <q>ClosedChannelException - If this channel is closed</q> - */ - @Test - @Disabled("we deliberately violate the spec") - public void throwsClosedChannelExceptionWhenTruncateIsCalledOnClosedChannel() throws Exception { - try (SeekableByteChannel c = new SeekableInMemoryByteChannel()) { - c.close(); - c.truncate(0); - } - } + // https://docs.oracle.com/javase/7/docs/api/java/nio/channels/SeekableByteChannel.html#position(long) /* * <q>IllegalArgumentException - If the new position is negative</q> @@ -296,8 +260,6 @@ public class SeekableInMemoryByteChannelTest { } } - // https://docs.oracle.com/javase/7/docs/api/java/nio/channels/SeekableByteChannel.html#truncate(long) - /* * <q>IOException - If the new position is negative</q> */ @@ -334,6 +296,8 @@ public class SeekableInMemoryByteChannelTest { } } + // https://docs.oracle.com/javase/7/docs/api/java/nio/channels/SeekableByteChannel.html#truncate(long) + /* * <q> In either case, if the current position is greater than the given size then it is set to that size.</q> */ @@ -390,6 +354,42 @@ public class SeekableInMemoryByteChannelTest { } } + /* + * <q>ClosedChannelException - If this channel is closed</q> + */ + @Test + @Disabled("we deliberately violate the spec") + public void throwsClosedChannelExceptionWhenPositionIsReadOnClosedChannel() throws Exception { + try (SeekableByteChannel c = new SeekableInMemoryByteChannel()) { + c.close(); + c.position(); + } + } + + /* + * <q>ClosedChannelException - If this channel is closed</q> + */ + @Test + @Disabled("we deliberately violate the spec") + public void throwsClosedChannelExceptionWhenSizeIsReadOnClosedChannel() throws Exception { + try (SeekableByteChannel c = new SeekableInMemoryByteChannel()) { + c.close(); + c.size(); + } + } + + /* + * <q>ClosedChannelException - If this channel is closed</q> + */ + @Test + @Disabled("we deliberately violate the spec") + public void throwsClosedChannelExceptionWhenTruncateIsCalledOnClosedChannel() throws Exception { + try (SeekableByteChannel c = new SeekableInMemoryByteChannel()) { + c.close(); + c.truncate(0); + } + } + /* * <q>Setting the position to a value that is greater than the current size is legal but does not change the size of the entity. A later attempt to write * bytes at such a position will cause the entity to grow to accommodate the new bytes; the values of any bytes between the previous end-of-file and the