MCPcopy Index your code
hub / github.com/apache/tomcat / toBytes

Method toBytes

java/org/apache/tomcat/util/buf/MessageBytes.java:293–325  ·  view source on GitHub ↗

Convert to bytes and fill the ByteChunk with the converted value.

()

Source from the content-addressed store, hash-verified

291 * Convert to bytes and fill the ByteChunk with the converted value.
292 */
293 public void toBytes() {
294 if (type == T_NULL) {
295 byteC.recycle();
296 return;
297 }
298
299 if (type == T_BYTES) {
300 // No conversion required
301 return;
302 }
303
304 ByteBuffer bb;
305 CharsetEncoder encoder = getCharset().newEncoder();
306 encoder.onMalformedInput(CodingErrorAction.REPORT);
307 encoder.onUnmappableCharacter(CodingErrorAction.REPORT);
308
309 try {
310 if (type == T_CHARS) {
311 bb = encoder.encode(CharBuffer.wrap(charC));
312 } else {
313 // Must be T_STR
314 bb = encoder.encode(CharBuffer.wrap(strValue));
315 }
316 } catch (CharacterCodingException cce) {
317 // Some calls to this conversion originate in application code and
318 // the Servlet API methods do not declare a suitable exception that
319 // can be thrown. Therefore, stick with the uncaught exception type
320 // used by the old, pre-Java 16 optimised version of this code.
321 throw new IllegalArgumentException(cce);
322 }
323
324 byteC.setBytes(bb.array(), bb.arrayOffset(), bb.limit());
325 }
326
327
328 /**

Callers 9

testParseHostMethod · 0.95
testToBytesFromNullMethod · 0.95
parseCookieHeaderMethod · 0.95
prepareRequestMethod · 0.95
doAuthenticateMethod · 0.95
doAuthenticateMethod · 0.95
MessageBytesTypeEnum · 0.45
processParametersMethod · 0.45

Calls 8

getCharsetMethod · 0.95
arrayMethod · 0.95
limitMethod · 0.95
newEncoderMethod · 0.80
recycleMethod · 0.65
encodeMethod · 0.65
wrapMethod · 0.45
setBytesMethod · 0.45

Tested by 3

testParseHostMethod · 0.76
testToBytesFromNullMethod · 0.76