jicarilla-sandbox/platform/components/http/api/src/java/org/jicarilla/http HTTPEncoding.java,1.3,1.4 HTTPException.java,1.3,1.4 HTTPField.java,1.3,1.4 HTTPMessage.java,1.4,1.5 HTTPParser.java,1.2,1.3

[email protected]
Newsgroups gmane.comp.java.jicarilla.cvs
Message-ID <[email protected]>
Update of /cvsroot/jicarilla/jicarilla-sandbox/platform/components/http/api/src/java/org/jicarilla/http
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2537/components/http/api/src/java/org/jicarilla/http

Modified Files:
	HTTPEncoding.java HTTPException.java HTTPField.java 
	HTTPMessage.java HTTPParser.java 
Log Message:
Ran some code analysis tools on the code and changed approximately 200 small things based on that. Nothing shocking (I hope!)

Index: HTTPEncoding.java
===================================================================
RCS file: /cvsroot/jicarilla/jicarilla-sandbox/platform/components/http/api/src/java/org/jicarilla/http/HTTPEncoding.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- HTTPEncoding.java	11 Jan 2004 12:28:11 -0000	1.3
+++ HTTPEncoding.java	26 Feb 2004 16:51:54 -0000	1.4
@@ -269,32 +269,37 @@
      */
     public final static char[] transfer_coding;
 
+    public final static int OFFSET_OF_NORMAL_CHARACTERS_IN_ASCII = 0x20;
+    public final static int NUMBER_OF_TEXT_CHARACTERS = 127-32;
+    public final static int NUMBER_OF_HEX_CHARACTERS = 6+6+10;
+    public final static int NUMBER_OF_VERSION_CHARACTERS = 15;
+    public final static int NUMBER_OF_TOKEN_CHARACTERS = 80;
     // fill in the above character classes
     static
     {
         int index;
 
-        TEXT = new char[127-32];
+        TEXT = new char[NUMBER_OF_TEXT_CHARACTERS];
         for( int i = 0; i < TEXT.length; i++ )
         {
-            TEXT[i] = (char) (i + 0x20);
+            TEXT[i] = (char) (i + OFFSET_OF_NORMAL_CHARACTERS_IN_ASCII);
         }
         Arrays.sort(TEXT);
 
-        HEX = new char[6+6+10];
+        HEX = new char[NUMBER_OF_HEX_CHARACTERS];
         for( int i = 0; i < 7; i++ )
             HEX[i] = UPALPHA[i];
         for( int i = 0; i < 7; i++ )
             HEX[i+6] = LOALPHA[i];
         for( int i = 0; i < 10; i++ )
-            HEX[i+12] = DIGIT[i];
+            HEX[i+6+6] = DIGIT[i];
         Arrays.sort(HEX);
 
         Arrays.sort(separators);
 
         // won't work:
         // token = new char[(CHAR.length-CTL.length)-separators.length-2];
-        token = new char[80];
+        token = new char[NUMBER_OF_TOKEN_CHARACTERS];
         index = 0;
         for( int i = 0; i < CHAR.length; i++)
         {
@@ -333,7 +338,7 @@
         quoted_string = CHAR;
         quoted_pair = CHAR;
 
-        VERSION = new char[15];
+        VERSION = new char[NUMBER_OF_VERSION_CHARACTERS];
         VERSION[0] = Iso646.LATIN_CAPITAL_LETTER_H;
         VERSION[1] = Iso646.LATIN_CAPITAL_LETTER_T;
         VERSION[2] = Iso646.LATIN_CAPITAL_LETTER_P;
@@ -534,27 +539,28 @@
 
     public final static String STATUS_999_MSG = "IO Problem";
 
-    public final static String[] STATUS_MSG = new String[1000];
+    public final static int NUMBER_OF_STATUS_MSG = 1000;
+    public final static String[] STATUS_MSG = new String[NUMBER_OF_STATUS_MSG];
     static
     {
         // perform some runtime-introspection to getEntry all those
         // status messages listed above into the indexed array
         // STATUS_MSG
-        Field[] fields = HTTPEncoding.class.getFields();
+        final Field[] fields = HTTPEncoding.class.getFields();
         for( int i = 0; i < fields.length; i++ )
         {
-            Pattern pattern = Pattern.compile( "STATUS_([0-9][0-9][0-9])_MSG" );
+            final Pattern pattern = Pattern.compile( "STATUS_([0-9][0-9][0-9])_MSG" );
             if(
                     Modifier.isStatic( fields[i].getModifiers() ) &&
                     Modifier.isFinal( fields[i].getModifiers() ) &&
                     Modifier.isPublic( fields[i].getModifiers() ) &&
                     fields[i].getType().equals( String.class ) )
             {
-                Matcher matcher = pattern.matcher( fields[i].getName() );
+                final Matcher matcher = pattern.matcher( fields[i].getName() );
                 if(matcher.matches())
                 {
-                    String code = matcher.group(1);
-                    int num = (new Integer( code )).intValue();
+                    final String code = matcher.group(1);
+                    final int num = (new Integer( code )).intValue();
                     try
                     {
                         STATUS_MSG[num] = (String)fields[i].get( null );
@@ -594,7 +600,7 @@
 
     static
     {
-        byte[] arr = HEADER_CONTENT_LENGTH.getBytes();
+        final byte[] arr = HEADER_CONTENT_LENGTH.getBytes();
         HEADER_CONTENT_LENGTH_BUFFER = ByteBuffer.wrap( arr );
     }
 
@@ -609,7 +615,7 @@
      * @param c the character to test
      * @return true if it is, false otherwise
      */
-    public final static boolean isControlChar( char c )
+    public final static boolean isControlChar( final char c )
     {
         if( Arrays.binarySearch( CTL, c ) >= 0 )
             return true;
@@ -623,7 +629,7 @@
      * @param c the character to test
      * @return true if it is, false otherwise
      */
-    public final static boolean isSeparatorChar( char c )
+    public final static boolean isSeparatorChar( final char c )
     {
         if( Arrays.binarySearch( separators, c ) >= 0 )
             return true;
@@ -637,7 +643,7 @@
      * @param c the character to test
      * @return true if it is, false otherwise
      */
-    public final static boolean isTokenChar( char c )
+    public final static boolean isTokenChar( final char c )
     {
         if( !isSeparatorChar( c ) && !isControlChar( c ) )
             return true;
@@ -651,7 +657,7 @@
      * @param c the character to test
      * @return true if it is, false otherwise
      */
-    public final static boolean isTextChar( char c )
+    public final static boolean isTextChar( final char c )
     {
         return !isControlChar( c );
     }
@@ -662,7 +668,7 @@
      * @param c the character to test
      * @return true if it is, false otherwise
      */
-    public final static boolean isMethodChar( char c )
+    public final static boolean isMethodChar( final char c )
     {
         return isTokenChar( c );
     }
@@ -673,9 +679,9 @@
      * @param c the character to test
      * @return true if it is, false otherwise
      */
-    public final static boolean isLWSChar( char c )
+    public final static boolean isLWSChar( final char c )
     {
-        return (c == CR || c == LF || c == SP || c == HT);
+        return c == CR || c == LF || c == SP || c == HT;
     }
     /**
      * Determine whether the specified character is a status code
@@ -684,7 +690,7 @@
      * @param c the character to test
      * @return true if it is, false otherwise
      */
-    public final static boolean isStatusCodeChar( char c )
+    public final static boolean isStatusCodeChar( final char c )
     {
         if( Arrays.binarySearch( DIGIT, c ) >= 0 )
             return true;
@@ -698,7 +704,7 @@
      * @param c the character to test
      * @return true if it is, false otherwise
      */
-    public final static boolean isReasonPhraseChar( char c )
+    public final static boolean isReasonPhraseChar( final char c )
     {
         if( Arrays.binarySearch( TEXT, c ) < 0 )
             return false;
@@ -746,7 +752,7 @@
      * @param c the character to test
      * @return true if it is a valid URI char, false otherwise
      */
-    public final static boolean isURIChar( char c )
+    public final static boolean isURIChar( final char c )
     {
         if( isControlChar( c ) )
             return false;
@@ -765,7 +771,7 @@
      * @param c the character to test
      * @return true if it is, false otherwise
      */
-    public final static boolean isVersionChar( char c )
+    public final static boolean isVersionChar( final char c )
     {
         final int contained = Arrays.binarySearch( VERSION, c );
         if( contained >= 0 )
@@ -780,7 +786,7 @@
      * @param s
      * @return
      */
-    public final static boolean isVersionString( String s )
+    public final static boolean isVersionString( final String s )
     {
         if( s == null )
             return false;
@@ -804,7 +810,7 @@
         return true;
     }
 
-    public final static int getMajorVersion( String versionString )
+    public final static int getMajorVersion( final String versionString )
     {
         if( !isVersionString(versionString) )
             throw new IllegalArgumentException( "Not a valid HTTP version string!" );
@@ -821,7 +827,7 @@
 
         return new Integer( version.toString() ).intValue();
     }
-    public final static int getMinorVersion( String versionString )
+    public final static int getMinorVersion( final String versionString )
     {
         if( !isVersionString(versionString) )
             throw new IllegalArgumentException( "Not a valid HTTP version string!" );
@@ -830,11 +836,12 @@
                 versionString.substring( versionString.indexOf( Iso646.SOLIDUS ) ) ).intValue();
     }
 
-    public final static char tokenCharToLowerCase( char token )
+    public final static int NUMBER_OF_CHARS_TO_SHIFT_ASCII_UPPER_TO_LOWER = 32;
+    public final static char tokenCharToLowerCase( final char token )
     {
         if(     token >= Iso646.LATIN_CAPITAL_LETTER_A &&
                 token <= Iso646.LATIN_CAPITAL_LETTER_Z)
-            return (char)(token + 32);
+            return (char)(token + NUMBER_OF_CHARS_TO_SHIFT_ASCII_UPPER_TO_LOWER);
 
         return token;
     }

Index: HTTPException.java
===================================================================
RCS file: /cvsroot/jicarilla/jicarilla-sandbox/platform/components/http/api/src/java/org/jicarilla/http/HTTPException.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- HTTPException.java	19 Jan 2004 21:54:55 -0000	1.3
+++ HTTPException.java	26 Feb 2004 16:51:54 -0000	1.4
@@ -59,34 +59,34 @@
     {
         super( HTTPEncoding.STATUS_MSG[DEFAULT_CODE] );
     }
-    public HTTPException( int code )
+    public HTTPException( final int code )
     {
         super( HTTPEncoding.STATUS_MSG[code] );
 
         m_code = code;
     }
-    public HTTPException( String message )
+    public HTTPException( final String message )
     {
         super( message );
     }
-    public HTTPException( int code, Throwable t )
+    public HTTPException( final int code, final Throwable t )
     {
         super( HTTPEncoding.STATUS_MSG[code], t );
 
         m_code = code;
     }
-    public HTTPException( String message, Throwable t )
+    public HTTPException( final String message, final Throwable t )
     {
         super( message, t );
     }
-    public HTTPException( int code, String message )
+    public HTTPException( final int code, final String message )
     {
         super( message );
 
         m_code = code;
     }
 
-    public HTTPException( int code, String message, Throwable t )
+    public HTTPException( final int code, final String message, final Throwable t )
     {
         super( message, t );
 
@@ -105,7 +105,7 @@
     //  Equals and HashCode
     // ----------------------------------------------------------------------
 
-    public boolean equals( Object o )
+    public boolean equals( final Object o )
     {
         if( this == o ) return true;
         if( !(o instanceof HTTPException) ) return false;

Index: HTTPField.java
===================================================================
RCS file: /cvsroot/jicarilla/jicarilla-sandbox/platform/components/http/api/src/java/org/jicarilla/http/HTTPField.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- HTTPField.java	11 Jan 2004 12:28:11 -0000	1.3
+++ HTTPField.java	26 Feb 2004 16:51:54 -0000	1.4
@@ -122,7 +122,7 @@
      * @param name The name.
      * @param value The value.
      */
-    public HTTPField( ByteBuffer name, ByteBuffer value )
+    public HTTPField( final ByteBuffer name, final ByteBuffer value )
     {
         m_name = name;
         m_value = value;
@@ -138,7 +138,7 @@
      * @param name The new name
      * @see #getName()
      */
-    public void setName( ByteBuffer name )
+    public void setName( final ByteBuffer name )
     {
         m_name = name;
     }
@@ -164,7 +164,7 @@
      *
      * @param value The new value.
      */
-    public void setValue( ByteBuffer value )
+    public void setValue( final ByteBuffer value )
     {
         m_value = value;
     }
@@ -197,16 +197,16 @@
      * @param object the {@link java.lang.Object} to compare to
      * @return true if the objects are equal.
      */
-    public boolean equals( Object object )
+    public boolean equals( final Object object )
     {
         if( this == object )
         {
             return true;
         } else if( this.getClass().equals( object.getClass() ) )
         {
-            HTTPField pair = (HTTPField) object;
-            return ((null == m_name ? null == pair.m_name : m_name.equals( pair.m_name ))
-                    && (null == m_value ? null == pair.m_value : m_value.equals( pair.m_value )));
+            final HTTPField pair = (HTTPField) object;
+            return (null == m_name ? null == pair.m_name : m_name.equals( pair.m_name ))
+                    && (null == m_value ? null == pair.m_value : m_value.equals( pair.m_value ));
         } else
         {
             return false;
@@ -220,9 +220,9 @@
      */
     public int hashCode()
     {
-        return (this.getClass().hashCode()
+        return this.getClass().hashCode()
                 ^ (null == m_name ? 0 : m_name.hashCode())
-                ^ (null == m_value ? 0 : m_value.hashCode()));
+                ^ (null == m_value ? 0 : m_value.hashCode());
     }
 
     /**
@@ -233,7 +233,7 @@
      */
     public String toExternalForm()
     {
-        StringBuffer buffer = new StringBuffer();
+        final StringBuffer buffer = new StringBuffer();
         NioUtil.append( buffer, m_name );
         buffer.append( ": " );
         NioUtil.append( buffer, m_value );

Index: HTTPMessage.java
===================================================================
RCS file: /cvsroot/jicarilla/jicarilla-sandbox/platform/components/http/api/src/java/org/jicarilla/http/HTTPMessage.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- HTTPMessage.java	20 Feb 2004 14:21:42 -0000	1.4
+++ HTTPMessage.java	26 Feb 2004 16:51:54 -0000	1.5
@@ -58,8 +58,8 @@
     protected ByteBuffer m_field2;
     protected ByteBuffer m_field3;
 
-    protected ArrayList m_headers;
-    protected LinkedList m_bodyParts;
+    protected List m_headers;
+    protected List m_bodyParts;
 
     // ----------------------------------------------------------------------
     //  Constructors
@@ -86,7 +86,7 @@
      * @param isRequest true if the message should behave like a
      *     request, false if it should behave like a response
      */
-    public void setMessageType( boolean isRequest )
+    public void setMessageType( final boolean isRequest )
     {
         m_isRequest = isRequest;
     }
@@ -110,7 +110,7 @@
         return m_isComplete;
     }
 
-    public void setComplete( boolean complete )
+    public void setComplete( final boolean complete )
     {
         m_isComplete = complete;
     }
@@ -120,7 +120,7 @@
      *
      * @param field the first HTTP header line field
      */
-    public void setField1( ByteBuffer field )
+    public void setField1( final ByteBuffer field )
     {
         m_field1 = field;
     }
@@ -146,7 +146,7 @@
         return NioUtil.toString( getField1() );
     }
 
-    public void setField1( String field )
+    public void setField1( final String field )
     {
         setField1( NioUtil.toByteBuffer( field ) );
     }
@@ -156,7 +156,7 @@
      *
      * @param field2 the second HTTP header line field
      */
-    public void setField2( ByteBuffer field2 )
+    public void setField2( final ByteBuffer field2 )
     {
         m_field2 = field2;
     }
@@ -182,7 +182,7 @@
         return NioUtil.toString( getField2() );
     }
 
-    public void setField2( String field )
+    public void setField2( final String field )
     {
         setField2( NioUtil.toByteBuffer( field ) );
     }
@@ -191,7 +191,7 @@
      *
      * @param field the third HTTP header line field
      */
-    public void setField3( ByteBuffer field )
+    public void setField3( final ByteBuffer field )
     {
         m_field3 = field;
     }
@@ -217,7 +217,7 @@
         return NioUtil.toString( getField3() );
     }
 
-    public void setField3( String field )
+    public void setField3( final String field )
     {
         setField3( NioUtil.toByteBuffer( field ) );
     }
@@ -228,12 +228,12 @@
      * @param name The new header name
      * @param value The new header value
      */
-    public void addHeader( ByteBuffer name, ByteBuffer value )
+    public void addHeader( final ByteBuffer name, final ByteBuffer value )
     {
         m_headers.add( new HTTPField( name, value ) );
     }
 
-    public void addHeader( String name, String value )
+    public void addHeader( final String name, final String value )
     {
         addHeader( NioUtil.toByteBuffer( name ), NioUtil.toByteBuffer( value ) );
     }
@@ -255,17 +255,17 @@
      *
      * @param buffer the body part to append
      */
-    public void addBodyPart( ByteBuffer buffer )
+    public void addBodyPart( final ByteBuffer buffer )
     {
         m_bodyParts.add( buffer );
     }
 
-    public void addBodyPart( String string )
+    public void addBodyPart( final String string )
     {
         m_bodyParts.add( NioUtil.toByteBuffer( string ) );
     }
 
-    public void addBodyParts( ByteBuffer[] buffers )
+    public void addBodyParts( final ByteBuffer[] buffers )
     {
         for( int i = 0; i < buffers.length; i++ )
             addBodyPart( buffers[i] );
@@ -283,8 +283,8 @@
 
     public String getBodyAsString()
     {
-        ByteBuffer[] buf = getBodyParts();
-        String body = NioUtil.toString( buf ); // ouch!
+        final ByteBuffer[] buf = getBodyParts();
+        final String body = NioUtil.toString( buf ); // ouch!
         return body;
     }
 
@@ -298,14 +298,14 @@
         //    throw new IllegalStateException( "We're not a response!" );
 
         // status code is the second field
-        String val = getField2String();
+        final String val = getField2String();
         return new Integer( val ).intValue();
     }
-    public void setStatusCode( ByteBuffer statusCode )
+    public void setStatusCode( final ByteBuffer statusCode )
     {
         setField2( statusCode );
     }
-    public void setStatusCode( int code )
+    public void setStatusCode( final int code )
     {
         setStatusCode( NioUtil.toByteBuffer( code ) );
     }

Index: HTTPParser.java
===================================================================
RCS file: /cvsroot/jicarilla/jicarilla-sandbox/platform/components/http/api/src/java/org/jicarilla/http/HTTPParser.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- HTTPParser.java	4 Jan 2004 16:10:17 -0000	1.2
+++ HTTPParser.java	26 Feb 2004 16:51:54 -0000	1.3
@@ -71,17 +71,17 @@
      * Return this from Handler.getBodyType() if there is no
      * message body.
      */
-    public final static int BODY_TYPE_NONE = 1;
+    int BODY_TYPE_NONE = 1;
     /**
      * Return this from Handler.getBodyType() if the message
      * body is chunked.
      */
-    public final static int BODY_TYPE_CHUNKING = 2;
+    int BODY_TYPE_CHUNKING = 2;
     /**
      * Return this from Handler.getBodyType() if the
      * message body is 'normal' (whatever that means).
      */
-    public final static int BODY_TYPE_NORMAL = 3;
+    int BODY_TYPE_NORMAL = 3;
 
     void reset();
 



-------------------------------------------------------
SF.Net is sponsored by: Speed Start Your Linux Apps Now.
Build and deploy apps & Web services for Linux with
a free DVD software kit from IBM. Click Now!
http://ads.osdn.com/?ad_id=1356&alloc_id=3438&op=click
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.