Convert to bytes and fill the ByteChunk with the converted value.
()
| 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 | /** |