harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From zhouke...@apache.org
Subject svn commit: r796623 - in /harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni: internal/net/www/protocol/jar/JarURLConnection.java util/Util.java
Date Wed, 22 Jul 2009 07:34:22 GMT
Author: zhoukevin
Date: Wed Jul 22 07:34:18 2009
New Revision: 796623

URL: http://svn.apache.org/viewvc?rev=796623&view=rev
Log:
Fix a test failure of JarURLConnectionTest for z/OS. The file name in private method of org.apache.harmony.luni.internal.net.www.protocol.jar.JarURLConnection.openJarFile()
should be decoded using "UTF-8" encoding.

Modified:
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/jar/JarURLConnection.java
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/util/Util.java

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/jar/JarURLConnection.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/jar/JarURLConnection.java?rev=796623&r1=796622&r2=796623&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/jar/JarURLConnection.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/jar/JarURLConnection.java
Wed Jul 22 07:34:18 2009
@@ -138,9 +138,9 @@
     JarFile openJarFile() throws IOException {
         JarFile jar = null;
         if (jarFileURL.getProtocol().equals("file")) { //$NON-NLS-1$
-            jar = new JarFile(new File(Util.decode(jarFileURL.getFile(), false)),
-                        true, ZipFile.OPEN_READ);
-        } else{
+            jar = new JarFile(new File(Util.decode(jarFileURL.getFile(), false,
+                    "UTF-8")), true, ZipFile.OPEN_READ);
+        } else {
             final InputStream is = jarFileURL.openConnection().getInputStream();
             try {
                 jar = AccessController

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/util/Util.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/util/Util.java?rev=796623&r1=796622&r2=796623&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/util/Util.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/util/Util.java
Wed Jul 22 07:34:18 2009
@@ -20,6 +20,7 @@
 
 import java.io.ByteArrayOutputStream;
 import java.io.UTFDataFormatException;
+import java.io.UnsupportedEncodingException;
 import java.util.Calendar;
 import java.util.TimeZone;
 
@@ -267,38 +268,61 @@
 	 *            java.lang.String The encoded string.
 	 * @return java.lang.String The decoded version.
 	 */
-	public static String decode(String s, boolean convertPlus) {
-		if (!convertPlus && s.indexOf('%') == -1)
-			return s;
-		StringBuilder result = new StringBuilder(s.length());
-		ByteArrayOutputStream out = new ByteArrayOutputStream();
-		for (int i = 0; i < s.length();) {
-			char c = s.charAt(i);
-			if (convertPlus && c == '+')
-				result.append(' ');
-			else if (c == '%') {
-				out.reset();
-				do {
-					if (i + 2 >= s.length())
-						throw new IllegalArgumentException(Msg.getString(
-								"K01fe", i));
-					int d1 = Character.digit(s.charAt(i + 1), 16);
-					int d2 = Character.digit(s.charAt(i + 2), 16);
-					if (d1 == -1 || d2 == -1)
-						throw new IllegalArgumentException(Msg.getString(
-								"K01ff", s.substring(i, i + 3), String
-										.valueOf(i)));
-					out.write((byte) ((d1 << 4) + d2));
-					i += 3;
-				} while (i < s.length() && s.charAt(i) == '%');
-				result.append(out.toString());
-				continue;
-			} else
-				result.append(c);
-			i++;
-		}
-		return result.toString();
-	}
+    public static String decode(String s, boolean convertPlus) {
+        return decode(s, convertPlus, null);
+    }
+
+    /**
+     * '%' and two following hex digit characters are converted to the
+     * equivalent byte value. All other characters are passed through
+     * unmodified. e.g. "ABC %24%25" -> "ABC $%"
+     * 
+     * @param s
+     *            java.lang.String The encoded string.
+     * @param encoding
+     *            the specified encoding
+     * @return java.lang.String The decoded version.
+     */
+    public static String decode(String s, boolean convertPlus, String encoding) {
+        if (!convertPlus && s.indexOf('%') == -1)
+            return s;
+        StringBuilder result = new StringBuilder(s.length());
+        ByteArrayOutputStream out = new ByteArrayOutputStream();
+        for (int i = 0; i < s.length();) {
+            char c = s.charAt(i);
+            if (convertPlus && c == '+')
+                result.append(' ');
+            else if (c == '%') {
+                out.reset();
+                do {
+                    if (i + 2 >= s.length())
+                        throw new IllegalArgumentException(Msg.getString(
+                                "K01fe", i));
+                    int d1 = Character.digit(s.charAt(i + 1), 16);
+                    int d2 = Character.digit(s.charAt(i + 2), 16);
+                    if (d1 == -1 || d2 == -1)
+                        throw new IllegalArgumentException(Msg.getString(
+                                "K01ff", s.substring(i, i + 3), String
+                                        .valueOf(i)));
+                    out.write((byte) ((d1 << 4) + d2));
+                    i += 3;
+                } while (i < s.length() && s.charAt(i) == '%');
+                if (encoding == null) {
+                    result.append(out.toString());
+                } else {
+                    try {
+                        result.append(out.toString(encoding));
+                    } catch (UnsupportedEncodingException e) {
+                        throw new IllegalArgumentException(e);
+                    }
+                }
+                continue;
+            } else
+                result.append(c);
+            i++;
+        }
+        return result.toString();
+    }
 	
 	public static String toASCIILowerCase(String s) {
         int len = s.length();



Mime
View raw message