You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by bo...@apache.org on 2019/08/18 15:27:57 UTC

[commons-compress] branch master updated (8bdb913 -> 26ad28c)

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

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


    from 8bdb913  COMPRESS-231 deal with edge case
     new 0cc0820  COMPRESS-231 javadocs
     new 26ad28c  COMPRESS-231 increase test coverage

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:
 .../utils/MultiReadOnlySeekableByteChannel.java    |  2 +
 .../MultiReadOnlySeekableByteChannelTest.java      | 77 ++++++++++++++++++++++
 2 files changed, 79 insertions(+)


[commons-compress] 01/02: COMPRESS-231 javadocs

Posted by bo...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 0cc082068c25419ea41133978dfb405bb058e48c
Author: Stefan Bodewig <bo...@apache.org>
AuthorDate: Sun Aug 18 17:10:06 2019 +0200

    COMPRESS-231 javadocs
---
 .../apache/commons/compress/utils/MultiReadOnlySeekableByteChannel.java | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/src/main/java/org/apache/commons/compress/utils/MultiReadOnlySeekableByteChannel.java b/src/main/java/org/apache/commons/compress/utils/MultiReadOnlySeekableByteChannel.java
index 221294b..203d9f3 100644
--- a/src/main/java/org/apache/commons/compress/utils/MultiReadOnlySeekableByteChannel.java
+++ b/src/main/java/org/apache/commons/compress/utils/MultiReadOnlySeekableByteChannel.java
@@ -193,6 +193,7 @@ public class MultiReadOnlySeekableByteChannel implements SeekableByteChannel {
      *
      * @param channels the channels to concatenate
      * @throws NullPointerException if channels is null
+     * @return SeekableByteChannel that concatenates all provided channels
      */
     public static SeekableByteChannel forSeekableByteChannels(SeekableByteChannel... channels) {
         if (Objects.requireNonNull(channels, "channels must not be null").length == 1) {
@@ -207,6 +208,7 @@ public class MultiReadOnlySeekableByteChannel implements SeekableByteChannel {
      * @param files the files to concatenate
      * @throws NullPointerException if files is null
      * @throws IOException if opening a channel for one of the files fails
+     * @return SeekableByteChannel that concatenates all provided files
      */
     public static SeekableByteChannel forFiles(File... files) throws IOException {
         List<SeekableByteChannel> channels = new ArrayList<>();


[commons-compress] 02/02: COMPRESS-231 increase test coverage

Posted by bo...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 26ad28cdaeb46f5cd0344687116952db97857929
Author: Stefan Bodewig <bo...@apache.org>
AuthorDate: Sun Aug 18 17:27:40 2019 +0200

    COMPRESS-231 increase test coverage
---
 .../MultiReadOnlySeekableByteChannelTest.java      | 77 ++++++++++++++++++++++
 1 file changed, 77 insertions(+)

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 a405ed8..77694d5 100644
--- a/src/test/java/org/apache/commons/compress/utils/MultiReadOnlySeekableByteChannelTest.java
+++ b/src/test/java/org/apache/commons/compress/utils/MultiReadOnlySeekableByteChannelTest.java
@@ -21,6 +21,7 @@ package org.apache.commons.compress.utils;
 import java.io.IOException;
 import java.nio.ByteBuffer;
 import java.nio.channels.ClosedChannelException;
+import java.nio.channels.NonWritableChannelException;
 import java.nio.channels.SeekableByteChannel;
 import java.nio.charset.StandardCharsets;
 import java.util.ArrayList;
@@ -104,6 +105,43 @@ public class MultiReadOnlySeekableByteChannelTest {
             }, grouped(new byte[] { 1, 2, 3, 4, 5, }, 3));
     }
 
+    @Test
+    public void closesAllAndThrowsExceptionIfCloseThrows() {
+        SeekableByteChannel[] ts = new ThrowingSeekableByteChannel[] {
+            new ThrowingSeekableByteChannel(),
+            new ThrowingSeekableByteChannel()
+        };
+        SeekableByteChannel s = MultiReadOnlySeekableByteChannel.forSeekableByteChannels(ts);
+        try {
+            s.close();
+            Assert.fail("IOException expected");
+        } catch (IOException expected) {
+        }
+        Assert.assertFalse(ts[0].isOpen());
+        Assert.assertFalse(ts[1].isOpen());
+    }
+
+    @Test
+    public void cantTruncate() throws IOException {
+        SeekableByteChannel s = MultiReadOnlySeekableByteChannel.forSeekableByteChannels(makeEmpty(), makeEmpty());
+        thrown.expect(NonWritableChannelException.class);
+        s.truncate(1);
+    }
+
+    @Test
+    public void cantWrite() throws IOException {
+        SeekableByteChannel s = MultiReadOnlySeekableByteChannel.forSeekableByteChannels(makeEmpty(), makeEmpty());
+        thrown.expect(NonWritableChannelException.class);
+        s.write(ByteBuffer.allocate(10));
+    }
+
+    @Test
+    public void cantPositionToANegativePosition() throws IOException {
+        SeekableByteChannel s = MultiReadOnlySeekableByteChannel.forSeekableByteChannels(makeEmpty(), makeEmpty());
+        thrown.expect(IllegalArgumentException.class);
+        s.position(-1);
+    }
+
     private SeekableByteChannel makeEmpty() {
         return makeSingle(new byte[0]);
     }
@@ -167,6 +205,8 @@ public class MultiReadOnlySeekableByteChannelTest {
         Assert.assertEquals("readBufferSize " + readBufferSize, expected.length, channel.size());
         channel.position(0);
         Assert.assertEquals("readBufferSize " + readBufferSize, 0, channel.position());
+        Assert.assertEquals("readBufferSize " + readBufferSize, 0,
+            channel.read(ByteBuffer.allocate(0)));
 
         // Will hold the entire result that we read
         final ByteBuffer resultBuffer = ByteBuffer.allocate(expected.length + 100);
@@ -214,4 +254,41 @@ public class MultiReadOnlySeekableByteChannelTest {
         }
         return groups.toArray(new byte[0][]);
     }
+
+    private static class ThrowingSeekableByteChannel implements SeekableByteChannel {
+        private boolean closed = false;
+        @Override
+        public boolean isOpen() {
+            return !closed;
+        }
+        @Override
+        public void close() throws IOException {
+            closed = true;
+            throw new IOException("foo");
+        }
+        @Override
+        public int read(ByteBuffer dst) throws IOException {
+            return -1;
+        }
+        @Override
+        public int write(ByteBuffer src) throws IOException {
+            return 0;
+        }
+        @Override
+        public long position() throws IOException {
+            return 0;
+        }
+        @Override
+        public SeekableByteChannel position(long newPosition) throws IOException {
+            return this;
+        }
+        @Override
+        public long size() throws IOException {
+            return 0;
+        }
+        @Override
+        public SeekableByteChannel truncate(long size) throws IOException {
+            return this;
+        }
+    }
 }