1 18 package org.apache.beehive.netui.util.internal; 19 20 import java.io.File ; 21 22 public class FileUtils 23 { 24 private static final boolean OS_CASE_SENSITIVE = ! new File ( "x" ).equals( new File ( "X" ) ); 25 26 27 33 public static boolean isAbsoluteURI( String uri ) 34 { 35 if ( uri.length() == 0 || uri.charAt( 0 ) == '/' ) return false; 39 40 for ( int i = 0, len = uri.length(); i < len; ++i ) 41 { 42 char c = uri.charAt( i ); 43 44 if ( c == ':' ) 45 { 46 return true; 47 } 48 else if ( c == '/' ) 49 { 50 return false; 51 } 52 } 53 54 return false; 55 } 56 57 60 public static boolean uriEndsWith( String uri, String ending ) 61 { 62 int queryStart = uri.indexOf( '?' ); 63 64 if ( queryStart == -1 ) 65 { 66 return uri.endsWith( ending ); 67 } 68 else 69 { 70 return uri.length() - queryStart >= ending.length() 71 && uri.substring( queryStart - ending.length(), queryStart ).equals( ending ); 72 } 73 } 74 75 82 public static String getFileExtension( String filename ) 83 { 84 int lastDot = filename.lastIndexOf( '.' ); 85 return lastDot != -1 ? filename.substring( lastDot + 1 ) : ""; 86 } 87 88 public static String stripFileExtension( String filename ) 89 { 90 int lastDot = filename.lastIndexOf( '.' ); 91 return lastDot != -1 ? filename.substring( 0, lastDot ) : filename; 92 } 93 94 97 public static boolean isOSCaseSensitive() 98 { 99 return OS_CASE_SENSITIVE; 100 } 101 102 115 public static boolean osSensitiveEquals( String s1, String s2 ) 116 { 117 if ( OS_CASE_SENSITIVE ) 118 { 119 return s1.equals( s2 ); 120 } 121 else 122 { 123 return s1.equalsIgnoreCase( s2 ); 124 } 125 } 126 127 140 public static boolean osSensitiveEndsWith( String str, String suffix ) 141 { 142 if ( OS_CASE_SENSITIVE ) 143 { 144 return str.endsWith( suffix ); 145 } 146 else 147 { 148 int strLen = str.length(); 149 int suffixLen = suffix.length(); 150 151 if ( strLen < suffixLen ) 152 { 153 return false; 154 } 155 156 return ( str.substring( strLen - suffixLen ).equalsIgnoreCase( suffix ) ); 157 } 158 } 159 } 160 161 | Popular Tags |