Class Method

java.lang.Object
org.apache.tomcat.util.http.Method

public class Method extends Object
HTTP method constants and utilities.
  • Field Details

  • Method Details

    • bytesToString

      public static String bytesToString(byte[] buf, int start, int len)
      Provides optimised conversion from bytes to Strings for known HTTP methods. The bytes are assumed to be an ISO-8859-1 encoded representation of an HTTP method. The method is not validated as being a token, but only valid HTTP method names will be returned.

      Doing it this way is ~10x faster than using MessageBytes.toStringType() saving ~40ns per request which is ~1% of the processing time for a minimal "Hello World" type servlet. For non-standard methods there is an additional overhead of ~2.5ns per request.

      Pretty much every request ends up converting the method to a String so it is more efficient to do this straight away and always use Strings.

      Parameters:
      buf - The byte buffer containing the HTTP method to convert
      start - The first byte of the HTTP method
      len - The number of bytes to convert
      Returns:
      The HTTP method as a String or null if the method is not recognised.