avalon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From leosim...@apache.org
Subject cvs commit: jakarta-avalon-apps/xcommander/src/java/org/apache/avalon/xcommander XCommanderHandler.java
Date Thu, 05 Sep 2002 09:42:39 GMT
leosimons    2002/09/05 02:42:39

  Modified:    xcommander/src/java/org/apache/avalon/xcommander
                        XCommanderHandler.java
  Log:
  applied patch from Greg Steuck <greg-xcommand-patch@nest.cx>:
  
  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:avalon-cvs-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:avalon-cvs-help@jakarta.apache.org>


Mime
View raw message