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,25 @@ 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+ return encode (buffer , toEncode .toLowerCase (Locale .ENGLISH ));
447+ }
448+
449+
450+ /**
451+ * Encodes the given string into the buffer. If there is not enough space in the buffer, or the encoded version is
452+ * bigger than the original it will return false and not modify the buffers position.
453+ *
454+ * @param buffer The buffer to encode into
455+ * @param toEncode The string to encode
456+ *
457+ * @return true if encoding succeeded
458+ */
459+ public static boolean encode (ByteBuffer buffer , String toEncode ) {
442460 if (buffer .remaining () <= toEncode .length ()) {
443461 return false ;
444462 }
@@ -453,9 +471,6 @@ public static boolean encode(ByteBuffer buffer, String toEncode, boolean forceLo
453471 throw new IllegalArgumentException (
454472 sm .getString ("hpack.invalidCharacter" , Character .toString (c ), Integer .valueOf (c )));
455473 }
456- if (forceLowercase ) {
457- c = Hpack .toLower (c );
458- }
459474 HuffmanCode code = HUFFMAN_CODES [c ];
460475 length += code .length ;
461476 }
@@ -469,9 +484,6 @@ public static boolean encode(ByteBuffer buffer, String toEncode, boolean forceLo
469484 byte currentBufferByte = 0 ;
470485 for (int i = 0 ; i < toEncode .length (); ++i ) {
471486 char c = toEncode .charAt (i );
472- if (forceLowercase ) {
473- c = Hpack .toLower (c );
474- }
475487 HuffmanCode code = HUFFMAN_CODES [c ];
476488 if (code .length + bytePos <= 8 ) {
477489 // it fits in the current byte
0 commit comments