Home | History | Annotate | Download | only in io

Lines Matching refs:filename

26  * General filename and filepath manipulation utilities.
42 * This class defines six components within a filename
53 * If you omit the last separator, it is impossible to determine if the filename
200 * @param filename the filename to normalize, null returns null
201 * @return the normalized filename, or null if invalid
203 public static String normalize(String filename) {
204 return doNormalize(filename, true);
246 * @param filename the filename to normalize, null returns null
247 * @return the normalized filename, or null if invalid
249 public static String normalizeNoEndSeparator(String filename) {
250 return doNormalize(filename, false);
256 * @param filename the filename
258 * @return the normalized filename
260 private static String doNormalize(String filename, boolean keepSeparator) {
261 if (filename == null) {
264 int size = filename.length();
266 return filename;
268 int prefix = getPrefixLength(filename);
274 filename.getChars(0, filename.length(), array, 0);
354 * Concatenates a filename to a base path using normal command line style rules.
390 * @param fullFilenameToAdd the filename (or path) to attach to the base
462 * Returns the length of the filename prefix, such as <code>C:/</code> or <code>~/</code>.
466 * The prefix length includes the first slash in the full filename
489 * @param filename the filename to find the prefix in, null returns -1
492 public static int getPrefixLength(String filename) {
493 if (filename == null) {
496 int len = filename.length();
500 char ch0 = filename.charAt(0);
511 int posUnix = filename.indexOf(UNIX_SEPARATOR, 1);
512 int posWin = filename.indexOf(WINDOWS_SEPARATOR, 1);
520 char ch1 = filename.charAt(1);
524 if (len == 2 || isSeparator(filename.charAt(2)) == false) {
532 int posUnix = filename.indexOf(UNIX_SEPARATOR, 2);
533 int posWin = filename.indexOf(WINDOWS_SEPARATOR, 2);
554 * @param filename the filename to find the last path separator in, null returns -1
558 public static int indexOfLastSeparator(String filename) {
559 if (filename == null) {
562 int lastUnixPos = filename.lastIndexOf(UNIX_SEPARATOR);
563 int lastWindowsPos = filename.lastIndexOf(WINDOWS_SEPARATOR);
576 * @param filename the filename to find the last path separator in, null returns -1
580 public static int indexOfExtension(String filename) {
581 if (filename == null) {
584 int extensionPos = filename.lastIndexOf(EXTENSION_SEPARATOR);
585 int lastSeparator = indexOfLastSeparator(filename);
591 * Gets the prefix from a full filename, such as <code>C:/</code>
595 * The prefix includes the first slash in the full filename where applicable.
616 * @param filename the filename to query, null returns null
619 public static String getPrefix(String filename) {
620 if (filename == null) {
623 int len = getPrefixLength(filename);
627 if (len > filename.length()) {
628 return filename + UNIX_SEPARATOR; // we know this only happens for unix
630 return filename.substring(0, len);
634 * Gets the path from a full filename, which excludes the prefix.
652 * @param filename the filename to query, null returns null
655 public static String getPath(String filename) {
656 return doGetPath(filename, 1);
660 * Gets the path from a full filename, which excludes the prefix, and
679 * @param filename the filename to query, null returns null
682 public static String getPathNoEndSeparator(String filename) {
683 return doGetPath(filename, 0);
689 * @param filename the filename
693 private static String doGetPath(String filename, int separatorAdd) {
694 if (filename == null) {
697 int prefix = getPrefixLength(filename);
701 int index = indexOfLastSeparator(filename);
702 if (prefix >= filename.length() || index < 0) {
705 return filename.substring(prefix, index + separatorAdd);
709 * Gets the full path from a full filename, which is the prefix + path.
730 * @param filename the filename to query, null returns null
733 public static String getFullPath(String filename) {
734 return doGetFullPath(filename, true);
738 * Gets the full path from a full filename, which is the prefix + path,
760 * @param filename the filename to query, null returns null
763 public static String getFullPathNoEndSeparator(String filename) {
764 return doGetFullPath(filename, false);
770 * @param filename the filename
774 private static String doGetFullPath(String filename, boolean includeSeparator) {
775 if (filename == null) {
778 int prefix = getPrefixLength(filename);
782 if (prefix >= filename.length()) {
784 return getPrefix(filename); // add end slash if necessary
786 return filename;
789 int index = indexOfLastSeparator(filename);
791 return filename.substring(0, prefix);
794 return filename.substring(0, end);
798 * Gets the name minus the path from a full filename.
811 * @param filename the filename to query, null returns null
814 public static String getName(String filename) {
815 if (filename == null) {
818 int index = indexOfLastSeparator(filename);
819 return filename.substring(index + 1);
823 * Gets the base name, minus the full path and extension, from a full filename.
836 * @param filename the filename to query, null returns null
839 public static String getBaseName(String filename) {
840 return removeExtension(getName(filename));
844 * Gets the extension of a filename.
846 * This method returns the textual part of the filename after the last dot.
857 * @param filename the filename to retrieve the extension of.
860 public static String getExtension(String filename) {
861 if (filename == null) {
864 int index = indexOfExtension(filename);
868 return filename.substring(index + 1);
874 * Removes the extension from a filename.
876 * This method returns the textual part of the filename before the last dot.
887 * @param filename the filename to query, null returns null
888 * @return the filename minus the extension
890 public static String removeExtension(String filename) {
891 if (filename == null) {
894 int index = indexOfExtension(filename);
896 return filename;
898 return filename.substring(0, index);
909 * @param filename1 the first filename to query, may be null
910 * @param filename2 the second filename to query, may be null
924 * @param filename1 the first filename to query, may be null
925 * @param filename2 the second filename to query, may be null
940 * @param filename1 the first filename to query, may be null
941 * @param filename2 the second filename to query, may be null
957 * @param filename1 the first filename to query, may be null
958 * @param filename2 the second filename to query, may be null
970 * @param filename1 the first filename to query, may be null
971 * @param filename2 the second filename to query, may be null
1000 * Checks whether the extension of the filename is that specified.
1002 * This method obtains the extension as the textual part of the filename
1006 * @param filename the filename to query, null returns false
1008 * @return true if the filename has the specified extension
1010 public static boolean isExtension(String filename, String extension) {
1011 if (filename == null) {
1015 return (indexOfExtension(filename) == -1);
1017 String fileExt = getExtension(filename);
1022 * Checks whether the extension of the filename is one of those specified.
1024 * This method obtains the extension as the textual part of the filename
1028 * @param filename the filename to query, null returns false
1030 * @return true if the filename is one of the extensions
1032 public static boolean isExtension(String filename, String[] extensions) {
1033 if (filename == null) {
1037 return (indexOfExtension(filename) == -1);
1039 String fileExt = getExtension(filename);
1049 * Checks whether the extension of the filename is one of those specified.
1051 * This method obtains the extension as the textual part of the filename
1055 * @param filename the filename to query, null returns false
1057 * @return true if the filename is one of the extensions
1059 public static boolean isExtension(String filename, Collection<String> extensions) {
1060 if (filename == null) {
1064 return (indexOfExtension(filename) == -1);
1066 String fileExt = getExtension(filename);
1077 * Checks a filename to see if it matches the specified wildcard matcher,
1092 * @param filename the filename to match on
1094 * @return true if the filename matches the wilcard string
1097 public static boolean wildcardMatch(String filename, String wildcardMatcher) {
1098 return wildcardMatch(filename, wildcardMatcher, IOCase.SENSITIVE);
1102 * Checks a filename to see if it matches the specified wildcard matcher
1117 * @param filename the filename to match on
1119 * @return true if the filename matches the wilcard string
1122 public static boolean wildcardMatchOnSystem(String filename, String wildcardMatcher) {
1123 return wildcardMatch(filename, wildcardMatcher, IOCase.SYSTEM);
1127 * Checks a filename to see if it matches the specified wildcard matcher
1133 * @param filename the filename to match on
1136 * @return true if the filename matches the wilcard string
1139 public static boolean wildcardMatch(String filename, String wildcardMatcher, IOCase caseSensitivity) {
1140 if (filename == null && wildcardMatcher == null) {
1143 if (filename == null || wildcardMatcher == null) {
1149 filename = caseSensitivity.convertCase(filename);
1178 textIdx = filename.length();
1185 textIdx = filename.indexOf(wcs[wcsIdx], textIdx);
1190 int repeat = filename.indexOf(wcs[wcsIdx], textIdx + 1);
1196 if (!filename.startsWith(wcs[wcsIdx], textIdx)) {
1211 if (wcsIdx == wcs.length && textIdx == filename.length()) {