1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one 3 * or more contributor license agreements. See the NOTICE file 4 * distributed with this work for additional information 5 * regarding copyright ownership. The ASF licenses this file 6 * to you under the Apache License, Version 2.0 (the 7 * "License"); you may not use this file except in compliance 8 * with the License. You may obtain a copy of the License at 9 * 10 * https://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, 13 * software distributed under the License is distributed on an 14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 * KIND, either express or implied. See the License for the 16 * specific language governing permissions and limitations 17 * under the License. 18 */ 19 20 package org.apache.commons.compress.utils; 21 22 import java.io.File; 23 import java.nio.file.Path; 24 25 import org.apache.commons.io.FilenameUtils; 26 import org.apache.commons.io.file.PathUtils; 27 28 /** 29 * Generic file name utilities. 30 * 31 * @since 1.20 32 * @deprecated Use {@link PathUtils} and {@link FilenameUtils}. 33 */ 34 @Deprecated 35 public class FileNameUtils { 36 37 /** 38 * Gets the base name (i.e. the part up to and not including the last ".") of the last path segment of a file name. 39 * <p> 40 * Will return the file name itself if it doesn't contain any dots. All leading directories of the {@code file name} parameter are skipped. 41 * </p> 42 * 43 * @return the base name of file name 44 * @param path the path of the file to obtain the base name of. 45 * @since 1.22 46 * @deprecated Use {@link PathUtils#getBaseName(Path)}. 47 */ 48 @Deprecated 49 public static String getBaseName(final Path path) { 50 return PathUtils.getBaseName(path); 51 } 52 53 /** 54 * Gets the base name (i.e. the part up to and not including the last ".") of the last path segment of a file name. 55 * <p> 56 * Will return the file name itself if it doesn't contain any dots. All leading directories of the {@code file name} parameter are skipped. 57 * </p> 58 * 59 * @return the base name of file name 60 * @param fileName the name of the file to obtain the base name of. 61 * @deprecated Use {@link FilenameUtils#removeExtension(String)}. 62 */ 63 @Deprecated 64 public static String getBaseName(final String fileName) { 65 if (fileName == null) { 66 return null; 67 } 68 return FilenameUtils.removeExtension(new File(fileName).getName()); 69 } 70 71 /** 72 * Gets the extension (i.e. the part after the last ".") of a file. 73 * <p> 74 * Will return an empty string if the file name doesn't contain any dots. Only the last segment of a the file name is consulted - i.e. all leading 75 * directories of the {@code file name} parameter are skipped. 76 * </p> 77 * 78 * @return the extension of file name 79 * @param path the path of the file to obtain the extension of. 80 * @since 1.22 81 * @deprecated Use {@link PathUtils#getExtension(Path)}. 82 */ 83 @Deprecated 84 public static String getExtension(final Path path) { 85 return PathUtils.getExtension(path); 86 } 87 88 /** 89 * Gets the extension (i.e. the part after the last ".") of a file. 90 * <p> 91 * Will return an empty string if the file name doesn't contain any dots. Only the last segment of a the file name is consulted - i.e. all leading 92 * directories of the {@code fileName} parameter are skipped. 93 * </p> 94 * 95 * @return the extension of file name 96 * @param fileName the name of the file to obtain the extension of. 97 * @deprecated Use {@link FilenameUtils#getExtension(String)}. 98 */ 99 @Deprecated 100 public static String getExtension(final String fileName) { 101 return FilenameUtils.getExtension(fileName); 102 } 103 }