You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2012/01/10 21:54:52 UTC

svn commit: r1229724 - /tomcat/trunk/java/org/apache/tomcat/util/buf/C2BConverter.java

Author: markt
Date: Tue Jan 10 20:54:50 2012
New Revision: 1229724

URL: http://svn.apache.org/viewvc?rev=1229724&view=rev
Log:
Whitespace and Javadoc fixes. No functional change.

Modified:
    tomcat/trunk/java/org/apache/tomcat/util/buf/C2BConverter.java

Modified: tomcat/trunk/java/org/apache/tomcat/util/buf/C2BConverter.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/buf/C2BConverter.java?rev=1229724&r1=1229723&r2=1229724&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/util/buf/C2BConverter.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/util/buf/C2BConverter.java Tue Jan 10 20:54:50 2012
@@ -21,12 +21,12 @@ import java.io.OutputStream;
 import java.io.OutputStreamWriter;
 import java.nio.charset.Charset;
 
-/** Efficient conversion of character to bytes.
- *
- *  This uses the standard JDK mechanism - a writer - but provides mechanisms
- *  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 )
+/**
+ * Efficient conversion of character to bytes.
  *
+ * This uses the standard JDK mechanism - a writer - but provides mechanisms 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).
  */
 public final class C2BConverter {
 
@@ -37,74 +37,75 @@ public final class C2BConverter {
     /** Create a converter, with bytes going to a byte buffer
      */
     public C2BConverter(ByteChunk output, String encoding) throws IOException {
-        this.bb=output;
-        ios=new IntermediateOutputStream( output );
-        conv=new WriteConvertor( ios, B2CConverter.getCharset(encoding));
+        this.bb = output;
+        ios = new IntermediateOutputStream(output);
+        conv = new WriteConvertor(ios, B2CConverter.getCharset(encoding));
     }
 
-    /** Reset the internal state, empty the buffers.
-     *  The encoding remain in effect, the internal buffers remain allocated.
+    /**
+     * Reset the internal state, empty the buffers.
+     * The encoding remain in effect, the internal buffers remain allocated.
      */
-    public  final void recycle() {
+    public final void recycle() {
         conv.recycle();
         bb.recycle();
     }
 
-    /** Generate the bytes using the specified encoding
+    /**
+     * Generate the bytes using the specified encoding.
      */
-    public  final void convert(char c[], int off, int len ) throws IOException {
-        conv.write( c, off, len );
+    public final void convert(char c[], int off, int len) throws IOException {
+        conv.write(c, off, len);
     }
 
-    /** Generate the bytes using the specified encoding
+    /**
+     * Generate the bytes using the specified encoding.
      */
-    public  final void convert(String s, int off, int len ) throws IOException {
-        conv.write( s, off, len );
+    public final void convert(String s, int off, int len) throws IOException {
+        conv.write(s, off, len);
     }
 
-    /** Generate the bytes using the specified encoding
+    /**
+     * Generate the bytes using the specified encoding.
      */
-    public  final void convert(String s ) throws IOException {
-        conv.write( s );
+    public final void convert(String s) throws IOException {
+        conv.write(s);
     }
 
-    /** Generate the bytes using the specified encoding
+    /**
+     * Generate the bytes using the specified encoding.
      */
-    public  final void convert(char c ) throws IOException {
-        conv.write( c );
+    public final void convert(char c) throws IOException {
+        conv.write(c);
     }
 
-    /** Flush any internal buffers into the ByteOutput or the internal
-     *  byte[]
+    /**
+     * Flush any internal buffers into the ByteOutput or the internal byte[].
      */
-    public  final void flushBuffer() throws IOException {
+    public final void flushBuffer() throws IOException {
         conv.flush();
     }
 }
 
 // -------------------- Private implementation --------------------
-
-
-
 /**
- *  Special writer class, where close() is overridden. The default implementation
- *  would set byteOutputter to null, and the writer can't be recycled.
- *
- *  Note that the flush method will empty the internal buffers _and_ call
- *  flush on the output stream - that's why we use an intermediary output stream
- *  that overrides flush(). The idea is to  have full control: flushing the
- *  char->byte converter should be independent of flushing the OutputStream.
- *
- *  When a WriteConverter is created, it'll allocate one or 2 byte buffers,
- *  with a 8k size that can't be changed ( at least in JDK1.1 -> 1.4 ). It would
- *  also allocate a ByteOutputter or equivalent - again some internal buffers.
- *
- *  It is essential to keep  this object around and reuse it. You can use either
- *  pools or per thread data - but given that in most cases a converter will be
- *  needed for every thread and most of the time only 1 ( or 2 ) encodings will
- *  be used, it is far better to keep it per thread and eliminate the pool
- *  overhead too.
+ * Special writer class, where close() is overridden. The default implementation
+ * would set byteOutputter to null, and the writer can't be recycled.
  *
+ * Note that the flush method will empty the internal buffers _and_ call
+ * flush on the output stream - that's why we use an intermediary output stream
+ * that overrides flush(). The idea is to  have full control: flushing the
+ * char->byte converter should be independent of flushing the OutputStream.
+ *
+ * When a WriteConverter is created, it'll allocate one or 2 byte buffers,
+ * with a 8k size that can't be changed ( at least in JDK1.1 -> 1.4 ). It would
+ * also allocate a ByteOutputter or equivalent - again some internal buffers.
+ *
+ * It is essential to keep  this object around and reuse it. You can use either
+ * pools or per thread data - but given that in most cases a converter will be
+ * needed for every thread and most of the time only 1 ( or 2 ) encodings will
+ * be used, it is far better to keep it per thread and eliminate the pool
+ * overhead too.
  */
  final class WriteConvertor extends OutputStreamWriter {
     // stream with flush() and close(). overridden.
@@ -112,81 +113,83 @@ public final class C2BConverter {
 
     // Has a private, internal byte[8192]
 
-    /** Create a converter.
+    /**
+     * Create a converter.
      */
     public WriteConvertor(IntermediateOutputStream out, Charset charset) {
         super(out, charset);
-        ios=out;
+        ios = out;
     }
 
-    /** Overridden - will do nothing but reset internal state.
+    /**
+     * This is a NOOP.
      */
     @Override
-    public  final void close() throws IOException {
+    public final void close() throws IOException {
         // NOTHING
         // Calling super.close() would reset out and cb.
     }
 
     /**
-     *  Flush the characters only
+     *  Flush the characters only.
      */
     @Override
-    public  final void flush() throws IOException {
+    public final void flush() throws IOException {
         // Will flushBuffer and out()
         // flushBuffer put any remaining chars in the byte[]
         super.flush();
     }
 
     @Override
-    public  final void write(char cbuf[], int off, int len) throws IOException {
-        // will do the conversion and call write on the output stream
+    public final void write(char cbuf[], int off, int len) throws IOException {
+        // Will do the conversion and call write on the output stream
         super.write( cbuf, off, len );
     }
 
-    /** Reset the buffer
+    /**
+     * Reset the buffer.
      */
     public  final void recycle() {
         ios.disable();
         try {
-            // System.out.println("Reseting writer");
             flush();
         } catch( Exception ex ) {
             ex.printStackTrace();
         }
         ios.enable();
     }
-
 }
 
 
-/** Special output stream where close() is overridden, so super.close()
-    is never called.
-
-    This allows recycling. It can also be disabled, so callbacks will
-    not be called if recycling the converter and if data was not flushed.
-*/
+/**
+ * Special output stream where close() is overridden, so super.close()
+ * is never called.
+ *
+ * This allows recycling. It can also be disabled, so callbacks will
+ * not be called if recycling the converter and if data was not flushed.
+ */
 final class IntermediateOutputStream extends OutputStream {
     private final ByteChunk tbuff;
-    private boolean enabled=true;
+    private boolean enabled = true;
 
     public IntermediateOutputStream(ByteChunk tbuff) {
         this.tbuff=tbuff;
     }
 
     @Override
-    public  final void close() throws IOException {
+    public final void close() throws IOException {
         // shouldn't be called - we filter it out in writer
         throw new IOException("close() called - shouldn't happen ");
     }
 
     @Override
-    public  final void flush() throws IOException {
+    public final void flush() throws IOException {
         // nothing - write will go directly to the buffer,
         // we don't keep any state
     }
 
     @Override
-    public  final  void write(byte cbuf[], int off, int len) throws IOException {
+    public final void write(byte cbuf[], int off, int len) throws IOException {
         // will do the conversion and call write on the output stream
         if( enabled ) {
             tbuff.append( cbuf, off, len );
@@ -194,22 +197,24 @@ final class IntermediateOutputStream ext
     }
 
     @Override
-    public  final void write( int i ) throws IOException {
+    public final void write(int i) throws IOException {
         throw new IOException("write( int ) called - shouldn't happen ");
     }
 
     // -------------------- Internal methods --------------------
 
-    /** Temporary disable - this is used to recycle the converter without
-     *  generating an output if the buffers were not flushed
+    /**
+     * Temporary disable - this is used to recycle the converter without
+     * generating an output if the buffers were not flushed.
      */
     final void disable() {
-        enabled=false;
+        enabled = false;
     }
 
-    /** Reenable - used to recycle the converter
+    /**
+     * Re-enable - used to recycle the converter.
      */
     final void enable() {
-        enabled=true;
+        enabled = true;
     }
 }



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