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:45 UTC
[commons-vfs] 01/03: Sort members.
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() {
}
}