Source Code Cross Referenced for FileUtils.java in  » Library » Apache-beehive-1.0.2-src » org » apache » beehive » netui » util » internal » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Library » Apache beehive 1.0.2 src » org.apache.beehive.netui.util.internal 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Licensed to the Apache Software Foundation (ASF) under one or more
003:         * contributor license agreements.  See the NOTICE file distributed with
004:         * this work for additional information regarding copyright ownership.
005:         * The ASF licenses this file to You under the Apache License, Version 2.0
006:         * (the "License"); you may not use this file except in compliance with
007:         * the License.  You may obtain a copy of the License at
008:         * 
009:         *     http://www.apache.org/licenses/LICENSE-2.0
010:         * 
011:         * Unless required by applicable law or agreed to in writing, software
012:         * distributed under the License is distributed on an "AS IS" BASIS,
013:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         * See the License for the specific language governing permissions and
015:         * limitations under the License.
016:         *
017:         * $Header:$
018:         */
019:        package org.apache.beehive.netui.util.internal;
020:
021:        import java.io.File;
022:
023:        public class FileUtils {
024:            private static final boolean OS_CASE_SENSITIVE = !new File("x")
025:                    .equals(new File("X"));
026:
027:            /**
028:             * Tell whether a given URI is absolute, i.e., whether it contains a scheme-part (e.g., "http:").
029:             * 
030:             * @param uri the URI to test.
031:             * @return <code>true</code> if the given URI is absolute.
032:             */
033:            public static boolean isAbsoluteURI(String uri) {
034:                //
035:                // This method needs to be fast, so it can't use java.net.URI.
036:                //
037:                if (uri.length() == 0 || uri.charAt(0) == '/')
038:                    return false;
039:
040:                for (int i = 0, len = uri.length(); i < len; ++i) {
041:                    char c = uri.charAt(i);
042:
043:                    if (c == ':') {
044:                        return true;
045:                    } else if (c == '/') {
046:                        return false;
047:                    }
048:                }
049:
050:                return false;
051:            }
052:
053:            /**
054:             * Tell whether a URI ends in a given String.
055:             */
056:            public static boolean uriEndsWith(String uri, String ending) {
057:                int queryStart = uri.indexOf('?');
058:
059:                if (queryStart == -1) {
060:                    return uri.endsWith(ending);
061:                } else {
062:                    return uri.length() - queryStart >= ending.length()
063:                            && uri.substring(queryStart - ending.length(),
064:                                    queryStart).equals(ending);
065:                }
066:            }
067:
068:            /**
069:             * Get the file extension from a file name.
070:             * 
071:             * @param filename the file name.
072:             * @return the file extension (everything after the last '.'), or the empty string if there is no
073:             *         file extension.
074:             */
075:            public static String getFileExtension(String filename) {
076:                int lastDot = filename.lastIndexOf('.');
077:                return lastDot != -1 ? filename.substring(lastDot + 1) : "";
078:            }
079:
080:            public static String stripFileExtension(String filename) {
081:                int lastDot = filename.lastIndexOf('.');
082:                return lastDot != -1 ? filename.substring(0, lastDot)
083:                        : filename;
084:            }
085:
086:            /**
087:             * Tell whether the current operating system is case-sensitive with regard to file names.
088:             */
089:            public static boolean isOSCaseSensitive() {
090:                return OS_CASE_SENSITIVE;
091:            }
092:
093:            /**
094:             * Compare two strings, with case sensitivity determined by the operating system.
095:             * 
096:             * @param s1 the first String to compare.
097:             * @param s2 the second String to compare.
098:             * @return <code>true</code> when:
099:             *     <ul>
100:             *         <li>the strings match exactly (including case), or,</li>
101:             *         <li>the operating system is not case-sensitive with regard to file names, and the strings match,
102:             *             ignoring case.</li>
103:             *     </ul>
104:             * @see #isOSCaseSensitive()
105:             */
106:            public static boolean osSensitiveEquals(String s1, String s2) {
107:                if (OS_CASE_SENSITIVE) {
108:                    return s1.equals(s2);
109:                } else {
110:                    return s1.equalsIgnoreCase(s2);
111:                }
112:            }
113:
114:            /**
115:             * Tell whether a string ends with a particular suffix, with case sensitivity determined by the operating system.
116:             * 
117:             * @param str the String to test.
118:             * @param suffix the suffix to look for.
119:             * @return <code>true</code> when:
120:             *     <ul>
121:             *         <li><code>str</code> ends with <code>suffix</code>, or,</li>
122:             *         <li>the operating system is not case-sensitive with regard to file names, and <code>str</code> ends with
123:             *             <code>suffix</code>, ignoring case.</li>
124:             *     </ul>
125:             * @see #isOSCaseSensitive()
126:             */
127:            public static boolean osSensitiveEndsWith(String str, String suffix) {
128:                if (OS_CASE_SENSITIVE) {
129:                    return str.endsWith(suffix);
130:                } else {
131:                    int strLen = str.length();
132:                    int suffixLen = suffix.length();
133:
134:                    if (strLen < suffixLen) {
135:                        return false;
136:                    }
137:
138:                    return (str.substring(strLen - suffixLen)
139:                            .equalsIgnoreCase(suffix));
140:                }
141:            }
142:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.