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 2016/03/23 16:32:26 UTC
[4/6] commons-compress git commit: embrace seekable channels
embrace seekable channels
Project: http://git-wip-us.apache.org/repos/asf/commons-compress/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-compress/commit/699e3e2a
Tree: http://git-wip-us.apache.org/repos/asf/commons-compress/tree/699e3e2a
Diff: http://git-wip-us.apache.org/repos/asf/commons-compress/diff/699e3e2a
Branch: refs/heads/compress-2.0
Commit: 699e3e2a4913305b6176173cc877708c66ed10bb
Parents: 29377a3
Author: Stefan Bodewig <bo...@apache.org>
Authored: Wed Mar 23 15:53:50 2016 +0100
Committer: Stefan Bodewig <bo...@apache.org>
Committed: Wed Mar 23 15:53:50 2016 +0100
----------------------------------------------------------------------
.../commons/compress2/archivers/ArchiveFormat.java | 13 +++++--------
.../apache/commons/compress2/archivers/Archivers.java | 4 ++--
.../compress2/archivers/RandomAccessArchiveInput.java | 1 -
.../compress2/archivers/spi/AbstractArchiveFormat.java | 12 +++++++-----
.../commons/compress2/formats/ar/ArArchiveFormat.java | 4 ++--
5 files changed, 16 insertions(+), 18 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/commons-compress/blob/699e3e2a/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 6a37e1f..f527ed4 100644
--- a/src/main/java/org/apache/commons/compress2/archivers/ArchiveFormat.java
+++ b/src/main/java/org/apache/commons/compress2/archivers/ArchiveFormat.java
@@ -20,6 +20,7 @@ package org.apache.commons.compress2.archivers;
import java.nio.ByteBuffer;
import java.nio.channels.ReadableByteChannel;
+import java.nio.channels.SeekableByteChannel;
import java.nio.channels.WritableByteChannel;
import java.nio.charset.Charset;
import java.io.File;
@@ -50,12 +51,12 @@ public interface ArchiveFormat<A extends ArchiveEntry> {
* Does the format support writing to arbitrary non-seekable channels?
* @return whether writing to arbitrary non-seekable channels is supported
*/
- boolean supportsWritingToChannels();
+ boolean supportsWritingToNonSeekableChannels();
/**
* Does the format support reading from arbitrary non-seekable channels?
* @return whether writing to arbitrary non-seekable channels is supported
*/
- boolean supportsReadingFromChannels();
+ boolean supportsReadingFromNonSeekableChannels();
/**
* Does the format support content-based detection?
@@ -92,19 +93,16 @@ public interface ArchiveFormat<A extends ArchiveEntry> {
* @param charset the charset used for encoding the entry names.
* @throws IOException
*/
- // TODO go for SeekableByteChannel rather than File when embracing Java7?
// TODO use Path rather than File?
ArchiveInput<A> readFrom(File file, Charset charset) throws IOException;
/**
* Provides random access to an archive assuming the given charset for entry names.
- * @param file the file to read from
+ * @param channel the seekable channel to read from
* @param charset the charset used for encoding the entry names.
* @throws IOException
* @throws UnsupportedOperationException if this format doesn't support random access
*/
- // TODO go for SeekableByteChannel rather than File when embracing Java7?
- // TODO use Path rather than File?
- RandomAccessArchiveInput<A> readWithRandomAccessFrom(File file, Charset charset)
+ RandomAccessArchiveInput<A> readWithRandomAccessFrom(SeekableByteChannel channel, Charset charset)
throws IOException, UnsupportedOperationException;
/**
@@ -124,7 +122,6 @@ public interface ArchiveFormat<A extends ArchiveEntry> {
* @throws IOException
* @throws UnsupportedOperationException if this format doesn't support writing
*/
- // TODO go for SeekableByteChannel rather than File when embracing Java7?
// TODO use Path rather than File?
ArchiveOutput<A> writeTo(File file, Charset charset) throws IOException, UnsupportedOperationException;
}
http://git-wip-us.apache.org/repos/asf/commons-compress/blob/699e3e2a/src/main/java/org/apache/commons/compress2/archivers/Archivers.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/compress2/archivers/Archivers.java b/src/main/java/org/apache/commons/compress2/archivers/Archivers.java
index 195f190..aa1a882 100644
--- a/src/main/java/org/apache/commons/compress2/archivers/Archivers.java
+++ b/src/main/java/org/apache/commons/compress2/archivers/Archivers.java
@@ -140,14 +140,14 @@ public class Archivers implements Iterable<ArchiveFormat<? extends ArchiveEntry>
private static final Predicate<ArchiveFormat<? extends ArchiveEntry>> WRITE_TO_CHANNEL_PREDICATE =
new Predicate<ArchiveFormat<? extends ArchiveEntry>>() {
public boolean matches(ArchiveFormat<? extends ArchiveEntry> a) {
- return a.supportsWritingToChannels();
+ return a.supportsWritingToNonSeekableChannels();
}
};
private static final Predicate<ArchiveFormat<? extends ArchiveEntry>> READ_FROM_CHANNEL_PREDICATE =
new Predicate<ArchiveFormat<? extends ArchiveEntry>>() {
public boolean matches(ArchiveFormat<? extends ArchiveEntry> a) {
- return a.supportsReadingFromChannels();
+ return a.supportsReadingFromNonSeekableChannels();
}
};
http://git-wip-us.apache.org/repos/asf/commons-compress/blob/699e3e2a/src/main/java/org/apache/commons/compress2/archivers/RandomAccessArchiveInput.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/compress2/archivers/RandomAccessArchiveInput.java b/src/main/java/org/apache/commons/compress2/archivers/RandomAccessArchiveInput.java
index 9d99461..a970e93 100644
--- a/src/main/java/org/apache/commons/compress2/archivers/RandomAccessArchiveInput.java
+++ b/src/main/java/org/apache/commons/compress2/archivers/RandomAccessArchiveInput.java
@@ -38,6 +38,5 @@ public interface RandomAccessArchiveInput<A extends ArchiveEntry> extends Archiv
* @param entry the entry to read the contents of
* @return a channel to read the entry's contents from or null if the entry is not part of this archive.
*/
- // TODO SeekableByteChannel if using Java 7?
ReadableByteChannel getChannel(A entry);
}
http://git-wip-us.apache.org/repos/asf/commons-compress/blob/699e3e2a/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 2e02555..eef9b10 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
@@ -22,6 +22,7 @@ import java.io.File;
import java.io.IOException;
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;
@@ -55,13 +56,13 @@ public abstract class AbstractArchiveFormat<A extends ArchiveEntry> implements A
* <p>This implementation always returns false.</p>
*/
@Override
- public boolean supportsWritingToChannels() { return false; }
+ public boolean supportsWritingToNonSeekableChannels() { return false; }
/**
* {@inheritDoc}
* <p>This implementation always returns false.</p>
*/
@Override
- public boolean supportsReadingFromChannels() { return false; }
+ public boolean supportsReadingFromNonSeekableChannels() { return false; }
/**
* {@inheritDoc}
@@ -102,18 +103,19 @@ public abstract class AbstractArchiveFormat<A extends ArchiveEntry> implements A
*/
@Override
public ArchiveInput<A> readFrom(File file, Charset charset) throws IOException {
+ SeekableByteChannel channel = FileChannel.open(file.toPath(), StandardOpenOption.READ);
if (supportsRandomAccessInput()) {
- return readWithRandomAccessFrom(file, charset);
+ return readWithRandomAccessFrom(channel, charset);
}
- return readFrom(FileChannel.open(file.toPath(), StandardOpenOption.READ), charset);
+ return readFrom(channel, charset);
}
/**
* {@inheritDoc}
* <p>This implementation always throws an UnsupportedOperationException.</p>
*/
@Override
- public RandomAccessArchiveInput<A> readWithRandomAccessFrom(File file, Charset charset)
+ public RandomAccessArchiveInput<A> readWithRandomAccessFrom(SeekableByteChannel channel, Charset charset)
throws IOException, UnsupportedOperationException {
throw new UnsupportedOperationException("this format cannot doesn't support random access");
}
http://git-wip-us.apache.org/repos/asf/commons-compress/blob/699e3e2a/src/main/java/org/apache/commons/compress2/formats/ar/ArArchiveFormat.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/compress2/formats/ar/ArArchiveFormat.java b/src/main/java/org/apache/commons/compress2/formats/ar/ArArchiveFormat.java
index 6521b5c..e82536f 100644
--- a/src/main/java/org/apache/commons/compress2/formats/ar/ArArchiveFormat.java
+++ b/src/main/java/org/apache/commons/compress2/formats/ar/ArArchiveFormat.java
@@ -55,12 +55,12 @@ public class ArArchiveFormat extends AbstractArchiveFormat<ArArchiveEntry> {
* Yes.
*/
@Override
- public boolean supportsWritingToChannels() { return true; }
+ public boolean supportsWritingToNonSeekableChannels() { return true; }
/**
* Yes.
*/
@Override
- public boolean supportsReadingFromChannels() { return true; }
+ public boolean supportsReadingFromNonSeekableChannels() { return true; }
/**
* Yes.