avalon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dona...@apache.org
Subject cvs commit: jakarta-avalon-excalibur/io/src/java/org/apache/avalon/excalibur/io FileUtil.java
Date Tue, 03 Sep 2002 12:16:34 GMT
donaldp     2002/09/03 05:16:34

  Modified:    io/src/java/org/apache/avalon/excalibur/io FileUtil.java
  Log:
  here's the problem:
  catPath throws an ArrayIndexOutOfBoundsException if lookupPath
  (the base path) does not contain any '/' char.
  
  so, i've attached a replacement method.
  the change in the new version are :
  - no more ArrayIndexOutOfBoundsException, therefore support
    of relative path is ok.
  - output is normalized (wich makes the code significantly simplier,
    but also often slower).
  - always throws NullPointerException if any parameter is null.
  
  Submitted By: "Nicolas Leclerc" <nl@novadeck.com>
  
  Revision  Changes    Path
  1.34      +13 -17    jakarta-avalon-excalibur/io/src/java/org/apache/avalon/excalibur/io/FileUtil.java
  
  Index: FileUtil.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/io/src/java/org/apache/avalon/excalibur/io/FileUtil.java,v
  retrieving revision 1.33
  retrieving revision 1.34
  diff -u -r1.33 -r1.34
  --- FileUtil.java	31 Aug 2002 03:57:02 -0000	1.33
  +++ FileUtil.java	3 Sep 2002 12:16:34 -0000	1.34
  @@ -602,32 +602,28 @@
        *
        * @return The concatenated paths, or null if error occurs
        */
  -    public static String catPath( final String lookupPath, final String path )
  +    public static String catPath( String lookupPath,
  +                                  final String path )
       {
  -        // Cut off the last slash and everything beyond
  -        int index = lookupPath.lastIndexOf( "/" );
  -        String lookup = lookupPath.substring( 0, index );
  -        String pth = path;
  +        if( path == null )
  +        {
  +            throw new NullPointerException( "path" );
  +        }
   
  -        // Deal with .. by chopping dirs off the lookup path
  -        while( pth.startsWith( "../" ) )
  +        if( !lookupPath.endsWith( "/" ) )
           {
  -            if( lookup.length() > 0 )
  +            final int index = lookupPath.lastIndexOf( "/" );
  +            if( index < 0 )
               {
  -                index = lookup.lastIndexOf( "/" );
  -                lookup = lookup.substring( 0, index );
  +                lookupPath = "";
               }
               else
               {
  -                // More ..'s than dirs, return null
  -                return null;
  +                lookupPath = lookupPath.substring( 0, index + 1 );
               }
  -
  -            index = pth.indexOf( "../" ) + 3;
  -            pth = pth.substring( index );
           }
   
  -        return new StringBuffer( lookup ).append( "/" ).append( pth ).toString();
  +        return normalize( lookupPath + path );
       }
   
       /**
  
  
  

--
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