You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by co...@apache.org on 2005/11/24 06:31:30 UTC

svn commit: r348663 - in /tomcat/sandbox/java/org/apache/tomcat/util/buf: B2CConverter.java ByteChunk.java C2BConverter.java MessageBytes.java TimeStamp.java UDecoder.java UTF8Decoder.java

Author: costin
Date: Wed Nov 23 21:31:25 2005
New Revision: 348663

URL: http://svn.apache.org/viewcvs?rev=348663&view=rev
Log:
Various fixes and deprecations

Modified:
    tomcat/sandbox/java/org/apache/tomcat/util/buf/B2CConverter.java
    tomcat/sandbox/java/org/apache/tomcat/util/buf/ByteChunk.java
    tomcat/sandbox/java/org/apache/tomcat/util/buf/C2BConverter.java
    tomcat/sandbox/java/org/apache/tomcat/util/buf/MessageBytes.java
    tomcat/sandbox/java/org/apache/tomcat/util/buf/TimeStamp.java
    tomcat/sandbox/java/org/apache/tomcat/util/buf/UDecoder.java
    tomcat/sandbox/java/org/apache/tomcat/util/buf/UTF8Decoder.java

Modified: tomcat/sandbox/java/org/apache/tomcat/util/buf/B2CConverter.java
URL: http://svn.apache.org/viewcvs/tomcat/sandbox/java/org/apache/tomcat/util/buf/B2CConverter.java?rev=348663&r1=348662&r2=348663&view=diff
==============================================================================
--- tomcat/sandbox/java/org/apache/tomcat/util/buf/B2CConverter.java (original)
+++ tomcat/sandbox/java/org/apache/tomcat/util/buf/B2CConverter.java Wed Nov 23 21:31:25 2005
@@ -32,6 +32,8 @@
  *  Not used in the current code, the performance gain is not very big
  *  in the current case ( since String is created anyway ), but it will
  *  be used in a later version or after the remaining optimizations.
+ *  
+ *  @deprecated use CharsetDecoder using the ByteBuffer
  */
 public class B2CConverter {
     

Modified: tomcat/sandbox/java/org/apache/tomcat/util/buf/ByteChunk.java
URL: http://svn.apache.org/viewcvs/tomcat/sandbox/java/org/apache/tomcat/util/buf/ByteChunk.java?rev=348663&r1=348662&r2=348663&view=diff
==============================================================================
--- tomcat/sandbox/java/org/apache/tomcat/util/buf/ByteChunk.java (original)
+++ tomcat/sandbox/java/org/apache/tomcat/util/buf/ByteChunk.java Wed Nov 23 21:31:25 2005
@@ -688,6 +688,12 @@
 	    if( bb.get(i) != first ) continue;
 	    // found first char, now look for a match
             int myPos=i+1;
+
+            // not enough chars to have a match
+            if( i + srcLen >= end ) {
+                break;
+            }
+            
 	    for( int srcPos=srcOff + 1; srcPos< srcEnd; ) {
                 if( bb.get(myPos++) != src.charAt( srcPos++ ))
 		    break;
@@ -815,6 +821,7 @@
      * 
      * @param value to convert to byte array
      * @return the byte array value
+     * @deprecated WRONG, if ascii is all you need - rename the method !
      */
     public static final byte[] convertToBytes(String value) {
         byte[] result = new byte[value.length()];

Modified: tomcat/sandbox/java/org/apache/tomcat/util/buf/C2BConverter.java
URL: http://svn.apache.org/viewcvs/tomcat/sandbox/java/org/apache/tomcat/util/buf/C2BConverter.java?rev=348663&r1=348662&r2=348663&view=diff
==============================================================================
--- tomcat/sandbox/java/org/apache/tomcat/util/buf/C2BConverter.java (original)
+++ tomcat/sandbox/java/org/apache/tomcat/util/buf/C2BConverter.java Wed Nov 23 21:31:25 2005
@@ -27,6 +27,7 @@
  *  to recycle all the objects that are used. It is compatible with JDK1.1 and up,
  *  ( nio is better, but it's not available even in 1.2 or 1.3 )
  * 
+ * @deprecated Use CharsetEncoder on the ByteBuffer
  */
 public final class C2BConverter {
     
@@ -48,19 +49,23 @@
     }
 
     /** Create a converter
+     * Not used.
      */
     public C2BConverter(String encoding) throws IOException {
 	this( new ByteChunk(1024), encoding );
     }
 
+    // Not used
     public ByteChunk getByteChunk() {
 	return bb;
     }
 
+    // not used
     public String getEncoding() {
         return enc;
     }
 
+    // internal use only
     public void setByteChunk(ByteChunk bb) {
 	this.bb=bb;
 	ios.setByteChunk( bb );
@@ -97,7 +102,7 @@
     public final void convert(MessageBytes mb ) throws IOException {
         int type=mb.getType();
         if( type==MessageBytes.T_BYTES )
-            return;
+            return; // why ?
         ByteChunk orig=bb;
         setByteChunk( mb.getByteChunk());
         bb.recycle();

Modified: tomcat/sandbox/java/org/apache/tomcat/util/buf/MessageBytes.java
URL: http://svn.apache.org/viewcvs/tomcat/sandbox/java/org/apache/tomcat/util/buf/MessageBytes.java?rev=348663&r1=348662&r2=348663&view=diff
==============================================================================
--- tomcat/sandbox/java/org/apache/tomcat/util/buf/MessageBytes.java (original)
+++ tomcat/sandbox/java/org/apache/tomcat/util/buf/MessageBytes.java Wed Nov 23 21:31:25 2005
@@ -27,7 +27,16 @@
  * delayed and cached. Everything is recyclable.
  *
  * The object can represent a byte[], a char[], or a (sub) String. All
- * operations can be made in case sensitive mode or not.
+ * operations can be made in case sensitive mode or not. The byte[] 
+ * representation is the primary one - String and char[] are used for caching
+ * or as temporary storage. 
+ * 
+ * This class should be used for buffer operations as well, instead of 
+ * directly using ByteChunk, CharChunk, C2B and B2C encoders, which will be
+ * deprecated for public use. Eventually the implementation may use directly
+ * ByteBuffers or perform optimizations to avoid copy on grow. It is also easier
+ * to deal with a single class with a ( somehow ) consistent API.
+ *  
  *
  * @author dac@eng.sun.com
  * @author James Todd [gonzo@eng.sun.com]
@@ -72,7 +81,7 @@
      */
     public MessageBytes() {
     }
-
+    
     /** Construct a new MessageBytes instance
      */
     public static MessageBytes newInstance() {
@@ -113,9 +122,18 @@
 	hasStrValue=false;
 	hasHashCode=false;
 	hasIntValue=false;
-    hasLongValue=false;
+        hasLongValue=false;
 	hasDateValue=false;	
     }
+    
+    /** Allocate a byte buffer to use.
+     * 
+     * @param initial
+     * @param limit
+     */
+    public void allocate( int initial, int limit ) {
+       byteC.allocate(initial, limit); 
+    }
 
 
     /**
@@ -244,13 +262,16 @@
 	return strValue;
     }
 
-    /** Unimplemented yet. Do a char->byte conversion.
+    /** Do a char->byte conversion.
      */
     public void toBytes() {
         if( ! byteC.isNull() ) {
             type=T_BYTES;
             return;
         }
+        if( type== T_BYTES) {
+            return;
+        }
         toString();
         type=T_BYTES;
         byte bb[] = strValue.getBytes();
@@ -530,6 +551,30 @@
 	    break;
 	}
     }
+    
+    // -------------------- Flushing ------------------------- 
+    
+    // -------------------- Adding data -----------------------
+    
+    public void append( byte b ) {
+        
+    }
+    
+    public void append( byte b[], int off, int len ) {
+        
+    }
+    
+    public void append( char c ) {
+        
+    }
+    
+    public void append( char b[], int off, int len ) {
+        
+    }
+    
+    public void append( MessageBytes mb ) {
+        
+    }
 
     // -------------------- Deprecated code --------------------
     // efficient int, long and date
@@ -724,8 +769,8 @@
     public static class MessageBytesFactory {
 	protected MessageBytesFactory() {
 	}
-	public MessageBytes newInstance() {
-	    return new MessageBytes();
-	}
+        public MessageBytes newInstance() {
+            return new MessageBytes();
+        }
     }
 }

Modified: tomcat/sandbox/java/org/apache/tomcat/util/buf/TimeStamp.java
URL: http://svn.apache.org/viewcvs/tomcat/sandbox/java/org/apache/tomcat/util/buf/TimeStamp.java?rev=348663&r1=348662&r2=348663&view=diff
==============================================================================
--- tomcat/sandbox/java/org/apache/tomcat/util/buf/TimeStamp.java (original)
+++ tomcat/sandbox/java/org/apache/tomcat/util/buf/TimeStamp.java Wed Nov 23 21:31:25 2005
@@ -29,6 +29,8 @@
  * also Contexts, Servlets, cache - or any other object that
  * expires.
  * 
+ * Currently used in util.threads.Expirer, may be better to move there.
+ * 
  * @author Costin Manolache
  */
 public final class TimeStamp implements  Serializable {

Modified: tomcat/sandbox/java/org/apache/tomcat/util/buf/UDecoder.java
URL: http://svn.apache.org/viewcvs/tomcat/sandbox/java/org/apache/tomcat/util/buf/UDecoder.java?rev=348663&r1=348662&r2=348663&view=diff
==============================================================================
--- tomcat/sandbox/java/org/apache/tomcat/util/buf/UDecoder.java (original)
+++ tomcat/sandbox/java/org/apache/tomcat/util/buf/UDecoder.java Wed Nov 23 21:31:25 2005
@@ -24,7 +24,7 @@
  *  without adding complexity to the buffers.
  *
  *  The conversion will modify the original buffer.
- * 
+ *  
  *  @author Costin Manolache
  */
 public final class UDecoder {
@@ -105,6 +105,8 @@
     }
 
     /** In-buffer processing - the buffer will be modified
+     * IMPORTANT: this method doesn't work for UTF or other encodings !!
+     * Only the byte[] method works ( since it happens before charset decoding)
      */
     public void convert( CharChunk mb, boolean query )
 	throws IOException

Modified: tomcat/sandbox/java/org/apache/tomcat/util/buf/UTF8Decoder.java
URL: http://svn.apache.org/viewcvs/tomcat/sandbox/java/org/apache/tomcat/util/buf/UTF8Decoder.java?rev=348663&r1=348662&r2=348663&view=diff
==============================================================================
--- tomcat/sandbox/java/org/apache/tomcat/util/buf/UTF8Decoder.java (original)
+++ tomcat/sandbox/java/org/apache/tomcat/util/buf/UTF8Decoder.java Wed Nov 23 21:31:25 2005
@@ -29,6 +29,7 @@
  *
  * @author Costin Manolache
  * @author ( Xml-Xerces )
+ * @deprecated to be removed if not in use...
  */
 public final class UTF8Decoder extends B2CConverter {
     



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org