MCPcopy Create free account
hub / github.com/0opslab/opslabJutil / encodeBytes

Method encodeBytes

src/main/java/com/opslab/helper/UrlHelper.java:87–104  ·  view source on GitHub ↗

Encodes byte array using allowed characters from URIPart.

(byte[] source, URIPart uriPart)

Source from the content-addressed store, hash-verified

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.

Callers 1

encodeUriComponentMethod · 0.95

Calls 3

isValidMethod · 0.80
writeMethod · 0.45
toByteArrayMethod · 0.45

Tested by

no test coverage detected