MCPcopy Index your code
hub / github.com/OpenFeign/feign / encodeChunk

Method encodeChunk

core/src/main/java/feign/template/UriUtils.java:150–171  ·  view source on GitHub ↗

Encode a Uri Chunk, ensuring that all reserved characters are also encoded. @param value to encode. @param charset to use. @return an encoded uri chunk.

(String value, Charset charset, boolean allowReserved)

Source from the content-addressed store, hash-verified

148 * @return an encoded uri chunk.
149 */
150 private static String encodeChunk(String value, Charset charset, boolean allowReserved) {
151 if (isEncoded(value, charset)) {
152 return value;
153 }
154
155 byte[] data = value.getBytes(charset);
156 try (ByteArrayOutputStream bos = new ByteArrayOutputStream()) {
157 for (byte b : data) {
158 if (isUnreserved((char) b)) {
159 bos.write(b);
160 } else if (isReserved((char) b) && allowReserved) {
161 bos.write(b);
162 } else {
163 pctEncode(b, bos);
164 }
165 }
166 return new String(bos.toByteArray(), charset);
167 } catch (IOException ioe) {
168 throw new IllegalStateException(
169 "Error occurred during encoding of the uri: " + ioe.getMessage(), ioe);
170 }
171 }
172
173 /**
174 * Percent Encode the provided byte.

Callers 2

encodeMethod · 0.95
encodeInternalMethod · 0.95

Calls 7

isEncodedMethod · 0.95
isUnreservedMethod · 0.95
isReservedMethod · 0.95
pctEncodeMethod · 0.95
writeMethod · 0.65
toByteArrayMethod · 0.45
getMessageMethod · 0.45

Tested by

no test coverage detected