? .HeaderGroup.java.swp ? httpstatus_optimize.diff Index: HttpStatus.java =================================================================== RCS file: /home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpStatus.java,v retrieving revision 1.12 diff -u -r1.12 HttpStatus.java --- HttpStatus.java 28 Jan 2003 22:25:21 -0000 1.12 +++ HttpStatus.java 27 Apr 2003 01:19:30 -0000 @@ -65,15 +65,18 @@ import java.util.Hashtable; -import org.apache.commons.logging.LogFactory; -import org.apache.commons.logging.Log; /** - *

Constants enumerating the HTTP status codes.

+ * Constants enumerating the HTTP status codes. + * All status codes defined in RFC1945 (HTTP/1.0, RFC2616 (HTTP/1.1), and + * RFC2518 (WebDAV) are supported. * * @see StatusLine * @author Unascribed * @author Mike Bowler + * @author Jeff Dever + * + * TODO: Internationalization of reason phrases * * @version $Id: HttpStatus.java,v 1.12 2003/01/28 22:25:21 jsdever Exp $ */ @@ -82,44 +85,56 @@ // -------------------------------------------------------- Class Variables - /** Reason phrases (as Strings), by status code (as Integer). */ - private static final Hashtable MAP_STATUS_CODES = new Hashtable(); + /** Reason phrases lookup table. */ + private static final String[][] ReasonPhrases = new String[][]{ + new String[0], + new String[3], + new String[8], + new String[8], + new String[25], + new String[8] + }; + - /** Log object for this class. */ - private static final Log LOG = LogFactory.getLog(HttpStatus.class); // --------------------------------------------------------- Public Methods /** - * Get the "reason phrase" associated with the given - * HTTP status code, or null if no - * such reason phrase can be found. - * @param nHttpStatusCode the numeric status code + * Get the reason phrase for a particular status code. + * + * This method always returns the English text as specified in the + * relevent RFCs and is not internationalized. + * + * @param statusCode the numeric status code * @return the reason phrase associated with the given status code + * or null if the status code is not recognized. + * + * TODO: getStatusText should be called getReasonPhrase to match RFC */ - public static String getStatusText(int nHttpStatusCode) { - LOG.trace("enter HttpStatus.getStatusText(int)"); + public static String getStatusText(int statusCode) { + + int classIndex = statusCode/100; + int codeIndex = statusCode-classIndex*100; + if (classIndex < 1 || classIndex > ReasonPhrases.length-1 || + codeIndex < 0 || codeIndex > ReasonPhrases[classIndex].length) + return null; + return ReasonPhrases[classIndex][codeIndex]; - Integer intKey = new Integer(nHttpStatusCode); - if (!MAP_STATUS_CODES.containsKey(intKey)) { - LOG.warn("No status text available for status code " + nHttpStatusCode); - return null; - } else { - return (String) MAP_STATUS_CODES.get(intKey); - } + } // -------------------------------------------------------- Private Methods /** - * Store the given reason phrase (as String), by status code (as Integer). - * @param nKey The status code - * @param strVal The reason phrase + * Store the given reason phrase, by status code. + * @param statusCode The status code to lookup + * @param reasonPhrase The reason phrase for this status code */ - private static void addStatusCodeMap(int nKey, String strVal) { - MAP_STATUS_CODES.put(new Integer(nKey), strVal); + private static void addStatusCodeMap(int statusCode, String reasonPhrase) { + int classIndex = statusCode/100; + ReasonPhrases[classIndex][statusCode-classIndex*100] = reasonPhrase; }