mirror of
https://github.com/Eaglercraft-TeaVM-Fork/eagler-teavm.git
synced 2024-12-22 16:14:10 -08:00
Add support for URL encode/decode methods added in Java 10.
This commit is contained in:
parent
9daba6e5a6
commit
cbbf7b5298
|
@ -52,17 +52,10 @@ public final class TURLEncoder {
|
||||||
return buf.toString();
|
return buf.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String encode(String s, String enc) throws UnsupportedEncodingException {
|
public static String encode(String s, Charset enc) {
|
||||||
Objects.requireNonNull(s);
|
Objects.requireNonNull(s);
|
||||||
Objects.requireNonNull(enc);
|
Objects.requireNonNull(enc);
|
||||||
|
|
||||||
// check for UnsupportedEncodingException
|
|
||||||
try {
|
|
||||||
Charset.forName(enc);
|
|
||||||
} catch (UnsupportedCharsetException e) {
|
|
||||||
throw new UnsupportedEncodingException(enc);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Guess a bit bigger for encoded form
|
// Guess a bit bigger for encoded form
|
||||||
StringBuffer buf = new StringBuffer(s.length() + 16);
|
StringBuffer buf = new StringBuffer(s.length() + 16);
|
||||||
int start = -1;
|
int start = -1;
|
||||||
|
@ -91,7 +84,19 @@ public final class TURLEncoder {
|
||||||
return buf.toString();
|
return buf.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void convert(String s, StringBuffer buf, String enc) throws UnsupportedEncodingException {
|
public static String encode(String s, String enc) throws UnsupportedEncodingException {
|
||||||
|
Objects.requireNonNull(s);
|
||||||
|
Objects.requireNonNull(enc);
|
||||||
|
|
||||||
|
// check for UnsupportedEncodingException
|
||||||
|
try {
|
||||||
|
return encode(s, Charset.forName(enc));
|
||||||
|
} catch (UnsupportedCharsetException e) {
|
||||||
|
throw new UnsupportedEncodingException(enc);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void convert(String s, StringBuffer buf, Charset enc) {
|
||||||
byte[] bytes = s.getBytes(enc);
|
byte[] bytes = s.getBytes(enc);
|
||||||
for (int j = 0; j < bytes.length; j++) {
|
for (int j = 0; j < bytes.length; j++) {
|
||||||
buf.append('%');
|
buf.append('%');
|
||||||
|
|
Loading…
Reference in New Issue
Block a user