Make `loader` Windows compatible

The encoding of UTF-8 (et al.) chars in the
JarUrlConnection has to be made explicit, otherwise
Wdinows apparently does not pick the default(?).

Fixes gh-711, Fixes gh-753
This commit is contained in:
Artem Bilan 2014-04-30 11:56:04 +03:00 committed by Phillip Webb
parent f81c01d490
commit 471e6af2af
1 changed files with 14 additions and 18 deletions

View File

@ -20,14 +20,14 @@ import java.io.ByteArrayOutputStream;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.net.URL; import java.net.URL;
import java.nio.charset.Charset;
import java.util.jar.Manifest; import java.util.jar.Manifest;
/** /**
* {@link java.net.JarURLConnection} used to support {@link JarFile#getUrl()}. * {@link java.net.JarURLConnection} used to support {@link JarFile#getUrl()}.
* *
* @author Phillip Webb * @author Phillip Webb
*/ */
class JarURLConnection extends java.net.JarURLConnection { class JarURLConnection extends java.net.JarURLConnection {
@ -169,25 +169,21 @@ class JarURLConnection extends java.net.JarURLConnection {
if ((length == 0) || (source.indexOf('%') < 0)) { if ((length == 0) || (source.indexOf('%') < 0)) {
return source; return source;
} }
try { ByteArrayOutputStream bos = new ByteArrayOutputStream(length);
ByteArrayOutputStream bos = new ByteArrayOutputStream(length); for (int i = 0; i < length; i++) {
for (int i = 0; i < length; i++) { int ch = source.charAt(i);
int ch = source.charAt(i); if (ch == '%') {
if (ch == '%') { if ((i + 2) >= length) {
if ((i + 2) >= length) { throw new IllegalArgumentException("Invalid encoded sequence \""
throw new IllegalArgumentException("Invalid encoded sequence \"" + source.substring(i) + "\"");
+ source.substring(i) + "\"");
}
ch = decodeEscapeSequence(source, i);
i += 2;
} }
bos.write(ch); ch = decodeEscapeSequence(source, i);
i += 2;
} }
return new String(bos.toByteArray(), "UTF-8"); bos.write(ch);
}
catch (UnsupportedEncodingException ex) {
throw new IllegalStateException(ex);
} }
return new String(bos.toByteArray(), Charset.defaultCharset());
} }
private static char decodeEscapeSequence(String source, int i) { private static char decodeEscapeSequence(String source, int i) {