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 16:03:28 UTC
[1/3] commons-compress git commit: unused import
Repository: commons-compress
Updated Branches:
refs/heads/compress-2.0 66a824fb5 -> 0a6d97a12
unused import
Project: http://git-wip-us.apache.org/repos/asf/commons-compress/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-compress/commit/b691d9ab
Tree: http://git-wip-us.apache.org/repos/asf/commons-compress/tree/b691d9ab
Diff: http://git-wip-us.apache.org/repos/asf/commons-compress/diff/b691d9ab
Branch: refs/heads/compress-2.0
Commit: b691d9ab575179537c57f2c7900e0cda5c8de9bb
Parents: 66a824f
Author: Stefan Bodewig <bo...@apache.org>
Authored: Sat Apr 29 17:33:07 2017 +0200
Committer: Stefan Bodewig <bo...@apache.org>
Committed: Sat Apr 29 17:33:07 2017 +0200
----------------------------------------------------------------------
.../java/org/apache/commons/compress2/archivers/ArchiveFormat.java | 1 -
1 file changed, 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/commons-compress/blob/b691d9ab/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 fe4bf72..792f2be 100644
--- a/src/main/java/org/apache/commons/compress2/archivers/ArchiveFormat.java
+++ b/src/main/java/org/apache/commons/compress2/archivers/ArchiveFormat.java
@@ -18,7 +18,6 @@
*/
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;
[2/3] commons-compress git commit: API for compressors
Posted by bo...@apache.org.
API for compressors
Project: http://git-wip-us.apache.org/repos/asf/commons-compress/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-compress/commit/822bc577
Tree: http://git-wip-us.apache.org/repos/asf/commons-compress/tree/822bc577
Diff: http://git-wip-us.apache.org/repos/asf/commons-compress/diff/822bc577
Branch: refs/heads/compress-2.0
Commit: 822bc577296236275fb0dec76eebc6a11fbb2bef
Parents: b691d9a
Author: Stefan Bodewig <bo...@apache.org>
Authored: Sat Apr 29 18:02:48 2017 +0200
Committer: Stefan Bodewig <bo...@apache.org>
Committed: Sat Apr 29 18:02:48 2017 +0200
----------------------------------------------------------------------
.../compress2/compressors/CompressedInput.java | 41 +++++++++++
.../compress2/compressors/CompressedOutput.java | 51 ++++++++++++++
.../compressors/CompressionFormat.java | 71 ++++++++++++++++++++
.../spi/AbstractCompressedInput.java | 56 +++++++++++++++
.../spi/AbstractCompressedOutput.java | 45 +++++++++++++
.../spi/AbstractCompressionFormat.java | 71 ++++++++++++++++++++
6 files changed, 335 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/commons-compress/blob/822bc577/src/main/java/org/apache/commons/compress2/compressors/CompressedInput.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/compress2/compressors/CompressedInput.java b/src/main/java/org/apache/commons/compress2/compressors/CompressedInput.java
new file mode 100644
index 0000000..00a87e2
--- /dev/null
+++ b/src/main/java/org/apache/commons/compress2/compressors/CompressedInput.java
@@ -0,0 +1,41 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.commons.compress2.compressors;
+
+import java.io.IOException;
+import java.nio.channels.ReadableByteChannel;
+
+/**
+ * Reads compressed channels.
+ * @NotThreadSafe
+ */
+public interface CompressedInput extends AutoCloseable {
+
+ /**
+ * Obtains the next compressed channel.
+ * @return the next channel or null if the end of the input has been reached.
+ */
+ ReadableByteChannel next() throws IOException;
+
+ /**
+ * Returns the current number of bytes read from this input.
+ * @return the number of read bytes
+ */
+ long getBytesRead();
+}
http://git-wip-us.apache.org/repos/asf/commons-compress/blob/822bc577/src/main/java/org/apache/commons/compress2/compressors/CompressedOutput.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/compress2/compressors/CompressedOutput.java b/src/main/java/org/apache/commons/compress2/compressors/CompressedOutput.java
new file mode 100644
index 0000000..98430e6
--- /dev/null
+++ b/src/main/java/org/apache/commons/compress2/compressors/CompressedOutput.java
@@ -0,0 +1,51 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.commons.compress2.compressors;
+
+import java.io.IOException;
+import java.nio.channels.WritableByteChannel;
+
+public interface CompressedOutput extends AutoCloseable {
+
+ /**
+ * Prepares for writing a new compressed channel.
+ *
+ * <p>The caller must then write the content to the channel and
+ * close it to complete the process.</p>
+ *
+ * @return a channel to write the content to be compressed to
+ * @throws IOException
+ */
+ WritableByteChannel startCompressing() throws IOException;
+
+ /**
+ * Finishes the addition of compressed channels to this output, without closing it.
+ *
+ * <p>Additional data can be written, if the format supports it.<p>
+ *
+ * @throws IOException
+ */
+ default void finish() throws IOException { }
+
+ /**
+ * Returns the current number of bytes written to this output.
+ * @return the number of written bytes
+ */
+ long getBytesWritten();
+}
http://git-wip-us.apache.org/repos/asf/commons-compress/blob/822bc577/src/main/java/org/apache/commons/compress2/compressors/CompressionFormat.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/compress2/compressors/CompressionFormat.java b/src/main/java/org/apache/commons/compress2/compressors/CompressionFormat.java
new file mode 100644
index 0000000..ce0e0e6
--- /dev/null
+++ b/src/main/java/org/apache/commons/compress2/compressors/CompressionFormat.java
@@ -0,0 +1,71 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.commons.compress2.compressors;
+
+import java.nio.channels.FileChannel;
+import java.nio.channels.ReadableByteChannel;
+import java.nio.channels.WritableByteChannel;
+import java.nio.file.Path;
+import java.nio.file.StandardOpenOption;
+import java.io.IOException;
+import org.apache.commons.compress2.Format;
+
+/**
+ * Describes a given compression format and works as factory and content-probe at the same time.
+ * @Immutable
+ */
+public interface CompressionFormat extends Format {
+
+ /**
+ * Reads a compressed channel.
+ * @param channel the channel to read from
+ * @throws IOException
+ */
+ CompressedInput readFrom(ReadableByteChannel channel) throws IOException;
+
+ /**
+ * Reads a compressed file.
+ * @param file the file to read from
+ * @throws IOException
+ */
+ default CompressedInput readFrom(Path path) throws IOException {
+ return readFrom(FileChannel.open(path, StandardOpenOption.READ));
+ }
+
+ /**
+ * Compresses data to a given channel.
+ * @param channel the channel to write to
+ * @throws IOException
+ * @throws UnsupportedOperationException if this format doesn't
+ * support writing.
+ */
+ CompressedOutput writeTo(WritableByteChannel channel)
+ throws IOException, UnsupportedOperationException;
+
+ /**
+ * Compresses data to a given file.
+ * @param file the file to write to
+ * @throws IOException
+ * @throws UnsupportedOperationException if this format doesn't support writing
+ */
+ default CompressedOutput writeTo(Path path) throws IOException, UnsupportedOperationException {
+ return writeTo(FileChannel.open(path, StandardOpenOption.WRITE, StandardOpenOption.CREATE,
+ StandardOpenOption.TRUNCATE_EXISTING));
+ }
+}
http://git-wip-us.apache.org/repos/asf/commons-compress/blob/822bc577/src/main/java/org/apache/commons/compress2/compressors/spi/AbstractCompressedInput.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/compress2/compressors/spi/AbstractCompressedInput.java b/src/main/java/org/apache/commons/compress2/compressors/spi/AbstractCompressedInput.java
new file mode 100644
index 0000000..667f23e
--- /dev/null
+++ b/src/main/java/org/apache/commons/compress2/compressors/spi/AbstractCompressedInput.java
@@ -0,0 +1,56 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.commons.compress2.compressors.spi;
+
+import org.apache.commons.compress2.compressors.CompressedInput;
+
+/**
+ * Base class implementations may use.
+ * @NotThreadSafe
+ */
+public abstract class AbstractCompressedInput implements CompressedInput {
+ /** holds the number of bytes read from this channel */
+ private long bytesRead = 0;
+
+ @Override
+ public long getBytesRead() {
+ return bytesRead;
+ }
+
+ /**
+ * Increments the counter of already read bytes.
+ * Doesn't increment if the EOF has been hit (read == -1)
+ *
+ * @param read the number of bytes read
+ */
+ protected void count(long read) {
+ if (read != -1) {
+ bytesRead = bytesRead + read;
+ }
+ }
+
+ /**
+ * Decrements the counter of already read bytes.
+ *
+ * @param pushedBack the number of bytes pushed back.
+ */
+ protected void pushedBackBytes(long pushedBack) {
+ bytesRead -= pushedBack;
+ }
+}
http://git-wip-us.apache.org/repos/asf/commons-compress/blob/822bc577/src/main/java/org/apache/commons/compress2/compressors/spi/AbstractCompressedOutput.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/compress2/compressors/spi/AbstractCompressedOutput.java b/src/main/java/org/apache/commons/compress2/compressors/spi/AbstractCompressedOutput.java
new file mode 100644
index 0000000..6376402
--- /dev/null
+++ b/src/main/java/org/apache/commons/compress2/compressors/spi/AbstractCompressedOutput.java
@@ -0,0 +1,45 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.commons.compress2.compressors.spi;
+
+import org.apache.commons.compress2.compressors.CompressedOutput;
+
+/**
+ * Base class implementations may use.
+ * @NotThreadSafe
+ */
+public abstract class AbstractCompressedOutput implements CompressedOutput {
+ /** holds the number of bytes written to this channel */
+ private long bytesWritten = 0;
+
+ @Override
+ public long getBytesWritten() {
+ return bytesWritten;
+ }
+
+ /**
+ * Increments the counter of written bytes.
+ *
+ * @param written the number of bytes written
+ */
+ protected void count(long written) {
+ bytesWritten += written;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/commons-compress/blob/822bc577/src/main/java/org/apache/commons/compress2/compressors/spi/AbstractCompressionFormat.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/compress2/compressors/spi/AbstractCompressionFormat.java b/src/main/java/org/apache/commons/compress2/compressors/spi/AbstractCompressionFormat.java
new file mode 100644
index 0000000..64526c8
--- /dev/null
+++ b/src/main/java/org/apache/commons/compress2/compressors/spi/AbstractCompressionFormat.java
@@ -0,0 +1,71 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.commons.compress2.compressors.spi;
+
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.nio.channels.WritableByteChannel;
+import org.apache.commons.compress2.compressors.CompressionFormat;
+import org.apache.commons.compress2.compressors.CompressedOutput;
+
+/**
+ * Base class implementations may use.
+ * @Immutable
+ */
+public abstract class AbstractCompressionFormat implements CompressionFormat {
+
+ /**
+ * {@inheritDoc}
+ * <p>This implementation always returns false.</p>
+ */
+ @Override
+ public boolean supportsWriting() { return false; }
+
+ /**
+ * {@inheritDoc}
+ * <p>This implementation always returns false.</p>
+ */
+ @Override
+ public boolean supportsAutoDetection() { return false; }
+ /**
+ * {@inheritDoc}
+ * <p>This implementation always throws an UnsupportedOperationException.</p>
+ */
+ @Override
+ public int getNumberOfBytesRequiredForAutodetection() throws UnsupportedOperationException {
+ throw new UnsupportedOperationException("this format doesn't support content-based detection");
+ }
+ /**
+ * {@inheritDoc}
+ * <p>This implementation always throws an UnsupportedOperationException.</p>
+ */
+ @Override
+ public boolean matches(ByteBuffer probe) throws UnsupportedOperationException {
+ throw new UnsupportedOperationException("this format doesn't support content-based detection");
+ }
+ /**
+ * {@inheritDoc}
+ * <p>This implementation always throws an UnsupportedOperationException.</p>
+ */
+ @Override
+ public CompressedOutput writeTo(WritableByteChannel channel)
+ throws IOException, UnsupportedOperationException {
+ throw new UnsupportedOperationException("this format is read-only");
+ }
+}
[3/3] commons-compress git commit: channel is ambiguos here
Posted by bo...@apache.org.
channel is ambiguos here
Project: http://git-wip-us.apache.org/repos/asf/commons-compress/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-compress/commit/0a6d97a1
Tree: http://git-wip-us.apache.org/repos/asf/commons-compress/tree/0a6d97a1
Diff: http://git-wip-us.apache.org/repos/asf/commons-compress/diff/0a6d97a1
Branch: refs/heads/compress-2.0
Commit: 0a6d97a1200eb415959131c76236e0e0cf8c66eb
Parents: 822bc57
Author: Stefan Bodewig <bo...@apache.org>
Authored: Sat Apr 29 18:03:04 2017 +0200
Committer: Stefan Bodewig <bo...@apache.org>
Committed: Sat Apr 29 18:03:04 2017 +0200
----------------------------------------------------------------------
.../org/apache/commons/compress2/archivers/ArchiveInput.java | 6 +++---
.../apache/commons/compress2/archivers/ArchiveOutput.java | 8 ++++----
2 files changed, 7 insertions(+), 7 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/commons-compress/blob/0a6d97a1/src/main/java/org/apache/commons/compress2/archivers/ArchiveInput.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/compress2/archivers/ArchiveInput.java b/src/main/java/org/apache/commons/compress2/archivers/ArchiveInput.java
index 6a6b98a..7e3d528 100644
--- a/src/main/java/org/apache/commons/compress2/archivers/ArchiveInput.java
+++ b/src/main/java/org/apache/commons/compress2/archivers/ArchiveInput.java
@@ -29,7 +29,7 @@ public interface ArchiveInput<A extends ArchiveEntry> extends AutoCloseable {
/**
* Obtains the next entry.
- * @return the next entry or null if the end of the channel has been reached.
+ * @return the next entry or null if the end of the input has been reached.
*/
A next() throws IOException;
@@ -40,7 +40,7 @@ public interface ArchiveInput<A extends ArchiveEntry> extends AutoCloseable {
ReadableByteChannel getChannel();
/**
- * Whether this channel is able to read the contents of the current entry.
+ * Whether this input is able to read the contents of the current entry.
*
* <p>Some archive formats support variants or details that are not supported (yet).</p>
*
@@ -49,7 +49,7 @@ public interface ArchiveInput<A extends ArchiveEntry> extends AutoCloseable {
boolean canReadEntryData();
/**
- * Returns the current number of bytes read from this channel.
+ * Returns the current number of bytes read from this input.
* @return the number of read bytes
*/
long getBytesRead();
http://git-wip-us.apache.org/repos/asf/commons-compress/blob/0a6d97a1/src/main/java/org/apache/commons/compress2/archivers/ArchiveOutput.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/compress2/archivers/ArchiveOutput.java b/src/main/java/org/apache/commons/compress2/archivers/ArchiveOutput.java
index 1f6e93e..a0f389e 100644
--- a/src/main/java/org/apache/commons/compress2/archivers/ArchiveOutput.java
+++ b/src/main/java/org/apache/commons/compress2/archivers/ArchiveOutput.java
@@ -35,7 +35,7 @@ public interface ArchiveOutput<A extends ArchiveEntry> extends AutoCloseable {
A createEntry(ArchiveEntryParameters params);
/**
- * Whether this channel is able to write the contents of the given entry.
+ * Whether this output is able to write the contents of the given entry.
*
* <p>Some archive formats support variants or details that are not supported (yet).</p>
*
@@ -46,7 +46,7 @@ public interface ArchiveOutput<A extends ArchiveEntry> extends AutoCloseable {
boolean canWriteEntryData(A archiveEntry);
/**
- * Initializes the channel for writing a new {@link ArchiveEntry}.
+ * Initializes the output for writing a new {@link ArchiveEntry}.
*
* <p>The caller must then write the content to the channel and call {@link #closeEntry()} to complete the
* process.</p>
@@ -64,7 +64,7 @@ public interface ArchiveOutput<A extends ArchiveEntry> extends AutoCloseable {
void closeEntry() throws IOException;
/**
- * Finishes the addition of entries to this stream, without closing it.
+ * Finishes the addition of entries to this output, without closing it.
*
* <p>Additional data can be written, if the format supports it.<p>
*
@@ -73,7 +73,7 @@ public interface ArchiveOutput<A extends ArchiveEntry> extends AutoCloseable {
void finish() throws IOException;
/**
- * Returns the current number of bytes written to this channel.
+ * Returns the current number of bytes written to this output.
* @return the number of written bytes
*/
long getBytesWritten();