commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dgra...@apache.org
Subject cvs commit: jakarta-commons/validator/src/share/org/apache/commons/validator ValidatorAction.java
Date Sat, 10 Apr 2004 21:01:59 GMT
dgraham     2004/04/10 14:01:59

  Modified:    validator/src/share/org/apache/commons/validator
                        ValidatorAction.java
  Log:
  Simplified IO in readJavascriptFile() which should also fix PR: 28257.
  
  Revision  Changes    Path
  1.22      +16 -19    jakarta-commons/validator/src/share/org/apache/commons/validator/ValidatorAction.java
  
  Index: ValidatorAction.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/validator/src/share/org/apache/commons/validator/ValidatorAction.java,v
  retrieving revision 1.21
  retrieving revision 1.22
  diff -u -r1.21 -r1.22
  --- ValidatorAction.java	8 Apr 2004 23:29:31 -0000	1.21
  +++ ValidatorAction.java	10 Apr 2004 21:01:59 -0000	1.22
  @@ -21,8 +21,10 @@
   
   package org.apache.commons.validator;
   
  +import java.io.BufferedReader;
   import java.io.IOException;
   import java.io.InputStream;
  +import java.io.InputStreamReader;
   import java.io.Serializable;
   import java.lang.reflect.InvocationTargetException;
   import java.lang.reflect.Method;
  @@ -403,32 +405,27 @@
               return null;
           }
   
  -        StringBuffer function = new StringBuffer();
  +        StringBuffer buffer = new StringBuffer();
  +        BufferedReader reader = new BufferedReader(new InputStreamReader(is));
           try {
  -            int bufferSize = is.available();
  -            int bytesRead;
  -            while (bufferSize > 0) {
  -                byte[] buffer = new byte[bufferSize];
  -                bytesRead = is.read(buffer, 0, bufferSize);
  -                if (bytesRead > 0) {
  -                    String functionPart = new String(buffer,0,bytesRead);
  -                    function.append(functionPart);
  -                }
  -                bufferSize = is.available();
  +            String line = null;
  +            while ((line = reader.readLine()) != null) {
  +                buffer.append(line + "\n");
               }
   
           } catch(IOException e) {
  -            log.error("readJavascriptFile()", e);
  +            log.error("Error reading javascript file.", e);
   
           } finally {
               try {
  -                is.close();
  +                reader.close();
               } catch(IOException e) {
  -                log.error("readJavascriptFile()", e);
  +                log.error("Error closing stream to javascript file.", e);
               }
           }
  -        String strFunction = function.toString();
  -        return strFunction.equals("") ? null : strFunction;
  +        
  +        String function = buffer.toString();
  +        return function.equals("") ? null : function;
       }
   
       /**
  
  
  

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


Mime
View raw message