/[classpath]/classpath/gnu/java/io/PlatformHelper.java
ViewVC logotype

Diff of /classpath/gnu/java/io/PlatformHelper.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.1 by cbj, Thu Mar 21 05:40:11 2002 UTC revision 1.2 by mark, Fri Oct 18 20:40:50 2002 UTC
# Line 1  Line 1 
1  /* PlatformHelper.java -- Isolate OS-specific IO helper methods and variables  /* PlatformHelper.java -- Isolate OS-specific IO helper methods and variables
2     Copyright (C) 1998 Free Software Foundation, Inc.     Copyright (C) 1998, 2002 Free Software Foundation, Inc.
3    
4  This file is part of GNU Classpath.  This file is part of GNU Classpath.
5    
# Line 41  import java.io.*; Line 41  import java.io.*;
41  import java.util.StringTokenizer;  import java.util.StringTokenizer;
42    
43  /**  /**
44   * We have many submissions in File.java, URLStreamHandler.java etc. to handle path   * We had many cahnges in File.java, URLStreamHandler.java etc. to handle
45   * representations on different platforms (Windows/Unix-family). Finally we'd like   * path representations on different platforms (Windows/Unix-family).
46   * to collect all these ad hoc codes into this utility class.   * Finally we'd like to collect all these ad hoc codes into this utility class.
47   *       --Gansha   *       --Gansha
48   */   */
49    
50  public class PlatformHelper{  public class PlatformHelper{
51    
52  public static final boolean isWindows = System.getProperty("os.name").indexOf("Windows") >= 0;  public static final boolean isWindows
53            = System.getProperty("os.name").indexOf("Windows") >= 0;
54    
55  public static final String separator = System.getProperty("file.separator");  public static final String separator = System.getProperty("file.separator");
56  public static final char separatorChar = separator.charAt(0);  public static final char separatorChar = separator.charAt(0);
# Line 57  public static final String pathSeparator Line 58  public static final String pathSeparator
58  public static final char pathSeparatorChar = pathSeparator.charAt(0);  public static final char pathSeparatorChar = pathSeparator.charAt(0);
59    
60  /**  /**
61   * This routine checks the input param "path" whether it begins with root path prefix.    * On most platforms 260 is equal or greater than a max path value,
62      * so we can set the initial buffer size of StringBuffer to half of this value
63      * to improve performance.
64      */
65    public static final int INITIAL_MAX_PATH = 260/2;
66    
67    /**
68     * This routine checks the input param "path" whether it begins with root path
69     * prefix.
70   * if not, return 0;   * if not, return 0;
71   * if yes, return the len of root path prefix;   * if yes, return the len of root path prefix;
72   *   --for Unix-family platform, root path begins with "/" and len is 1   *   --for Unix-family platform, root path begins with "/" and len is 1
# Line 106  public static final String toCanonicalFo Line 115  public static final String toCanonicalFo
115      */      */
116      String tmppath = path.replace('/', separatorChar);      String tmppath = path.replace('/', separatorChar);
117      StringBuffer canonpath;      StringBuffer canonpath;
118        // We found it'll be more efficient and easy to handle to
119        // return a lowercased canonical path
120        if(isWindows)
121            tmppath = tmppath.toLowerCase();
122      int i;      int i;
123      if ((i = beginWithRootPathPrefix(tmppath)) == 0 )      if ((i = beginWithRootPathPrefix(tmppath)) == 0 )
124          return path;          return path;
125      canonpath = new StringBuffer(tmppath.substring(0, i));      
126        /* The original
127               "canonpath = new StringBuffer(tmppath.substring(0, i))"
128           isn't very efficient because StringBuffer's
129           ensureCapacity_unsynchronized will fail definitely each time
130           and will enlarge buffer and copy contents.       .
131        */
132        canonpath = new StringBuffer(INITIAL_MAX_PATH);
133        canonpath.append(tmppath.substring(0, i));
134      tmppath = tmppath.substring(i);      tmppath = tmppath.substring(i);
135      // pathdepth==0 indicates there're only root path in the buffer      // pathdepth==0 indicates there're only root path in the buffer
136      int pathdepth = 0;      int pathdepth = 0;

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.2

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26