in commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/UriParser.java [159:195]
public static void decode(final StringBuilder buffer, final int offset, final int length)
throws FileSystemException {
int index = offset;
int count = length;
boolean ipv6Host = false;
for (; count > 0; count--, index++) {
final char ch = buffer.charAt(index);
if (ch == '[') {
ipv6Host = true;
}
if (ch == ']') {
ipv6Host = false;
}
if (ch != '%' || ipv6Host) {
continue;
}
if (count < 3) {
throw new FileSystemException("vfs.provider/invalid-escape-sequence.error",
buffer.substring(index, index + count));
}
// Decode
final int dig1 = Character.digit(buffer.charAt(index + 1), HEX_BASE);
final int dig2 = Character.digit(buffer.charAt(index + 2), HEX_BASE);
if (dig1 == -1 || dig2 == -1) {
throw new FileSystemException("vfs.provider/invalid-escape-sequence.error",
buffer.substring(index, index + 3));
}
final char value = (char) (dig1 << BITS_IN_HALF_BYTE | dig2);
// Replace
buffer.setCharAt(index, value);
buffer.delete(index + 1, index + 3);
count -= 2;
}
}