You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2020/09/23 14:13:44 UTC

[commons-vfs] branch master updated (3634df2 -> e7e47f8)

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

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


    from 3634df2  Use a table to present Java requirements per VFS version.
     new b4f33a5  Sort members.
     new 676451b  Remove URISyntaxException from private method. This commits simply changes the private method signature but not the public one in this class for source compatibility, which lets the compiler tell us that other methods now uselessly throw URISyntaxException.
     new e7e47f8  Drop some unused exceptions from throws clauses (this does not break binary compatibility).

The 3 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:
 .../vfs2/provider/webdav4/Webdav4FileObject.java   |   7 +-
 .../webdav4/test/Webdav4ProviderTestCase.java      |   6 +-
 .../commons/vfs2/provider/GenericURLFileName.java  |   6 +-
 .../vfs2/provider/http4/Http4FileObject.java       |   6 +-
 .../vfs2/provider/http5/Http5FileObject.java       |   6 +-
 .../org/apache/commons/vfs2/util/URIUtils.java     | 183 ++++++++++-----------
 6 files changed, 100 insertions(+), 114 deletions(-)


[commons-vfs] 01/03: Sort members.

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

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

commit b4f33a5f877afe3c9a7086141501aec610153c89
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Wed Sep 23 09:49:07 2020 -0400

    Sort members.
---
 .../org/apache/commons/vfs2/util/URIUtils.java     | 186 ++++++++++-----------
 1 file changed, 93 insertions(+), 93 deletions(-)

diff --git a/commons-vfs2/src/main/java/org/apache/commons/vfs2/util/URIUtils.java b/commons-vfs2/src/main/java/org/apache/commons/vfs2/util/URIUtils.java
index 3a80a29..8b05bf6 100644
--- a/commons-vfs2/src/main/java/org/apache/commons/vfs2/util/URIUtils.java
+++ b/commons-vfs2/src/main/java/org/apache/commons/vfs2/util/URIUtils.java
@@ -35,50 +35,66 @@ import org.apache.commons.vfs2.provider.GenericURLFileName;
  */
 public class URIUtils {
 
-    private static final Log LOG = LogFactory.getLog(URIUtils.class);
-
     /**
-     * The default charset of the protocol.  RFC 2277, 2396
+     * Internal character encoding utilities.
+     * <p>
+     * This was forked from some needed methods such as {@code #getBytes(...)} and {@code #getAsciiString(...)}
+     * in {@code org.apache.commons.httpclient.util.EncodingUtil},
+     * in order to not be dependent on HttpClient v3 API, when generating and handling {@link GenericURLFileName}s,
+     * but it should work with any different HTTP backend provider implementations.
+     * </p>
      */
-    private static final String DEFAULT_PROTOCOL_CHARSET = "UTF-8";
+    private static class EncodingUtils {
 
-    private URIUtils() {
-    }
+        /**
+         * Converts the byte array of ASCII characters to a string. This method is
+         * to be used when decoding content of HTTP elements (such as response
+         * headers)
+         *
+         * @param data the byte array to be encoded
+         * @param offset the index of the first byte to encode
+         * @param length the number of bytes to encode
+         * @return The string representation of the byte array
+         */
+        static String getAsciiString(final byte[] data, final int offset, final int length) {
+            try {
+                return new String(data, offset, length, "US-ASCII");
+            } catch (final UnsupportedEncodingException e) {
+                throw new RuntimeException("US-ASCII charset is not supported.");
+            }
+        }
 
-    /**
-     * Escape and encode a string regarded as the path component of an URI with
-     * the default protocol charset.
-     *
-     * @param unescaped an unescaped string
-     * @return the escaped string
-     *
-     * @throws URISyntaxException if the default protocol charset is not supported
-     */
-    public static String encodePath(final String unescaped) throws URISyntaxException {
-        return encodePath(unescaped, DEFAULT_PROTOCOL_CHARSET);
-    }
+        /**
+         * Converts the specified string to a byte array.  If the charset is not supported the
+         * default system charset is used.
+         *
+         * @param data the string to be encoded
+         * @param charset the desired character encoding
+         * @return The resulting byte array.
+         */
+        static byte[] getBytes(final String data, final String charset) {
+            if (data == null) {
+                throw new IllegalArgumentException("data may not be null");
+            }
 
-    /**
-     * Escape and encode a string regarded as the path component of an URI with
-     * a given charset.
-     *
-     * @param unescaped an unescaped string
-     * @param charset the charset
-     * @return the escaped string
-     *
-     * @throws URISyntaxException if the charset is not supported
-     */
-    public static String encodePath(final String unescaped, final String charset) throws URISyntaxException {
-        if (unescaped == null) {
-            throw new IllegalArgumentException("The string to encode may not be null.");
-        }
+            if (charset == null || charset.length() == 0) {
+                throw new IllegalArgumentException("charset may not be null or empty");
+            }
 
-        return encode(unescaped, URIBitSets.allowed_abs_path, charset);
-    }
+            try {
+                return data.getBytes(charset);
+            } catch (final UnsupportedEncodingException e) {
 
-    private static String encode(final String unescaped, final BitSet allowed, final String charset) throws URISyntaxException {
-        final byte[] rawdata = URLCodecUtils.encodeUrl(allowed, EncodingUtils.getBytes(unescaped, charset));
-        return EncodingUtils.getAsciiString(rawdata, 0, rawdata.length);
+                if (LOG.isWarnEnabled()) {
+                    LOG.warn("Unsupported encoding: " + charset + ". System encoding used.");
+                }
+
+                return data.getBytes();
+            }
+        }
+
+        private EncodingUtils() {
+        }
     }
 
     /**
@@ -122,9 +138,6 @@ public class URIUtils {
          */
         private static final int RADIX = 16;
 
-        private URLCodecUtils() {
-        }
-
         static final byte[] encodeUrl(BitSet urlsafe, final byte[] bytes) {
             if (bytes == null) {
                 return null;
@@ -158,68 +171,55 @@ public class URIUtils {
         private static char hexDigit(final int b) {
             return Character.toUpperCase(Character.forDigit(b & 0xF, RADIX));
         }
-    }
-
-    /**
-     * Internal character encoding utilities.
-     * <p>
-     * This was forked from some needed methods such as {@code #getBytes(...)} and {@code #getAsciiString(...)}
-     * in {@code org.apache.commons.httpclient.util.EncodingUtil},
-     * in order to not be dependent on HttpClient v3 API, when generating and handling {@link GenericURLFileName}s,
-     * but it should work with any different HTTP backend provider implementations.
-     * </p>
-     */
-    private static class EncodingUtils {
 
-        private EncodingUtils() {
+        private URLCodecUtils() {
         }
+    }
 
-        /**
-         * Converts the specified string to a byte array.  If the charset is not supported the
-         * default system charset is used.
-         *
-         * @param data the string to be encoded
-         * @param charset the desired character encoding
-         * @return The resulting byte array.
-         */
-        static byte[] getBytes(final String data, final String charset) {
-            if (data == null) {
-                throw new IllegalArgumentException("data may not be null");
-            }
+    private static final Log LOG = LogFactory.getLog(URIUtils.class);
 
-            if (charset == null || charset.length() == 0) {
-                throw new IllegalArgumentException("charset may not be null or empty");
-            }
+    /**
+     * The default charset of the protocol.  RFC 2277, 2396
+     */
+    private static final String DEFAULT_PROTOCOL_CHARSET = "UTF-8";
 
-            try {
-                return data.getBytes(charset);
-            } catch (final UnsupportedEncodingException e) {
+    private static String encode(final String unescaped, final BitSet allowed, final String charset) throws URISyntaxException {
+        final byte[] rawdata = URLCodecUtils.encodeUrl(allowed, EncodingUtils.getBytes(unescaped, charset));
+        return EncodingUtils.getAsciiString(rawdata, 0, rawdata.length);
+    }
 
-                if (LOG.isWarnEnabled()) {
-                    LOG.warn("Unsupported encoding: " + charset + ". System encoding used.");
-                }
+    /**
+     * Escape and encode a string regarded as the path component of an URI with
+     * the default protocol charset.
+     *
+     * @param unescaped an unescaped string
+     * @return the escaped string
+     *
+     * @throws URISyntaxException if the default protocol charset is not supported
+     */
+    public static String encodePath(final String unescaped) throws URISyntaxException {
+        return encodePath(unescaped, DEFAULT_PROTOCOL_CHARSET);
+    }
 
-                return data.getBytes();
-            }
+    /**
+     * Escape and encode a string regarded as the path component of an URI with
+     * a given charset.
+     *
+     * @param unescaped an unescaped string
+     * @param charset the charset
+     * @return the escaped string
+     *
+     * @throws URISyntaxException if the charset is not supported
+     */
+    public static String encodePath(final String unescaped, final String charset) throws URISyntaxException {
+        if (unescaped == null) {
+            throw new IllegalArgumentException("The string to encode may not be null.");
         }
 
-        /**
-         * Converts the byte array of ASCII characters to a string. This method is
-         * to be used when decoding content of HTTP elements (such as response
-         * headers)
-         *
-         * @param data the byte array to be encoded
-         * @param offset the index of the first byte to encode
-         * @param length the number of bytes to encode
-         * @return The string representation of the byte array
-         */
-        static String getAsciiString(final byte[] data, final int offset, final int length) {
-            try {
-                return new String(data, offset, length, "US-ASCII");
-            } catch (final UnsupportedEncodingException e) {
-                throw new RuntimeException("US-ASCII charset is not supported.");
-            }
-        }
+        return encode(unescaped, URIBitSets.allowed_abs_path, charset);
+    }
+
+    private URIUtils() {
     }
 
 }


[commons-vfs] 03/03: Drop some unused exceptions from throws clauses (this does not break binary compatibility).

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

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

commit e7e47f80900570fdbc26d3fc9a25713fc3afdd30
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Wed Sep 23 10:13:38 2020 -0400

    Drop some unused exceptions from throws clauses (this does not break
    binary compatibility).
---
 .../apache/commons/vfs2/provider/webdav4/Webdav4FileObject.java  | 7 +++----
 .../vfs2/provider/webdav4/test/Webdav4ProviderTestCase.java      | 6 ++----
 .../org/apache/commons/vfs2/provider/GenericURLFileName.java     | 6 ++----
 .../org/apache/commons/vfs2/provider/http4/Http4FileObject.java  | 6 ++----
 .../org/apache/commons/vfs2/provider/http5/Http5FileObject.java  | 6 ++----
 .../src/main/java/org/apache/commons/vfs2/util/URIUtils.java     | 9 ++-------
 6 files changed, 13 insertions(+), 27 deletions(-)

diff --git a/commons-vfs2-jackrabbit2/src/main/java/org/apache/commons/vfs2/provider/webdav4/Webdav4FileObject.java b/commons-vfs2-jackrabbit2/src/main/java/org/apache/commons/vfs2/provider/webdav4/Webdav4FileObject.java
index b74cc23..824c8a4 100644
--- a/commons-vfs2-jackrabbit2/src/main/java/org/apache/commons/vfs2/provider/webdav4/Webdav4FileObject.java
+++ b/commons-vfs2-jackrabbit2/src/main/java/org/apache/commons/vfs2/provider/webdav4/Webdav4FileObject.java
@@ -20,7 +20,6 @@ import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.io.OutputStream;
 import java.net.HttpURLConnection;
-import java.net.URISyntaxException;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
@@ -220,12 +219,12 @@ public class Webdav4FileObject extends Http4FileObject<Webdav4FileSystem> {
     private final Webdav4FileSystem fileSystem;
 
     protected Webdav4FileObject(final AbstractFileName name, final Webdav4FileSystem fileSystem)
-            throws FileSystemException, URISyntaxException {
+            throws FileSystemException {
         this(name, fileSystem, Webdav4FileSystemConfigBuilder.getInstance());
     }
 
     protected Webdav4FileObject(final AbstractFileName name, final Webdav4FileSystem fileSystem,
-            final Webdav4FileSystemConfigBuilder builder) throws FileSystemException, URISyntaxException {
+            final Webdav4FileSystemConfigBuilder builder) throws FileSystemException {
         super(name, fileSystem, builder);
         this.fileSystem = fileSystem;
         this.builder = builder;
@@ -588,7 +587,7 @@ public class Webdav4FileObject extends Http4FileObject<Webdav4FileSystem> {
         return i >= 0 ? path.substring(i + 1) : path;
     }
 
-    private void setupRequest(final HttpUriRequest request) throws FileSystemException {
+    private void setupRequest(final HttpUriRequest request) {
         // NOTE: *FileSystemConfigBuilder takes care of redirect option and user agent.
         request.addHeader("Cache-control", "no-cache");
         request.addHeader("Cache-store", "no-store");
diff --git a/commons-vfs2-jackrabbit2/src/test/java/org/apache/commons/vfs2/provider/webdav4/test/Webdav4ProviderTestCase.java b/commons-vfs2-jackrabbit2/src/test/java/org/apache/commons/vfs2/provider/webdav4/test/Webdav4ProviderTestCase.java
index 279b2fc..9d7fd07 100644
--- a/commons-vfs2-jackrabbit2/src/test/java/org/apache/commons/vfs2/provider/webdav4/test/Webdav4ProviderTestCase.java
+++ b/commons-vfs2-jackrabbit2/src/test/java/org/apache/commons/vfs2/provider/webdav4/test/Webdav4ProviderTestCase.java
@@ -153,7 +153,7 @@ public class Webdav4ProviderTestCase extends AbstractProviderTestConfig {
         return System.getProperty(TEST_URI);
     }
 
-    private static TransientRepository getTransientRepository(final File repoDirectory) throws IOException {
+    private static TransientRepository getTransientRepository(final File repoDirectory) {
         return new TransientRepository(new File(repoDirectory, "repository.xml"), repoDirectory);
     }
 
@@ -270,10 +270,8 @@ public class Webdav4ProviderTestCase extends AbstractProviderTestConfig {
      * <li>Remove temporary repository directory.</li>
      * </ol>
      * Stops the embedded Apache WebDAV Server.
-     *
-     * @throws Exception @throws
      */
-    private static void tearDownClass() throws Exception {
+    private static void tearDownClass() {
         // Stop Jackrabbit Main for graceful shutdown
         jrMain.shutdown();
 
diff --git a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/GenericURLFileName.java b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/GenericURLFileName.java
index 7216aaa..a5526e7 100644
--- a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/GenericURLFileName.java
+++ b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/GenericURLFileName.java
@@ -67,10 +67,9 @@ public class GenericURLFileName extends GenericFileName {
      *
      * @param charset the charset used for the path encoding
      * @return The encoded path.
-     * @throws URISyntaxException If an error occurs encoding the URI.
      * @throws FileSystemException If some other error occurs.
      */
-    public String getPathQueryEncoded(final String charset) throws URISyntaxException, FileSystemException {
+    public String getPathQueryEncoded(final String charset) throws FileSystemException {
         if (getQueryString() == null) {
             if (charset != null) {
                 return URIUtils.encodePath(getPathDecoded(), charset);
@@ -128,9 +127,8 @@ public class GenericURLFileName extends GenericFileName {
      * @param charset The character set.
      * @return The encoded URI
      * @throws FileSystemException if some other exception occurs.
-     * @throws URISyntaxException if an exception occurs encoding the URI.
      */
-    public String getURIEncoded(final String charset) throws FileSystemException, URISyntaxException {
+    public String getURIEncoded(final String charset) throws FileSystemException {
         final StringBuilder sb = new StringBuilder(BUFFER_SIZE);
         appendRootUri(sb, true);
         sb.append(getPathQueryEncoded(charset));
diff --git a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/http4/Http4FileObject.java b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/http4/Http4FileObject.java
index 4e6049f..05e5356 100644
--- a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/http4/Http4FileObject.java
+++ b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/http4/Http4FileObject.java
@@ -74,10 +74,9 @@ public class Http4FileObject<FS extends Http4FileSystem> extends AbstractFileObj
      * @param name file name
      * @param fileSystem file system
      * @throws FileSystemException if any error occurs
-     * @throws URISyntaxException if given file name cannot be converted to a URI due to URI syntax error
      */
     protected Http4FileObject(final AbstractFileName name, final FS fileSystem)
-            throws FileSystemException, URISyntaxException {
+            throws FileSystemException {
         this(name, fileSystem, Http4FileSystemConfigBuilder.getInstance());
     }
 
@@ -88,10 +87,9 @@ public class Http4FileObject<FS extends Http4FileSystem> extends AbstractFileObj
      * @param fileSystem file system
      * @param builder {@code Http4FileSystemConfigBuilder} object
      * @throws FileSystemException if any error occurs
-     * @throws URISyntaxException if given file name cannot be converted to a URI due to URI syntax error
      */
     protected Http4FileObject(final AbstractFileName name, final FS fileSystem,
-            final Http4FileSystemConfigBuilder builder) throws FileSystemException, URISyntaxException {
+            final Http4FileSystemConfigBuilder builder) throws FileSystemException {
         super(name, fileSystem);
         final FileSystemOptions fileSystemOptions = fileSystem.getFileSystemOptions();
         urlCharset = builder.getUrlCharset(fileSystemOptions);
diff --git a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/http5/Http5FileObject.java b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/http5/Http5FileObject.java
index a48891d..30b7f80 100644
--- a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/http5/Http5FileObject.java
+++ b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/http5/Http5FileObject.java
@@ -75,10 +75,9 @@ public class Http5FileObject<FS extends Http5FileSystem> extends AbstractFileObj
      * @param name file name
      * @param fileSystem file system
      * @throws FileSystemException if any error occurs
-     * @throws URISyntaxException if given file name cannot be converted to a URI due to URI syntax error
      */
     protected Http5FileObject(final AbstractFileName name, final FS fileSystem)
-            throws FileSystemException, URISyntaxException {
+            throws FileSystemException {
         this(name, fileSystem, Http5FileSystemConfigBuilder.getInstance());
     }
 
@@ -89,10 +88,9 @@ public class Http5FileObject<FS extends Http5FileSystem> extends AbstractFileObj
      * @param fileSystem file system
      * @param builder {@code Http4FileSystemConfigBuilder} object
      * @throws FileSystemException if any error occurs
-     * @throws URISyntaxException if given file name cannot be converted to a URI due to URI syntax error
      */
     protected Http5FileObject(final AbstractFileName name, final FS fileSystem,
-            final Http5FileSystemConfigBuilder builder) throws FileSystemException, URISyntaxException {
+            final Http5FileSystemConfigBuilder builder) throws FileSystemException {
         super(name, fileSystem);
         final FileSystemOptions fileSystemOptions = fileSystem.getFileSystemOptions();
         urlCharset = builder.getUrlCharset(fileSystemOptions);
diff --git a/commons-vfs2/src/main/java/org/apache/commons/vfs2/util/URIUtils.java b/commons-vfs2/src/main/java/org/apache/commons/vfs2/util/URIUtils.java
index bb3b528..76779f0 100644
--- a/commons-vfs2/src/main/java/org/apache/commons/vfs2/util/URIUtils.java
+++ b/commons-vfs2/src/main/java/org/apache/commons/vfs2/util/URIUtils.java
@@ -18,7 +18,6 @@ package org.apache.commons.vfs2.util;
 
 import java.io.ByteArrayOutputStream;
 import java.io.UnsupportedEncodingException;
-import java.net.URISyntaxException;
 import java.util.BitSet;
 
 import org.apache.commons.logging.Log;
@@ -194,10 +193,8 @@ public class URIUtils {
      *
      * @param unescaped an unescaped string
      * @return the escaped string
-     *
-     * @throws URISyntaxException not thrown but kept for source compatibility
      */
-    public static String encodePath(final String unescaped) throws URISyntaxException {
+    public static String encodePath(final String unescaped) {
         return encodePath(unescaped, DEFAULT_PROTOCOL_CHARSET);
     }
 
@@ -208,10 +205,8 @@ public class URIUtils {
      * @param unescaped an unescaped string
      * @param charset the charset
      * @return the escaped string
-     *
-     * @throws URISyntaxException not thrown but kept for source compatibility
      */
-    public static String encodePath(final String unescaped, final String charset) throws URISyntaxException {
+    public static String encodePath(final String unescaped, final String charset) {
         if (unescaped == null) {
             throw new IllegalArgumentException("The string to encode may not be null.");
         }


[commons-vfs] 02/03: Remove URISyntaxException from private method. This commits simply changes the private method signature but not the public one in this class for source compatibility, which lets the compiler tell us that other methods now uselessly throw URISyntaxException.

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

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

commit 676451b7faffa65dcabe15beb5ebb154244f8c58
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Wed Sep 23 10:00:16 2020 -0400

    Remove URISyntaxException from private method. This commits simply
    changes the private method signature but not the public one in this
    class for source compatibility, which lets the compiler tell us that
    other methods now uselessly throw URISyntaxException.
---
 .../src/main/java/org/apache/commons/vfs2/util/URIUtils.java        | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/commons-vfs2/src/main/java/org/apache/commons/vfs2/util/URIUtils.java b/commons-vfs2/src/main/java/org/apache/commons/vfs2/util/URIUtils.java
index 8b05bf6..bb3b528 100644
--- a/commons-vfs2/src/main/java/org/apache/commons/vfs2/util/URIUtils.java
+++ b/commons-vfs2/src/main/java/org/apache/commons/vfs2/util/URIUtils.java
@@ -183,7 +183,7 @@ public class URIUtils {
      */
     private static final String DEFAULT_PROTOCOL_CHARSET = "UTF-8";
 
-    private static String encode(final String unescaped, final BitSet allowed, final String charset) throws URISyntaxException {
+    private static String encode(final String unescaped, final BitSet allowed, final String charset) {
         final byte[] rawdata = URLCodecUtils.encodeUrl(allowed, EncodingUtils.getBytes(unescaped, charset));
         return EncodingUtils.getAsciiString(rawdata, 0, rawdata.length);
     }
@@ -195,7 +195,7 @@ public class URIUtils {
      * @param unescaped an unescaped string
      * @return the escaped string
      *
-     * @throws URISyntaxException if the default protocol charset is not supported
+     * @throws URISyntaxException not thrown but kept for source compatibility
      */
     public static String encodePath(final String unescaped) throws URISyntaxException {
         return encodePath(unescaped, DEFAULT_PROTOCOL_CHARSET);
@@ -209,7 +209,7 @@ public class URIUtils {
      * @param charset the charset
      * @return the escaped string
      *
-     * @throws URISyntaxException if the charset is not supported
+     * @throws URISyntaxException not thrown but kept for source compatibility
      */
     public static String encodePath(final String unescaped, final String charset) throws URISyntaxException {
         if (unescaped == null) {