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 2017/04/29 14:47:50 UTC
commons-compress git commit: provide default implementation in
ArchiveFormat interface
Repository: commons-compress
Updated Branches:
refs/heads/compress-2.0 77d9195c1 -> e36fcf9af
provide default implementation in ArchiveFormat interface
Project: http://git-wip-us.apache.org/repos/asf/commons-compress/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-compress/commit/e36fcf9a
Tree: http://git-wip-us.apache.org/repos/asf/commons-compress/tree/e36fcf9a
Diff: http://git-wip-us.apache.org/repos/asf/commons-compress/diff/e36fcf9a
Branch: refs/heads/compress-2.0
Commit: e36fcf9af4aced6f6477c5007802e5f19288c540
Parents: 77d9195
Author: Stefan Bodewig <bo...@apache.org>
Authored: Sat Apr 29 16:41:55 2017 +0200
Committer: Stefan Bodewig <bo...@apache.org>
Committed: Sat Apr 29 16:41:55 2017 +0200
----------------------------------------------------------------------
.../compress2/archivers/ArchiveFormat.java | 17 ++++++++++--
.../archivers/spi/AbstractArchiveFormat.java | 27 --------------------
2 files changed, 15 insertions(+), 29 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/commons-compress/blob/e36fcf9a/src/main/java/org/apache/commons/compress2/archivers/ArchiveFormat.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/compress2/archivers/ArchiveFormat.java b/src/main/java/org/apache/commons/compress2/archivers/ArchiveFormat.java
index ca1ecfa..5dd2a6b 100644
--- a/src/main/java/org/apache/commons/compress2/archivers/ArchiveFormat.java
+++ b/src/main/java/org/apache/commons/compress2/archivers/ArchiveFormat.java
@@ -19,11 +19,13 @@
package org.apache.commons.compress2.archivers;
import java.nio.ByteBuffer;
+import java.nio.channels.FileChannel;
import java.nio.channels.ReadableByteChannel;
import java.nio.channels.SeekableByteChannel;
import java.nio.channels.WritableByteChannel;
import java.nio.charset.Charset;
import java.nio.file.Path;
+import java.nio.file.StandardOpenOption;
import java.io.IOException;
/**
@@ -93,7 +95,14 @@ public interface ArchiveFormat<A extends ArchiveEntry> {
* @param charset the charset used for encoding the entry names.
* @throws IOException
*/
- ArchiveInput<A> readFrom(Path path, Charset charset) throws IOException;
+ default ArchiveInput<A> readFrom(Path path, Charset charset) throws IOException {
+ SeekableByteChannel channel = FileChannel.open(path, StandardOpenOption.READ);
+ if (supportsRandomAccessInput()) {
+ return readWithRandomAccessFrom(channel, charset);
+ }
+
+ return readFrom(channel, charset);
+ }
/**
* Provides random access to an archive assuming the given charset for entry names.
* @param channel the seekable channel to read from
@@ -121,5 +130,9 @@ public interface ArchiveFormat<A extends ArchiveEntry> {
* @throws IOException
* @throws UnsupportedOperationException if this format doesn't support writing
*/
- ArchiveOutput<A> writeTo(Path path, Charset charset) throws IOException, UnsupportedOperationException;
+ default ArchiveOutput<A> writeTo(Path path, Charset charset) throws IOException, UnsupportedOperationException {
+ return writeTo(FileChannel.open(path, StandardOpenOption.WRITE, StandardOpenOption.CREATE,
+ StandardOpenOption.TRUNCATE_EXISTING),
+ charset);
+ }
}
http://git-wip-us.apache.org/repos/asf/commons-compress/blob/e36fcf9a/src/main/java/org/apache/commons/compress2/archivers/spi/AbstractArchiveFormat.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/compress2/archivers/spi/AbstractArchiveFormat.java b/src/main/java/org/apache/commons/compress2/archivers/spi/AbstractArchiveFormat.java
index 3ee071c..76475a8 100644
--- a/src/main/java/org/apache/commons/compress2/archivers/spi/AbstractArchiveFormat.java
+++ b/src/main/java/org/apache/commons/compress2/archivers/spi/AbstractArchiveFormat.java
@@ -23,10 +23,7 @@ import java.nio.ByteBuffer;
import java.nio.channels.ReadableByteChannel;
import java.nio.channels.SeekableByteChannel;
import java.nio.channels.WritableByteChannel;
-import java.nio.channels.FileChannel;
import java.nio.charset.Charset;
-import java.nio.file.Path;
-import java.nio.file.StandardOpenOption;
import org.apache.commons.compress2.archivers.ArchiveEntry;
import org.apache.commons.compress2.archivers.ArchiveFormat;
import org.apache.commons.compress2.archivers.ArchiveInput;
@@ -98,20 +95,6 @@ public abstract class AbstractArchiveFormat<A extends ArchiveEntry> implements A
}
/**
* {@inheritDoc}
- * <p>This implementation delegates to {@link #readWithRandomAccessFrom} if random access is supported or {@link
- * #readFrom(ReadableByteChannel, Charset)} otherwise.</p>
- */
- @Override
- public ArchiveInput<A> readFrom(Path path, Charset charset) throws IOException {
- SeekableByteChannel channel = FileChannel.open(path, StandardOpenOption.READ);
- if (supportsRandomAccessInput()) {
- return readWithRandomAccessFrom(channel, charset);
- }
-
- return readFrom(channel, charset);
- }
- /**
- * {@inheritDoc}
* <p>This implementation always throws an UnsupportedOperationException.</p>
*/
@Override
@@ -129,14 +112,4 @@ public abstract class AbstractArchiveFormat<A extends ArchiveEntry> implements A
throws IOException, UnsupportedOperationException {
throw new UnsupportedOperationException("this format is read-only");
}
- /**
- * {@inheritDoc}
- * <p>This implementation always delegates to {@link #writeTo(Channel, Charset)}.</p>
- */
- @Override
- public ArchiveOutput<A> writeTo(Path path, Charset charset) throws IOException, UnsupportedOperationException {
- return writeTo(FileChannel.open(path, StandardOpenOption.WRITE, StandardOpenOption.CREATE,
- StandardOpenOption.TRUNCATE_EXISTING),
- charset);
- }
}