leosimons    2002/09/05 02:42:39

  Modified:    xcommander/src/java/org/apache/avalon/xcommander
                        XCommanderHandler.java
  Log:
  applied patch from Greg Steuck <[EMAIL PROTECTED]>:
  
  Hi Leo,
  
  I accdentaly looked into XCommanderHandler and couldn't bear the sight
  of String += char. So I rewrote it to store accumulated values into a
  CharArrayWriter until the whole thing is read. It is not the best that
  could be done, but it should be an improvement compared to what we
  had.
  
  Thanks
  Greg
  
  Revision  Changes    Path
  1.5       +9 -10     
jakarta-avalon-apps/xcommander/src/java/org/apache/avalon/xcommander/XCommanderHandler.java
  
  Index: XCommanderHandler.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-avalon-apps/xcommander/src/java/org/apache/avalon/xcommander/XCommanderHandler.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- XCommanderHandler.java    20 May 2002 10:20:18 -0000      1.4
  +++ XCommanderHandler.java    5 Sep 2002 09:42:39 -0000       1.5
  @@ -23,6 +23,7 @@
   import org.xml.sax.SAXException;
   import org.xml.sax.XMLReader;
   import org.xml.sax.helpers.XMLReaderFactory;
  +import java.io.CharArrayWriter;
   
   /**
    * This handles an individual incoming XCommander request.
  @@ -150,20 +151,18 @@
   
               // read the input. When a zero byte is encountered,
               // pass the input to the SAX parser.
  -            String inputLine;
  -            int streamResult;
  -            char buf[] = new char[ 1 ];
  +            final CharArrayWriter inputBuffer = new CharArrayWriter();
  +            int lastChar;
               do
               {
  -                inputLine = "";
  +                inputBuffer.reset();
   
  -                do
  +                while( (lastChar = m_in.read()) > 0 )
                   {
  -                    streamResult = m_in.read( buf, 0, 1 );
  -                    inputLine += buf[ 0 ];
  -                } while( buf[ 0 ] != '\u0000' );
  +                    inputBuffer.write( lastChar );
  +                }
   
  -                inputLine = inputLine.substring( 0, ( inputLine.length() - 1 ) );
  +                String inputLine = inputBuffer.toString();
   
                   if( -1 != inputLine.indexOf( "<command" ) )
                   {
  @@ -173,7 +172,7 @@
                       }
                       m_parser.parse( new InputSource( new StringReader( inputLine ) 
) );
                   }
  -            } while( streamResult != -1 );
  +            } while( lastChar != -1 );
   
               //Finish
               m_out.flush();
  
  
  

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to