Encodes byte array using allowed characters from URIPart.
(byte[] source, URIPart uriPart)
| 85 | * Encodes byte array using allowed characters from {@link URIPart}. |
| 86 | */ |
| 87 | private static byte[] encodeBytes(byte[] source, URIPart uriPart) { |
| 88 | ByteArrayOutputStream bos = new ByteArrayOutputStream(source.length); |
| 89 | for (byte b : source) { |
| 90 | if (b < 0) { |
| 91 | b += 256; |
| 92 | } |
| 93 | if (uriPart.isValid((char) b)) { |
| 94 | bos.write(b); |
| 95 | } else { |
| 96 | bos.write('%'); |
| 97 | char hex1 = Character.toUpperCase(Character.forDigit((b >> 4) & 0xF, 16)); |
| 98 | char hex2 = Character.toUpperCase(Character.forDigit(b & 0xF, 16)); |
| 99 | bos.write(hex1); |
| 100 | bos.write(hex2); |
| 101 | } |
| 102 | } |
| 103 | return bos.toByteArray(); |
| 104 | } |
| 105 | |
| 106 | /** |
| 107 | * Encodes the given URI scheme with the given encoding. |
no test coverage detected