commons-compress git commit: add compressors class for discovering compression formats

2017-04-29 Thread bodewig
Repository: commons-compress
Updated Branches:
  refs/heads/compress-2.0 2b31d222b -> 9caa606a8


add compressors class for discovering compression formats


Project: http://git-wip-us.apache.org/repos/asf/commons-compress/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-compress/commit/9caa606a
Tree: http://git-wip-us.apache.org/repos/asf/commons-compress/tree/9caa606a
Diff: http://git-wip-us.apache.org/repos/asf/commons-compress/diff/9caa606a

Branch: refs/heads/compress-2.0
Commit: 9caa606a8c7726b868d8c1bed7da420389191745
Parents: 2b31d22
Author: Stefan Bodewig 
Authored: Sat Apr 29 22:41:16 2017 +0200
Committer: Stefan Bodewig 
Committed: Sat Apr 29 22:41:16 2017 +0200

--
 .../commons/compress2/FormatDiscoverer.java | 117 +++
 .../commons/compress2/archivers/Archivers.java  |  88 ++
 .../compress2/compressors/Compressors.java  |  58 +
 ...mons.compress2.compressors.CompressionFormat |   1 +
 .../compress2/archivers/ArchiversTest.java  |  13 ++-
 .../compress2/compressors/CompressorsTest.java  |  64 ++
 6 files changed, 257 insertions(+), 84 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/commons-compress/blob/9caa606a/src/main/java/org/apache/commons/compress2/FormatDiscoverer.java
--
diff --git a/src/main/java/org/apache/commons/compress2/FormatDiscoverer.java 
b/src/main/java/org/apache/commons/compress2/FormatDiscoverer.java
new file mode 100644
index 000..a838012
--- /dev/null
+++ b/src/main/java/org/apache/commons/compress2/FormatDiscoverer.java
@@ -0,0 +1,117 @@
+/*
+ * 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;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.Spliterator;
+import java.util.Spliterators;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.ServiceConfigurationError;
+import java.util.ServiceLoader;
+import java.util.Set;
+import java.util.TreeSet;
+import java.util.function.Function;
+import java.util.function.Predicate;
+import java.util.stream.Collectors;
+import java.util.stream.StreamSupport;
+import org.apache.commons.compress2.Format;
+
+/**
+ * Loads formats defined as "services" and provides access to them.
+ *
+ * Uses {@link java.util.ServiceLoader} under the covers but iterates over 
all formats found eagerly inside the
+ * constructor so errors are reported early.
+ */
+public abstract class FormatDiscoverer implements 
Iterable {
+private final ServiceLoader formatLoader;
+private Map formats;
+
+/**
+ * Loads services using the given class loader.
+ * @throws ServiceConfigurationError if an error occurs reading a service 
file or instantiating a format
+ */
+protected FormatDiscoverer(ClassLoader cl, Class clazz) throws 
ServiceConfigurationError {
+this(ServiceLoader.load(clazz, cl));
+}
+
+private FormatDiscoverer(ServiceLoader loader) {
+formatLoader = loader;
+fillMap();
+}
+
+/**
+ * Clears the cached formats and rebuilds it.
+ *
+ * @see ServiceLoader#reload
+ */
+public void reload() {
+formatLoader.reload();
+fillMap();
+}
+
+/**
+ * Iterator over all known formats.
+ */
+public Iterator iterator() {
+return formats.values().iterator();
+}
+
+/**
+ * Iterates over all known formats that support writing.
+ */
+public Iterable getFormatsWithWriteSupport() {
+return filter(Format::supportsWriting);
+}
+
+/**
+ * Gets a format by its name.
+ * @param name the {@link Format#getName name} of the format.
+ * @return the Format instance if one is known by that name
+ */
+public Optional getFormatByName(String name) {
+return Optional.ofNullable(formats.get(name));
+}
+
+private void fillMap() throws ServiceConfigurationError {
+Set ts = new TreeSet(Format.AUTO_DETECTION_ORDER);
+  

commons-compress git commit: reduce duplication in tests

2017-04-29 Thread bodewig
Repository: commons-compress
Updated Branches:
  refs/heads/compress-2.0 b74e53866 -> 2b31d222b


reduce duplication in tests


Project: http://git-wip-us.apache.org/repos/asf/commons-compress/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-compress/commit/2b31d222
Tree: http://git-wip-us.apache.org/repos/asf/commons-compress/tree/2b31d222
Diff: http://git-wip-us.apache.org/repos/asf/commons-compress/diff/2b31d222

Branch: refs/heads/compress-2.0
Commit: 2b31d222b26e0e22b5d4e1f1ae613b1925992a8c
Parents: b74e538
Author: Stefan Bodewig 
Authored: Sat Apr 29 20:07:27 2017 +0200
Committer: Stefan Bodewig 
Committed: Sat Apr 29 20:07:27 2017 +0200

--
 .../apache/commons/compress2/TestSupport.java   | 96 
 .../formats/AbstractFileSystemTest.java | 40 
 .../formats/ar/ArArchiveFormatTest.java |  3 +-
 .../compress2/formats/ar/RoundTripTest.java | 88 +-
 .../deflate/DeflateCompressionFormatTest.java   |  9 +-
 .../formats/deflate/RoundTripTest.java  | 90 +-
 6 files changed, 149 insertions(+), 177 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/commons-compress/blob/2b31d222/src/test/java/org/apache/commons/compress2/TestSupport.java
--
diff --git a/src/test/java/org/apache/commons/compress2/TestSupport.java 
b/src/test/java/org/apache/commons/compress2/TestSupport.java
new file mode 100644
index 000..22e0c62
--- /dev/null
+++ b/src/test/java/org/apache/commons/compress2/TestSupport.java
@@ -0,0 +1,96 @@
+/*
+ * 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;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.net.URI;
+import java.net.URL;
+import java.util.Locale;
+
+public class TestSupport {
+public static File mkdir(String name) throws IOException {
+File f = File.createTempFile(name, "");
+f.delete();
+f.mkdir();
+return f;
+}
+
+public static File getFile(String path) throws IOException {
+URL url = TestSupport.class.getClassLoader().getResource(path);
+if (url == null) {
+throw new FileNotFoundException("couldn't find " + path);
+}
+URI uri = null;
+try {
+uri = url.toURI();
+} catch (java.net.URISyntaxException ex) {
+throw new IOException(ex);
+}
+return new File(uri);
+}
+
+public static void rmdir(File f) {
+String[] s = f.list();
+if (s != null) {
+for (String element : s) {
+final File file = new File(f, element);
+if (file.isDirectory()){
+rmdir(file);
+}
+boolean ok = tryHardToDelete(file);
+if (!ok && file.exists()){
+System.out.println("Failed to delete "+element+" in 
"+f.getPath());
+}
+}
+}
+tryHardToDelete(f); // safer to delete and check
+if (f.exists()){
+throw new Error("Failed to delete "+f.getPath());
+}
+}
+
+private static final boolean ON_WINDOWS =
+System.getProperty("os.name").toLowerCase(Locale.ENGLISH)
+.indexOf("windows") > -1;
+
+/**
+ * Accommodate Windows bug encountered in both Sun and IBM JDKs.
+ * Others possible. If the delete does not work, call System.gc(),
+ * wait a little and try again.
+ *
+ * @return whether deletion was successful
+ * @since Stolen from FileUtils in Ant 1.8.0
+ */
+public static boolean tryHardToDelete(File f) {
+if (f != null && f.exists() && !f.delete()) {
+if (ON_WINDOWS) {
+System.gc();
+}
+try {
+Thread.sleep(10);
+} catch (InterruptedException ex) {
+// Ignore Exception
+}
+return f.delete();
+}
+return true;
+}
+}

ht

[2/2] commons-compress git commit: add DEFLATE as compression format to play with

2017-04-29 Thread bodewig
add DEFLATE as compression format to play with


Project: http://git-wip-us.apache.org/repos/asf/commons-compress/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-compress/commit/b74e5386
Tree: http://git-wip-us.apache.org/repos/asf/commons-compress/tree/b74e5386
Diff: http://git-wip-us.apache.org/repos/asf/commons-compress/diff/b74e5386

Branch: refs/heads/compress-2.0
Commit: b74e53866767f2323af1ac09681bf80318fe2c49
Parents: 27686ef
Author: Stefan Bodewig 
Authored: Sat Apr 29 19:54:35 2017 +0200
Committer: Stefan Bodewig 
Committed: Sat Apr 29 19:54:35 2017 +0200

--
 .../formats/deflate/DeflateCompressedInput.java |  92 +
 .../deflate/DeflateCompressedOutput.java|  87 +
 .../deflate/DeflateCompressionFormat.java   |  89 +
 .../deflate/DeflateCompressionFormatTest.java   |  53 ++
 .../formats/deflate/RoundTripTest.java  | 185 +++
 .../test-archives/default.tar.deflatez  | Bin 0 -> 468 bytes
 6 files changed, 506 insertions(+)
--


http://git-wip-us.apache.org/repos/asf/commons-compress/blob/b74e5386/src/main/java/org/apache/commons/compress2/formats/deflate/DeflateCompressedInput.java
--
diff --git 
a/src/main/java/org/apache/commons/compress2/formats/deflate/DeflateCompressedInput.java
 
b/src/main/java/org/apache/commons/compress2/formats/deflate/DeflateCompressedInput.java
new file mode 100644
index 000..a7d9977
--- /dev/null
+++ 
b/src/main/java/org/apache/commons/compress2/formats/deflate/DeflateCompressedInput.java
@@ -0,0 +1,92 @@
+/*
+ * 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.formats.deflate;
+
+import java.io.FilterInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.channels.Channels;
+import java.nio.channels.ReadableByteChannel;
+import java.util.zip.Inflater;
+import java.util.zip.InflaterInputStream;
+import org.apache.commons.compress2.compressors.spi.AbstractCompressedInput;
+
+/**
+ * Input for DEFLATE compressed channels.
+ */
+public class DeflateCompressedInput extends AbstractCompressedInput {
+private final InputStream in;
+private final Inflater inflater;
+private boolean nextCalled = false;
+
+public DeflateCompressedInput(ReadableByteChannel channel) {
+in = Channels.newInputStream(channel);
+inflater = new Inflater(false);
+}
+
+@Override
+public ReadableByteChannel next() throws IOException {
+if (nextCalled) {
+return null;
+}
+nextCalled = true;
+return Channels.newChannel(new InflaterInputStream(new 
WrappedStream(in), inflater));
+}
+
+@Override
+public void close() throws IOException {
+try {
+in.close();
+} finally {
+inflater.end();
+}
+}
+
+private class WrappedStream extends FilterInputStream  {
+private WrappedStream(InputStream i) {
+super(i);
+}
+
+@Override
+public void close() {
+inflater.reset();
+}
+
+@Override
+public int read() throws IOException {
+int r = super.read();
+count(r < 0 ? 0 : 1);
+return r;
+}
+
+@Override
+public int read(byte[] b, int off, int len) throws IOException {
+int r = super.read(b, off, len);
+count(r);
+return r;
+}
+
+@Override
+public long skip(long n) throws IOException {
+long r = super.skip(n);
+count(r);
+return r;
+}
+}
+}

http://git-wip-us.apache.org/repos/asf/commons-compress/blob/b74e5386/src/main/java/org/apache/commons/compress2/formats/deflate/DeflateCompressedOutput.java
--
diff --git 
a/src/main/java/org/apache/commons/compress2/formats/deflate/DeflateCompressedOutput.java
 
b/src/main/java/org/apache/commons/compress2/formats/deflate/

[1/2] commons-compress git commit: move IOUtils

2017-04-29 Thread bodewig
Repository: commons-compress
Updated Branches:
  refs/heads/compress-2.0 0a6d97a12 -> b74e53866


move IOUtils


Project: http://git-wip-us.apache.org/repos/asf/commons-compress/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-compress/commit/27686efc
Tree: http://git-wip-us.apache.org/repos/asf/commons-compress/tree/27686efc
Diff: http://git-wip-us.apache.org/repos/asf/commons-compress/diff/27686efc

Branch: refs/heads/compress-2.0
Commit: 27686efc56d4d10bc110443955da5d80ffb5a8b2
Parents: 0a6d97a
Author: Stefan Bodewig 
Authored: Sat Apr 29 19:49:20 2017 +0200
Committer: Stefan Bodewig 
Committed: Sat Apr 29 19:49:20 2017 +0200

--
 .../compress2/formats/ar/ArArchiveInput.java|   1 +
 .../commons/compress2/formats/ar/IOUtils.java   | 204 ---
 .../apache/commons/compress2/util/IOUtils.java  | 203 ++
 .../formats/ar/ArArchiveFormatTest.java |   2 +-
 .../compress2/formats/ar/RoundTripTest.java |   1 +
 5 files changed, 206 insertions(+), 205 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/commons-compress/blob/27686efc/src/main/java/org/apache/commons/compress2/formats/ar/ArArchiveInput.java
--
diff --git 
a/src/main/java/org/apache/commons/compress2/formats/ar/ArArchiveInput.java 
b/src/main/java/org/apache/commons/compress2/formats/ar/ArArchiveInput.java
index 8a62f8a..f39efec 100644
--- a/src/main/java/org/apache/commons/compress2/formats/ar/ArArchiveInput.java
+++ b/src/main/java/org/apache/commons/compress2/formats/ar/ArArchiveInput.java
@@ -31,6 +31,7 @@ import java.nio.file.attribute.FileTime;
 import org.apache.commons.compress2.archivers.ArchiveEntryParameters;
 import org.apache.commons.compress2.archivers.OwnerInformation;
 import org.apache.commons.compress2.archivers.spi.AbstractArchiveInput;
+import org.apache.commons.compress2.util.IOUtils;
 
 /**
  * Implements the "ar" archive format.

http://git-wip-us.apache.org/repos/asf/commons-compress/blob/27686efc/src/main/java/org/apache/commons/compress2/formats/ar/IOUtils.java
--
diff --git a/src/main/java/org/apache/commons/compress2/formats/ar/IOUtils.java 
b/src/main/java/org/apache/commons/compress2/formats/ar/IOUtils.java
deleted file mode 100644
index a7a429e..000
--- a/src/main/java/org/apache/commons/compress2/formats/ar/IOUtils.java
+++ /dev/null
@@ -1,204 +0,0 @@
-/*
- * 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.formats.ar;
-
-import java.io.ByteArrayOutputStream;
-import java.io.Closeable;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.nio.ByteBuffer;
-import java.nio.channels.ReadableByteChannel;
-import java.nio.channels.WritableByteChannel;
-
-/**
- * THIS CLASS WILL CERTAINLY NOT STAY HERE.
- * @Immutable
- */
-final class IOUtils {
-
-/** Private constructor to prevent instantiation of this utility class. */
-private IOUtils(){
-}
-
-/**
- * Copies the content of a InputStream into an OutputStream.
- * Uses a default buffer size of 8024 bytes.
- *
- * @param input
- *the InputStream to copy
- * @param output
- *the target Stream
- * @throws IOException
- * if an error occurs
- */
-public static long copy(final InputStream input, final OutputStream 
output) throws IOException {
-return copy(input, output, 8024);
-}
-
-/**
- * Copies the content of a InputStream into an OutputStream
- *
- * @param input
- *the InputStream to copy
- * @param output
- *the target Stream
- * @param buffersize
- *the buffer size to use
- * @throws IOException
- * if an error occurs
- */
-public static long copy(final InputStream input, final OutputStream 
output, int buffersize) throws IOException {
-final byte[] buffer = new byte[buffersize];
-int

[2/3] commons-compress git commit: API for compressors

2017-04-29 Thread bodewig
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 
Authored: Sat Apr 29 18:02:48 2017 +0200
Committer: Stefan Bodewig 
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 000..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 000..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.
+ *
+ * The caller must then write the content to the channel and
+ * close it to complete the process.
+ *
+ * @return a channel to write the content to be compressed to
+ * @throws IOException
+ */
+Wr

[3/3] commons-compress git commit: channel is ambiguos here

2017-04-29 Thread bodewig
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 
Authored: Sat Apr 29 18:03:04 2017 +0200
Committer: Stefan Bodewig 
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 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 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.
  * 
  * Some archive formats support variants or details that are not 
supported (yet).
  * 
@@ -49,7 +49,7 @@ public interface ArchiveInput 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 
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.
  *
  * Some archive formats support variants or details that are not 
supported (yet).
  *
@@ -46,7 +46,7 @@ public interface ArchiveOutput 
extends AutoCloseable {
 boolean canWriteEntryData(A archiveEntry);
 
 /**
- * Initializes the channel for writing a new {@link ArchiveEntry}.
+ * Initializes the output for writing a new {@link ArchiveEntry}.
  *
  * The caller must then write the content to the channel and call 
{@link #closeEntry()} to complete the
  * process.
@@ -64,7 +64,7 @@ public interface ArchiveOutput 
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.
  *
  * Additional data can be written, if the format supports it.
  * 
@@ -73,7 +73,7 @@ public interface ArchiveOutput 
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();



[1/3] commons-compress git commit: unused import

2017-04-29 Thread bodewig
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 
Authored: Sat Apr 29 17:33:07 2017 +0200
Committer: Stefan Bodewig 
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;



commons-compress git commit: extract common meta-data of archivers and compressors

2017-04-29 Thread bodewig
Repository: commons-compress
Updated Branches:
  refs/heads/compress-2.0 8d714b44d -> 66a824fb5


extract common meta-data of archivers and 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/66a824fb
Tree: http://git-wip-us.apache.org/repos/asf/commons-compress/tree/66a824fb
Diff: http://git-wip-us.apache.org/repos/asf/commons-compress/diff/66a824fb

Branch: refs/heads/compress-2.0
Commit: 66a824fb5793e022ef92e2f899f528f078bfe01b
Parents: 8d714b4
Author: Stefan Bodewig 
Authored: Sat Apr 29 17:28:12 2017 +0200
Committer: Stefan Bodewig 
Committed: Sat Apr 29 17:28:12 2017 +0200

--
 .../org/apache/commons/compress2/Format.java| 81 
 .../compress2/archivers/ArchiveFormat.java  | 34 +---
 .../commons/compress2/archivers/Archivers.java  | 16 +---
 3 files changed, 85 insertions(+), 46 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/commons-compress/blob/66a824fb/src/main/java/org/apache/commons/compress2/Format.java
--
diff --git a/src/main/java/org/apache/commons/compress2/Format.java 
b/src/main/java/org/apache/commons/compress2/Format.java
new file mode 100644
index 000..62b18c1
--- /dev/null
+++ b/src/main/java/org/apache/commons/compress2/Format.java
@@ -0,0 +1,81 @@
+/*
+ * 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;
+
+import java.nio.ByteBuffer;
+import java.util.Comparator;
+
+/**
+ * Common meta-data for archive and compression formats.
+ */
+public interface Format {
+/**
+ * The name by which this format is known.
+ * @return the name by which this format is known
+ */
+String getName();
+
+/**
+ * Does the format support writing?
+ * @return whether writing is supported
+ */
+boolean supportsWriting();
+
+/**
+ * Does the format support content-based detection?
+ * @return whether the format supports content-based detection.
+ */
+boolean supportsAutoDetection();
+/**
+ * If this format supports content-based detection, how many bytes does it 
need to read to know a channel is
+ * readable by this format?
+ * @return the minimal number of bytes needed
+ * @throws UnsupportedOperationException if this format doesn't support 
content based detection.
+ */
+int getNumberOfBytesRequiredForAutodetection() throws 
UnsupportedOperationException;
+/**
+ * Verifies the given input is readable by this format.
+ * @param probe a buffer holding at least {@link 
#getNumberOfBytesRequiredForAutodetection} bytes
+ * @return whether the input is readable by this format
+ * @throws UnsupportedOperationException if this format doesn't support 
content based detection.
+ */
+boolean matches(ByteBuffer probe) throws UnsupportedOperationException;
+
+/**
+ * Comparator that sorts {@link Format}s in ascending order of number of 
bytes required for aut-detection.
+ *
+ * Formats that don't support auto-detection at all are sorted last.
+ */
+public static final Comparator AUTO_DETECTION_ORDER = new 
Comparator() {
+@Override
+public int compare(Format f1, Format f2) {
+if (f1.supportsAutoDetection() && f2.supportsAutoDetection()) {
+return f1.getNumberOfBytesRequiredForAutodetection() - 
f2.getNumberOfBytesRequiredForAutodetection();
+}
+if (!f1.supportsAutoDetection() && !f2.supportsAutoDetection()) {
+return 0;
+}
+if (f1.supportsAutoDetection()) {
+return -1;
+}
+return 1;
+}
+};
+
+}

http://git-wip-us.apache.org/repos/asf/commons-compress/blob/66a824fb/src/main/java/org/apache/commons/compress2/archivers/ArchiveFormat.java
--
diff --git 
a/src/main/java/org/apache/commons/compress2/archivers/ArchiveFormat.java 

commons-compress git commit: javadoc

2017-04-29 Thread bodewig
Repository: commons-compress
Updated Branches:
  refs/heads/compress-2.0 e36fcf9af -> 8d714b44d


javadoc


Project: http://git-wip-us.apache.org/repos/asf/commons-compress/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-compress/commit/8d714b44
Tree: http://git-wip-us.apache.org/repos/asf/commons-compress/tree/8d714b44
Diff: http://git-wip-us.apache.org/repos/asf/commons-compress/diff/8d714b44

Branch: refs/heads/compress-2.0
Commit: 8d714b44d8336c502831c83d183cbcc058d93a32
Parents: e36fcf9
Author: Stefan Bodewig 
Authored: Sat Apr 29 16:48:23 2017 +0200
Committer: Stefan Bodewig 
Committed: Sat Apr 29 16:48:23 2017 +0200

--
 .../commons/compress2/archivers/ArchiveEntryParameters.java  | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
--


http://git-wip-us.apache.org/repos/asf/commons-compress/blob/8d714b44/src/main/java/org/apache/commons/compress2/archivers/ArchiveEntryParameters.java
--
diff --git 
a/src/main/java/org/apache/commons/compress2/archivers/ArchiveEntryParameters.java
 
b/src/main/java/org/apache/commons/compress2/archivers/ArchiveEntryParameters.java
index fb2c144..fe8c8a6 100644
--- 
a/src/main/java/org/apache/commons/compress2/archivers/ArchiveEntryParameters.java
+++ 
b/src/main/java/org/apache/commons/compress2/archivers/ArchiveEntryParameters.java
@@ -310,7 +310,7 @@ public class ArchiveEntryParameters implements ArchiveEntry 
{
 
 /**
  * Translates a set of permissons into a Unix stat(2) {@code st_mode} 
result
- * @param permissions the permissions
+ * @param permissions the permissions.
  * @param type the file type
  * @return the "mode"
  */
@@ -343,6 +343,8 @@ public class ArchiveEntryParameters implements ArchiveEntry 
{
 
 /**
  * Translates a Unix stat(2) {@code st_mode} compatible value into a set 
of permissions.
+ * @param mode the "mode"
+ * @return set of permissions
  */
 public static Set permissionsFromMode(long mode) {
 Set permissions = 
EnumSet.noneOf(PosixFilePermission.class);



commons-compress git commit: provide default implementation in ArchiveFormat interface

2017-04-29 Thread bodewig
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 
Authored: Sat Apr 29 16:41:55 2017 +0200
Committer: Stefan Bodewig 
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 {
  * @param charset the charset used for encoding the entry names.
  * @throws IOException
  */
-ArchiveInput readFrom(Path path, Charset charset) throws IOException;
+default ArchiveInput 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 {
  * @throws IOException
  * @throws UnsupportedOperationException if this format doesn't support 
writing
  */
-ArchiveOutput writeTo(Path path, Charset charset) throws IOException, 
UnsupportedOperationException;
+default ArchiveOutput 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 implements A
 }
 /**
  * {@inheritDoc}
- * This implementation delegates to {@link #readWithRandomAccessFrom} 
if random access is supported or {@link
- * #readFrom(ReadableByteChannel, Charset)} otherwise.
- */
-@Override
-public ArchiveInput readFrom(Path path, Charset charset) throws 
IOException {
-SeekableByteChannel channel = FileChannel.open(path, 
StandardOpenOption.READ);
-

commons-compress git commit: COMPRESS-382 COMPRESS-386 document new maxmemory setting

2017-04-29 Thread bodewig
Repository: commons-compress
Updated Branches:
  refs/heads/master 508be17bb -> 6dc03d613


COMPRESS-382 COMPRESS-386 document new maxmemory setting


Project: http://git-wip-us.apache.org/repos/asf/commons-compress/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-compress/commit/6dc03d61
Tree: http://git-wip-us.apache.org/repos/asf/commons-compress/tree/6dc03d61
Diff: http://git-wip-us.apache.org/repos/asf/commons-compress/diff/6dc03d61

Branch: refs/heads/master
Commit: 6dc03d613c3620b78f544fa4a7c349b16b190354
Parents: 508be17
Author: Stefan Bodewig 
Authored: Sat Apr 29 16:22:15 2017 +0200
Committer: Stefan Bodewig 
Committed: Sat Apr 29 16:22:15 2017 +0200

--
 src/site/xdoc/examples.xml | 12 
 1 file changed, 12 insertions(+)
--


http://git-wip-us.apache.org/repos/asf/commons-compress/blob/6dc03d61/src/site/xdoc/examples.xml
--
diff --git a/src/site/xdoc/examples.xml b/src/site/xdoc/examples.xml
index 4d928a8..16eb2a2 100644
--- a/src/site/xdoc/examples.xml
+++ b/src/site/xdoc/examples.xml
@@ -115,6 +115,18 @@ CompressorInputStream input = new CompressorStreamFactory()
 enable the support.
   
 
+  
+Starting with Compress 1.14
+CompressorStreamFactory has an optional
+constructor argument that can be used to set an upper limit of
+memory that may be used while decompressing or compressing a
+stream. As of 1.14 this setting only affects decompressing Z,
+XZ and LZMA compressed streams.
+For the Snappy and LZ4 formats the amount of memory used
+during compression is directly proportional to the window
+size.
+  
+
   
 
 In addition to the information stored



[lang] HashSetvBitSetTest: use diamond operator (closes #264)

2017-04-29 Thread pascalschumacher
Repository: commons-lang
Updated Branches:
  refs/heads/master d61090ab6 -> c8e648b92


HashSetvBitSetTest: use diamond operator (closes #264)

Use Java 7's diamond operator to make the code a tad more elegant, as
done in the rest of the codebase.


Project: http://git-wip-us.apache.org/repos/asf/commons-lang/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-lang/commit/c8e648b9
Tree: http://git-wip-us.apache.org/repos/asf/commons-lang/tree/c8e648b9
Diff: http://git-wip-us.apache.org/repos/asf/commons-lang/diff/c8e648b9

Branch: refs/heads/master
Commit: c8e648b92cc133a604b5e1f4da1ced943788e64b
Parents: d61090a
Author: Allon Mureinik 
Authored: Sat Apr 29 10:37:40 2017 +0300
Committer: pascalschumacher 
Committed: Sat Apr 29 10:48:41 2017 +0200

--
 src/test/java/org/apache/commons/lang3/HashSetvBitSetTest.java | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
--


http://git-wip-us.apache.org/repos/asf/commons-lang/blob/c8e648b9/src/test/java/org/apache/commons/lang3/HashSetvBitSetTest.java
--
diff --git a/src/test/java/org/apache/commons/lang3/HashSetvBitSetTest.java 
b/src/test/java/org/apache/commons/lang3/HashSetvBitSetTest.java
index cafb298..97fe714 100644
--- a/src/test/java/org/apache/commons/lang3/HashSetvBitSetTest.java
+++ b/src/test/java/org/apache/commons/lang3/HashSetvBitSetTest.java
@@ -39,7 +39,7 @@ public class HashSetvBitSetTest {
 
 @Benchmark
 public int[] testHashSet() {
-final HashSet toRemove = new HashSet();
+final HashSet toRemove = new HashSet<>();
 int found = 0;
 for (int i = 0; i < numberOfElementsToCompute; i++) {
 toRemove.add(found++);