001/*
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements.  See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership.  The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License.  You may obtain a copy of the License at
009 *
010 *   https://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing,
013 * software distributed under the License is distributed on an
014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015 * KIND, either express or implied.  See the License for the
016 * specific language governing permissions and limitations
017 * under the License.
018 */
019
020package org.apache.commons.compress.utils;
021
022import java.io.File;
023import java.nio.file.Path;
024
025import org.apache.commons.io.FilenameUtils;
026import org.apache.commons.io.file.PathUtils;
027
028/**
029 * Generic file name utilities.
030 *
031 * @since 1.20
032 * @deprecated Use {@link PathUtils} and {@link FilenameUtils}.
033 */
034@Deprecated
035public class FileNameUtils {
036
037    /**
038     * Gets the base name (i.e. the part up to and not including the last ".") of the last path segment of a file name.
039     * <p>
040     * Will return the file name itself if it doesn't contain any dots. All leading directories of the {@code file name} parameter are skipped.
041     * </p>
042     *
043     * @return the base name of file name
044     * @param path the path of the file to obtain the base name of.
045     * @since 1.22
046     * @deprecated Use {@link PathUtils#getBaseName(Path)}.
047     */
048    @Deprecated
049    public static String getBaseName(final Path path) {
050        return PathUtils.getBaseName(path);
051    }
052
053    /**
054     * Gets the base name (i.e. the part up to and not including the last ".") of the last path segment of a file name.
055     * <p>
056     * Will return the file name itself if it doesn't contain any dots. All leading directories of the {@code file name} parameter are skipped.
057     * </p>
058     *
059     * @return the base name of file name
060     * @param fileName the name of the file to obtain the base name of.
061     * @deprecated Use {@link FilenameUtils#removeExtension(String)}.
062     */
063    @Deprecated
064    public static String getBaseName(final String fileName) {
065        if (fileName == null) {
066            return null;
067        }
068        return FilenameUtils.removeExtension(new File(fileName).getName());
069    }
070
071    /**
072     * Gets the extension (i.e. the part after the last ".") of a file.
073     * <p>
074     * 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
075     * directories of the {@code file name} parameter are skipped.
076     * </p>
077     *
078     * @return the extension of file name
079     * @param path the path of the file to obtain the extension of.
080     * @since 1.22
081     * @deprecated Use {@link PathUtils#getExtension(Path)}.
082     */
083    @Deprecated
084    public static String getExtension(final Path path) {
085        return PathUtils.getExtension(path);
086    }
087
088    /**
089     * Gets the extension (i.e. the part after the last ".") of a file.
090     * <p>
091     * 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
092     * directories of the {@code fileName} parameter are skipped.
093     * </p>
094     *
095     * @return the extension of file name
096     * @param fileName the name of the file to obtain the extension of.
097     * @deprecated Use {@link FilenameUtils#getExtension(String)}.
098     */
099    @Deprecated
100    public static String getExtension(final String fileName) {
101        return FilenameUtils.getExtension(fileName);
102    }
103}