1919import java .nio .ByteBuffer ;
2020import java .util .Arrays ;
2121import java .util .HashSet ;
22+ import java .util .Locale ;
2223import java .util .Set ;
2324
2425import org .apache .tomcat .util .res .StringManager ;
@@ -437,8 +438,29 @@ public static void decode(ByteBuffer data, int length, StringBuilder target) thr
437438 * @param forceLowercase If the string should be encoded in lower case
438439 *
439440 * @return true if encoding succeeded
441+ *
442+ * @deprecated Unused. This method will be removed in Tomcat 12 onwards.
440443 */
444+ @ Deprecated
441445 public static boolean encode (ByteBuffer buffer , String toEncode , boolean forceLowercase ) {
446+ if (forceLowercase ) {
447+ return encode (buffer , toEncode .toLowerCase (Locale .ENGLISH ));
448+ } else {
449+ return encode (buffer , toEncode );
450+ }
451+ }
452+
453+
454+ /**
455+ * Encodes the given string into the buffer. If there is not enough space in the buffer, or the encoded version is
456+ * bigger than the original it will return false and not modify the buffers position.
457+ *
458+ * @param buffer The buffer to encode into
459+ * @param toEncode The string to encode
460+ *
461+ * @return true if encoding succeeded
462+ */
463+ public static boolean encode (ByteBuffer buffer , String toEncode ) {
442464 if (buffer .remaining () <= toEncode .length ()) {
443465 return false ;
444466 }
@@ -453,9 +475,6 @@ public static boolean encode(ByteBuffer buffer, String toEncode, boolean forceLo
453475 throw new IllegalArgumentException (
454476 sm .getString ("hpack.invalidCharacter" , Character .toString (c ), Integer .valueOf (c )));
455477 }
456- if (forceLowercase ) {
457- c = Hpack .toLower (c );
458- }
459478 HuffmanCode code = HUFFMAN_CODES [c ];
460479 length += code .length ;
461480 }
@@ -469,9 +488,6 @@ public static boolean encode(ByteBuffer buffer, String toEncode, boolean forceLo
469488 byte currentBufferByte = 0 ;
470489 for (int i = 0 ; i < toEncode .length (); ++i ) {
471490 char c = toEncode .charAt (i );
472- if (forceLowercase ) {
473- c = Hpack .toLower (c );
474- }
475491 HuffmanCode code = HUFFMAN_CODES [c ];
476492 if (code .length + bytePos <= 8 ) {
477493 // it fits in the current byte
0 commit comments