Java Doc for FilenameUtils.java in  » Library » apache-common-IO » org » apache » commons » io » 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 common IO » org.apache.commons.io 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   org.apache.commons.io.FilenameUtils

FilenameUtils
public class FilenameUtils (Code)
General filename and filepath manipulation utilities.

When dealing with filenames you can hit problems when moving from a Windows based development machine to a Unix based production machine. This class aims to help avoid those problems.

NOTE: You may be able to avoid using this class entirely simply by using JDK java.io.File File objects and the two argument constructor java.io.File.File(java.io.Filejava.lang.String) File(File,String) .

Most methods on this class are designed to work the same on both Unix and Windows. Those that don't include 'System', 'Unix' or 'Windows' in their name.

Most methods recognise both separators (forward and back), and both sets of prefixes. See the javadoc of each method for details.

This class defines six components within a filename (example C:\dev\project\file.txt):

  • the prefix - C:\
  • the path - dev\project\
  • the full path - C:\dev\project\
  • the name - file.txt
  • the base name - file
  • the extension - txt
Note that this class works best if directory filenames end with a separator. If you omit the last separator, it is impossible to determine if the filename corresponds to a file or a directory. As a result, we have chosen to say it corresponds to a file.

This class only supports Unix and Windows style names. Prefixes are matched as follows:

 Windows:
 a\b\c.txt           --> ""          --> relative
 \a\b\c.txt          --> "\"         --> current drive absolute
 C:a\b\c.txt         --> "C:"        --> drive relative
 C:\a\b\c.txt        --> "C:\"       --> absolute
 \\server\a\b\c.txt  --> "\\server\" --> UNC
 Unix:
 a/b/c.txt           --> ""          --> relative
 /a/b/c.txt          --> "/"         --> absolute
 ~/a/b/c.txt         --> "~/"        --> current user
 ~                   --> "~/"        --> current user (slash added)
 ~user/a/b/c.txt     --> "~user/"    --> named user
 ~user               --> "~user/"    --> named user (slash added)
 
Both prefix styles are matched always, irrespective of the machine that you are currently running on.

Origin of code: Excalibur, Alexandria, Tomcat, Commons-Utils.
author:
   Kevin A. Burton
author:
   Scott Sanders
author:
   Daniel Rall
author:
   Christoph.Reck
author:
   Peter Donald
author:
   Jeff Turner
author:
   Matthew Hawthorne
author:
   Martin Cooper
author:
   Jeremias Maerki
author:
   Stephen Colebourne
version:
   $Id: FilenameUtils.java 490424 2006-12-27 01:20:43Z bayard $
since:
   Commons IO 1.1




Constructor Summary
public  FilenameUtils()
     Instances should NOT be constructed in standard programming.

Method Summary
public static  Stringconcat(String basePath, String fullFilenameToAdd)
     Concatenates a filename to a base path using normal command line style rules.

The effect is equivalent to resultant directory after changing directory to the first argument, followed by changing directory to the second argument.

The first argument is the base path, the second is the path to concatenate. The returned path is always normalized via FilenameUtils.normalize(String) , thus .. is handled.

If pathToAdd is absolute (has an absolute prefix), then it will be normalized and returned. Otherwise, the paths will be joined, normalized and returned.

The output will be the same on both Unix and Windows except for the separator character.

 /foo/ + bar          -->   /foo/bar
 /foo + bar           -->   /foo/bar
 /foo + /bar          -->   /bar
 /foo + C:/bar        -->   C:/bar
 /foo + C:bar         -->   C:bar (*)
 /foo/a/ + ../bar     -->   foo/bar
 /foo/ + ../../bar    -->   null
 /foo/ + /bar         -->   /bar
 /foo/..
public static  booleanequals(String filename1, String filename2)
     Checks whether two filenames are equal exactly.
public static  booleanequals(String filename1, String filename2, boolean normalized, IOCase caseSensitivity)
     Checks whether two filenames are equal, optionally normalizing and providing control over the case-sensitivity.
public static  booleanequalsNormalized(String filename1, String filename2)
     Checks whether two filenames are equal after both have been normalized.
public static  booleanequalsNormalizedOnSystem(String filename1, String filename2)
     Checks whether two filenames are equal after both have been normalized and using the case rules of the system.
public static  booleanequalsOnSystem(String filename1, String filename2)
     Checks whether two filenames are equal using the case rules of the system.
public static  StringgetBaseName(String filename)
     Gets the base name, minus the full path and extension, from a full filename.
public static  StringgetExtension(String filename)
     Gets the extension of a filename.

This method returns the textual part of the filename after the last dot. There must be no directory separator after the dot.

 foo.txt      --> "txt"
 a/b/c.jpg    --> "jpg"
 a/b.txt/c    --> ""
 a/b/c        --> ""
 

The output will be the same irrespective of the machine that the code is running on.
Parameters:
  filename - the filename to retrieve the extension of.

public static  StringgetFullPath(String filename)
     Gets the full path from a full filename, which is the prefix + path.
public static  StringgetFullPathNoEndSeparator(String filename)
     Gets the full path from a full filename, which is the prefix + path, and also excluding the final directory separator.
public static  StringgetName(String filename)
     Gets the name minus the path from a full filename.
public static  StringgetPath(String filename)
     Gets the path from a full filename, which excludes the prefix.
public static  StringgetPathNoEndSeparator(String filename)
     Gets the path from a full filename, which excludes the prefix, and also excluding the final directory separator.
public static  StringgetPrefix(String filename)
     Gets the prefix from a full filename, such as C:/ or ~/.

This method will handle a file in either Unix or Windows format. The prefix includes the first slash in the full filename where applicable.

 Windows:
 a\b\c.txt           --> ""          --> relative
 \a\b\c.txt          --> "\"         --> current drive absolute
 C:a\b\c.txt         --> "C:"        --> drive relative
 C:\a\b\c.txt        --> "C:\"       --> absolute
 \\server\a\b\c.txt  --> "\\server\" --> UNC
 Unix:
 a/b/c.txt           --> ""          --> relative
 /a/b/c.txt          --> "/"         --> absolute
 ~/a/b/c.txt         --> "~/"        --> current user
 ~                   --> "~/"        --> current user (slash added)
 ~user/a/b/c.txt     --> "~user/"    --> named user
 ~user               --> "~user/"    --> named user (slash added)
 

The output will be the same irrespective of the machine that the code is running on. ie.

public static  intgetPrefixLength(String filename)
     Returns the length of the filename prefix, such as C:/ or ~/.

This method will handle a file in either Unix or Windows format.

The prefix length includes the first slash in the full filename if applicable.

public static  intindexOfExtension(String filename)
     Returns the index of the last extension separator character, which is a dot.
public static  intindexOfLastSeparator(String filename)
     Returns the index of the last directory separator character.
public static  booleanisExtension(String filename, String extension)
     Checks whether the extension of the filename is that specified.

This method obtains the extension as the textual part of the filename after the last dot.

public static  booleanisExtension(String filename, String[] extensions)
     Checks whether the extension of the filename is one of those specified.

This method obtains the extension as the textual part of the filename after the last dot.

public static  booleanisExtension(String filename, Collection extensions)
     Checks whether the extension of the filename is one of those specified.

This method obtains the extension as the textual part of the filename after the last dot.

static  booleanisSystemWindows()
     Determines if Windows file system is in use.
public static  Stringnormalize(String filename)
     Normalizes a path, removing double and single dot path steps.

This method normalizes a path to a standard format. The input may contain separators in either Unix or Windows format. The output will contain separators in the format of the system.

A trailing slash will be retained. A double slash will be merged to a single slash (but UNC names are handled). A single dot path segment will be removed. A double dot will cause that path segment and the one before to be removed. If the double dot has no parent path segment to work with, null is returned.

The output will be the same on both Unix and Windows except for the separator character.

 /foo//               -->   /foo/
 /foo/./              -->   /foo/
 /foo/../bar          -->   /bar
 /foo/../bar/         -->   /bar/
 /foo/../bar/../baz   -->   /baz
 //foo//./bar         -->   /foo/bar
 /../                 -->   null
 ../foo               -->   null
 foo/bar/..
public static  StringnormalizeNoEndSeparator(String filename)
     Normalizes a path, removing double and single dot path steps, and removing any final directory separator.

This method normalizes a path to a standard format. The input may contain separators in either Unix or Windows format. The output will contain separators in the format of the system.

A trailing slash will be removed. A double slash will be merged to a single slash (but UNC names are handled). A single dot path segment will be removed. A double dot will cause that path segment and the one before to be removed. If the double dot has no parent path segment to work with, null is returned.

The output will be the same on both Unix and Windows except for the separator character.

 /foo//               -->   /foo
 /foo/./              -->   /foo
 /foo/../bar          -->   /bar
 /foo/../bar/         -->   /bar
 /foo/../bar/../baz   -->   /baz
 //foo//./bar         -->   /foo/bar
 /../                 -->   null
 ../foo               -->   null
 foo/bar/..
public static  StringremoveExtension(String filename)
     Removes the extension from a filename.
public static  StringseparatorsToSystem(String path)
     Converts all separators to the system separator.
public static  StringseparatorsToUnix(String path)
     Converts all separators to the Unix separator of forward slash.
public static  StringseparatorsToWindows(String path)
     Converts all separators to the Windows separator of backslash.
static  String[]splitOnTokens(String text)
     Splits a string into a number of tokens.
public static  booleanwildcardMatch(String filename, String wildcardMatcher)
     Checks a filename to see if it matches the specified wildcard matcher, always testing case-sensitive.
public static  booleanwildcardMatch(String filename, String wildcardMatcher, IOCase caseSensitivity)
     Checks a filename to see if it matches the specified wildcard matcher allowing control over case-sensitivity.
public static  booleanwildcardMatchOnSystem(String filename, String wildcardMatcher)
     Checks a filename to see if it matches the specified wildcard matcher using the case rules of the system.


Constructor Detail
FilenameUtils
public FilenameUtils()(Code)
Instances should NOT be constructed in standard programming.




Method Detail
concat
public static String concat(String basePath, String fullFilenameToAdd)(Code)
Concatenates a filename to a base path using normal command line style rules.

The effect is equivalent to resultant directory after changing directory to the first argument, followed by changing directory to the second argument.

The first argument is the base path, the second is the path to concatenate. The returned path is always normalized via FilenameUtils.normalize(String) , thus .. is handled.

If pathToAdd is absolute (has an absolute prefix), then it will be normalized and returned. Otherwise, the paths will be joined, normalized and returned.

The output will be the same on both Unix and Windows except for the separator character.

 /foo/ + bar          -->   /foo/bar
 /foo + bar           -->   /foo/bar
 /foo + /bar          -->   /bar
 /foo + C:/bar        -->   C:/bar
 /foo + C:bar         -->   C:bar (*)
 /foo/a/ + ../bar     -->   foo/bar
 /foo/ + ../../bar    -->   null
 /foo/ + /bar         -->   /bar
 /foo/.. + /bar       -->   /bar
 /foo + bar/c.txt     -->   /foo/bar/c.txt
 /foo/c.txt + bar     -->   /foo/c.txt/bar (!)
 
(*) Note that the Windows relative drive prefix is unreliable when used with this method. (!) Note that the first parameter must be a path. If it ends with a name, then the name will be built into the concatenated path. If this might be a problem, use FilenameUtils.getFullPath(String) on the base path argument.
Parameters:
  basePath - the base path to attach to, always treated as a path
Parameters:
  fullFilenameToAdd - the filename (or path) to attach to the base the concatenated path, or null if invalid



equals
public static boolean equals(String filename1, String filename2)(Code)
Checks whether two filenames are equal exactly.

No processing is performed on the filenames other than comparison, thus this is merely a null-safe case-sensitive equals.
Parameters:
  filename1 - the first filename to query, may be null
Parameters:
  filename2 - the second filename to query, may be null true if the filenames are equal, null equals null
See Also:   IOCase.SENSITIVE




equals
public static boolean equals(String filename1, String filename2, boolean normalized, IOCase caseSensitivity)(Code)
Checks whether two filenames are equal, optionally normalizing and providing control over the case-sensitivity.
Parameters:
  filename1 - the first filename to query, may be null
Parameters:
  filename2 - the second filename to query, may be null
Parameters:
  normalized - whether to normalize the filenames
Parameters:
  caseSensitivity - what case sensitivity rule to use, null means case-sensitive true if the filenames are equal, null equals null
since:
   Commons IO 1.3



equalsNormalized
public static boolean equalsNormalized(String filename1, String filename2)(Code)
Checks whether two filenames are equal after both have been normalized.

Both filenames are first passed to FilenameUtils.normalize(String) . The check is then performed in a case-sensitive manner.
Parameters:
  filename1 - the first filename to query, may be null
Parameters:
  filename2 - the second filename to query, may be null true if the filenames are equal, null equals null
See Also:   IOCase.SENSITIVE




equalsNormalizedOnSystem
public static boolean equalsNormalizedOnSystem(String filename1, String filename2)(Code)
Checks whether two filenames are equal after both have been normalized and using the case rules of the system.

Both filenames are first passed to FilenameUtils.normalize(String) . The check is then performed case-sensitive on Unix and case-insensitive on Windows.
Parameters:
  filename1 - the first filename to query, may be null
Parameters:
  filename2 - the second filename to query, may be null true if the filenames are equal, null equals null
See Also:   IOCase.SYSTEM




equalsOnSystem
public static boolean equalsOnSystem(String filename1, String filename2)(Code)
Checks whether two filenames are equal using the case rules of the system.

No processing is performed on the filenames other than comparison. The check is case-sensitive on Unix and case-insensitive on Windows.
Parameters:
  filename1 - the first filename to query, may be null
Parameters:
  filename2 - the second filename to query, may be null true if the filenames are equal, null equals null
See Also:   IOCase.SYSTEM




getBaseName
public static String getBaseName(String filename)(Code)
Gets the base name, minus the full path and extension, from a full filename.

This method will handle a file in either Unix or Windows format. The text after the last forward or backslash and before the last dot is returned.

 a/b/c.txt --> c
 a.txt     --> a
 a/b/c     --> c
 a/b/c/    --> ""
 

The output will be the same irrespective of the machine that the code is running on.
Parameters:
  filename - the filename to query, null returns null the name of the file without the path, or an empty string if none exists




getExtension
public static String getExtension(String filename)(Code)
Gets the extension of a filename.

This method returns the textual part of the filename after the last dot. There must be no directory separator after the dot.

 foo.txt      --> "txt"
 a/b/c.jpg    --> "jpg"
 a/b.txt/c    --> ""
 a/b/c        --> ""
 

The output will be the same irrespective of the machine that the code is running on.
Parameters:
  filename - the filename to retrieve the extension of. the extension of the file or an empty string if none exists.




getFullPath
public static String getFullPath(String filename)(Code)
Gets the full path from a full filename, which is the prefix + path.

This method will handle a file in either Unix or Windows format. The method is entirely text based, and returns the text before and including the last forward or backslash.

 C:\a\b\c.txt --> C:\a\b\
 ~/a/b/c.txt  --> ~/a/b/
 a.txt        --> ""
 a/b/c        --> a/b/
 a/b/c/       --> a/b/c/
 C:           --> C:
 C:\          --> C:\
 ~            --> ~/
 ~/           --> ~/
 ~user        --> ~user/
 ~user/       --> ~user/
 

The output will be the same irrespective of the machine that the code is running on.
Parameters:
  filename - the filename to query, null returns null the path of the file, an empty string if none exists, null if invalid




getFullPathNoEndSeparator
public static String getFullPathNoEndSeparator(String filename)(Code)
Gets the full path from a full filename, which is the prefix + path, and also excluding the final directory separator.

This method will handle a file in either Unix or Windows format. The method is entirely text based, and returns the text before the last forward or backslash.

 C:\a\b\c.txt --> C:\a\b
 ~/a/b/c.txt  --> ~/a/b
 a.txt        --> ""
 a/b/c        --> a/b
 a/b/c/       --> a/b/c
 C:           --> C:
 C:\          --> C:\
 ~            --> ~
 ~/           --> ~
 ~user        --> ~user
 ~user/       --> ~user
 

The output will be the same irrespective of the machine that the code is running on.
Parameters:
  filename - the filename to query, null returns null the path of the file, an empty string if none exists, null if invalid




getName
public static String getName(String filename)(Code)
Gets the name minus the path from a full filename.

This method will handle a file in either Unix or Windows format. The text after the last forward or backslash is returned.

 a/b/c.txt --> c.txt
 a.txt     --> a.txt
 a/b/c     --> c
 a/b/c/    --> ""
 

The output will be the same irrespective of the machine that the code is running on.
Parameters:
  filename - the filename to query, null returns null the name of the file without the path, or an empty string if none exists




getPath
public static String getPath(String filename)(Code)
Gets the path from a full filename, which excludes the prefix.

This method will handle a file in either Unix or Windows format. The method is entirely text based, and returns the text before and including the last forward or backslash.

 C:\a\b\c.txt --> a\b\
 ~/a/b/c.txt  --> a/b/
 a.txt        --> ""
 a/b/c        --> a/b/
 a/b/c/       --> a/b/c/
 

The output will be the same irrespective of the machine that the code is running on.

This method drops the prefix from the result. See FilenameUtils.getFullPath(String) for the method that retains the prefix.
Parameters:
  filename - the filename to query, null returns null the path of the file, an empty string if none exists, null if invalid




getPathNoEndSeparator
public static String getPathNoEndSeparator(String filename)(Code)
Gets the path from a full filename, which excludes the prefix, and also excluding the final directory separator.

This method will handle a file in either Unix or Windows format. The method is entirely text based, and returns the text before the last forward or backslash.

 C:\a\b\c.txt --> a\b
 ~/a/b/c.txt  --> a/b
 a.txt        --> ""
 a/b/c        --> a/b
 a/b/c/       --> a/b/c
 

The output will be the same irrespective of the machine that the code is running on.

This method drops the prefix from the result. See FilenameUtils.getFullPathNoEndSeparator(String) for the method that retains the prefix.
Parameters:
  filename - the filename to query, null returns null the path of the file, an empty string if none exists, null if invalid




getPrefix
public static String getPrefix(String filename)(Code)
Gets the prefix from a full filename, such as C:/ or ~/.

This method will handle a file in either Unix or Windows format. The prefix includes the first slash in the full filename where applicable.

 Windows:
 a\b\c.txt           --> ""          --> relative
 \a\b\c.txt          --> "\"         --> current drive absolute
 C:a\b\c.txt         --> "C:"        --> drive relative
 C:\a\b\c.txt        --> "C:\"       --> absolute
 \\server\a\b\c.txt  --> "\\server\" --> UNC
 Unix:
 a/b/c.txt           --> ""          --> relative
 /a/b/c.txt          --> "/"         --> absolute
 ~/a/b/c.txt         --> "~/"        --> current user
 ~                   --> "~/"        --> current user (slash added)
 ~user/a/b/c.txt     --> "~user/"    --> named user
 ~user               --> "~user/"    --> named user (slash added)
 

The output will be the same irrespective of the machine that the code is running on. ie. both Unix and Windows prefixes are matched regardless.
Parameters:
  filename - the filename to query, null returns null the prefix of the file, null if invalid




getPrefixLength
public static int getPrefixLength(String filename)(Code)
Returns the length of the filename prefix, such as C:/ or ~/.

This method will handle a file in either Unix or Windows format.

The prefix length includes the first slash in the full filename if applicable. Thus, it is possible that the length returned is greater than the length of the input string.

 Windows:
 a\b\c.txt           --> ""          --> relative
 \a\b\c.txt          --> "\"         --> current drive absolute
 C:a\b\c.txt         --> "C:"        --> drive relative
 C:\a\b\c.txt        --> "C:\"       --> absolute
 \\server\a\b\c.txt  --> "\\server\" --> UNC
 Unix:
 a/b/c.txt           --> ""          --> relative
 /a/b/c.txt          --> "/"         --> absolute
 ~/a/b/c.txt         --> "~/"        --> current user
 ~                   --> "~/"        --> current user (slash added)
 ~user/a/b/c.txt     --> "~user/"    --> named user
 ~user               --> "~user/"    --> named user (slash added)
 

The output will be the same irrespective of the machine that the code is running on. ie. both Unix and Windows prefixes are matched regardless.
Parameters:
  filename - the filename to find the prefix in, null returns -1 the length of the prefix, -1 if invalid or null




indexOfExtension
public static int indexOfExtension(String filename)(Code)
Returns the index of the last extension separator character, which is a dot.

This method also checks that there is no directory separator after the last dot. To do this it uses FilenameUtils.indexOfLastSeparator(String) which will handle a file in either Unix or Windows format.

The output will be the same irrespective of the machine that the code is running on.
Parameters:
  filename - the filename to find the last path separator in, null returns -1 the index of the last separator character, or -1 if thereis no such character




indexOfLastSeparator
public static int indexOfLastSeparator(String filename)(Code)
Returns the index of the last directory separator character.

This method will handle a file in either Unix or Windows format. The position of the last forward or backslash is returned.

The output will be the same irrespective of the machine that the code is running on.
Parameters:
  filename - the filename to find the last path separator in, null returns -1 the index of the last separator character, or -1 if thereis no such character




isExtension
public static boolean isExtension(String filename, String extension)(Code)
Checks whether the extension of the filename is that specified.

This method obtains the extension as the textual part of the filename after the last dot. There must be no directory separator after the dot. The extension check is case-sensitive on all platforms.
Parameters:
  filename - the filename to query, null returns false
Parameters:
  extension - the extension to check for, null or empty checks for no extension true if the filename has the specified extension




isExtension
public static boolean isExtension(String filename, String[] extensions)(Code)
Checks whether the extension of the filename is one of those specified.

This method obtains the extension as the textual part of the filename after the last dot. There must be no directory separator after the dot. The extension check is case-sensitive on all platforms.
Parameters:
  filename - the filename to query, null returns false
Parameters:
  extensions - the extensions to check for, null checks for no extension true if the filename is one of the extensions




isExtension
public static boolean isExtension(String filename, Collection extensions)(Code)
Checks whether the extension of the filename is one of those specified.

This method obtains the extension as the textual part of the filename after the last dot. There must be no directory separator after the dot. The extension check is case-sensitive on all platforms.
Parameters:
  filename - the filename to query, null returns false
Parameters:
  extensions - the extensions to check for, null checks for no extension true if the filename is one of the extensions




isSystemWindows
static boolean isSystemWindows()(Code)
Determines if Windows file system is in use. true if the system is Windows



normalize
public static String normalize(String filename)(Code)
Normalizes a path, removing double and single dot path steps.

This method normalizes a path to a standard format. The input may contain separators in either Unix or Windows format. The output will contain separators in the format of the system.

A trailing slash will be retained. A double slash will be merged to a single slash (but UNC names are handled). A single dot path segment will be removed. A double dot will cause that path segment and the one before to be removed. If the double dot has no parent path segment to work with, null is returned.

The output will be the same on both Unix and Windows except for the separator character.

 /foo//               -->   /foo/
 /foo/./              -->   /foo/
 /foo/../bar          -->   /bar
 /foo/../bar/         -->   /bar/
 /foo/../bar/../baz   -->   /baz
 //foo//./bar         -->   /foo/bar
 /../                 -->   null
 ../foo               -->   null
 foo/bar/..           -->   foo/
 foo/../../bar        -->   null
 foo/../bar           -->   bar
 //server/foo/../bar  -->   //server/bar
 //server/../bar      -->   null
 C:\foo\..\bar        -->   C:\bar
 C:\..\bar            -->   null
 ~/foo/../bar/        -->   ~/bar/
 ~/../bar             -->   null
 
(Note the file separator returned will be correct for Windows/Unix)
Parameters:
  filename - the filename to normalize, null returns null the normalized filename, or null if invalid



normalizeNoEndSeparator
public static String normalizeNoEndSeparator(String filename)(Code)
Normalizes a path, removing double and single dot path steps, and removing any final directory separator.

This method normalizes a path to a standard format. The input may contain separators in either Unix or Windows format. The output will contain separators in the format of the system.

A trailing slash will be removed. A double slash will be merged to a single slash (but UNC names are handled). A single dot path segment will be removed. A double dot will cause that path segment and the one before to be removed. If the double dot has no parent path segment to work with, null is returned.

The output will be the same on both Unix and Windows except for the separator character.

 /foo//               -->   /foo
 /foo/./              -->   /foo
 /foo/../bar          -->   /bar
 /foo/../bar/         -->   /bar
 /foo/../bar/../baz   -->   /baz
 //foo//./bar         -->   /foo/bar
 /../                 -->   null
 ../foo               -->   null
 foo/bar/..           -->   foo
 foo/../../bar        -->   null
 foo/../bar           -->   bar
 //server/foo/../bar  -->   //server/bar
 //server/../bar      -->   null
 C:\foo\..\bar        -->   C:\bar
 C:\..\bar            -->   null
 ~/foo/../bar/        -->   ~/bar
 ~/../bar             -->   null
 
(Note the file separator returned will be correct for Windows/Unix)
Parameters:
  filename - the filename to normalize, null returns null the normalized filename, or null if invalid



removeExtension
public static String removeExtension(String filename)(Code)
Removes the extension from a filename.

This method returns the textual part of the filename before the last dot. There must be no directory separator after the dot.

 foo.txt    --> foo
 a\b\c.jpg  --> a\b\c
 a\b\c      --> a\b\c
 a.b\c      --> a.b\c
 

The output will be the same irrespective of the machine that the code is running on.
Parameters:
  filename - the filename to query, null returns null the filename minus the extension




separatorsToSystem
public static String separatorsToSystem(String path)(Code)
Converts all separators to the system separator.
Parameters:
  path - the path to be changed, null ignored the updated path



separatorsToUnix
public static String separatorsToUnix(String path)(Code)
Converts all separators to the Unix separator of forward slash.
Parameters:
  path - the path to be changed, null ignored the updated path



separatorsToWindows
public static String separatorsToWindows(String path)(Code)
Converts all separators to the Windows separator of backslash.
Parameters:
  path - the path to be changed, null ignored the updated path



splitOnTokens
static String[] splitOnTokens(String text)(Code)
Splits a string into a number of tokens.
Parameters:
  text - the text to split the tokens, never null



wildcardMatch
public static boolean wildcardMatch(String filename, String wildcardMatcher)(Code)
Checks a filename to see if it matches the specified wildcard matcher, always testing case-sensitive.

The wildcard matcher uses the characters '?' and '*' to represent a single or multiple wildcard characters. This is the same as often found on Dos/Unix command lines. The check is case-sensitive always.

 wildcardMatch("c.txt", "*.txt")      --> true
 wildcardMatch("c.txt", "*.jpg")      --> false
 wildcardMatch("a/b/c.txt", "a/b/*")  --> true
 wildcardMatch("c.txt", "*.???")      --> true
 wildcardMatch("c.txt", "*.????")     --> false
 

Parameters:
  filename - the filename to match on
Parameters:
  wildcardMatcher - the wildcard string to match against true if the filename matches the wilcard string
See Also:   IOCase.SENSITIVE



wildcardMatch
public static boolean wildcardMatch(String filename, String wildcardMatcher, IOCase caseSensitivity)(Code)
Checks a filename to see if it matches the specified wildcard matcher allowing control over case-sensitivity.

The wildcard matcher uses the characters '?' and '*' to represent a single or multiple wildcard characters.
Parameters:
  filename - the filename to match on
Parameters:
  wildcardMatcher - the wildcard string to match against
Parameters:
  caseSensitivity - what case sensitivity rule to use, null means case-sensitive true if the filename matches the wilcard string
since:
   Commons IO 1.3




wildcardMatchOnSystem
public static boolean wildcardMatchOnSystem(String filename, String wildcardMatcher)(Code)
Checks a filename to see if it matches the specified wildcard matcher using the case rules of the system.

The wildcard matcher uses the characters '?' and '*' to represent a single or multiple wildcard characters. This is the same as often found on Dos/Unix command lines. The check is case-sensitive on Unix and case-insensitive on Windows.

 wildcardMatch("c.txt", "*.txt")      --> true
 wildcardMatch("c.txt", "*.jpg")      --> false
 wildcardMatch("a/b/c.txt", "a/b/*")  --> true
 wildcardMatch("c.txt", "*.???")      --> true
 wildcardMatch("c.txt", "*.????")     --> false
 

Parameters:
  filename - the filename to match on
Parameters:
  wildcardMatcher - the wildcard string to match against true if the filename matches the wilcard string
See Also:   IOCase.SYSTEM



Methods inherited from java.lang.Object
native protected Object clone() throws CloneNotSupportedException(Code)(Java Doc)
public boolean equals(Object obj)(Code)(Java Doc)
protected void finalize() throws Throwable(Code)(Java Doc)
final native public Class getClass()(Code)(Java Doc)
native public int hashCode()(Code)(Java Doc)
final native public void notify()(Code)(Java Doc)
final native public void notifyAll()(Code)(Java Doc)
public String toString()(Code)(Java Doc)
final native public void wait(long timeout) throws InterruptedException(Code)(Java Doc)
final public void wait(long timeout, int nanos) throws InterruptedException(Code)(Java Doc)
final public void wait() throws InterruptedException(Code)(Java Doc)

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.