Java Path File Name nio getPrefix(final Path file, final int filenameSuffixLength)

Here you can find the source of getPrefix(final Path file, final int filenameSuffixLength)

Description

Get part of filename before given suffix

License

Open Source License

Parameter

Parameter Description
file path
filenameSuffixLength length of the suffix

Exception

Parameter Description
IllegalArgumentException file has no filename (probably root of filesystem)

Return

prefix

Declaration

public static String getPrefix(final Path file,
        final int filenameSuffixLength) throws IllegalArgumentException 

Method Source Code

//package com.java2s;
/**/*from   ww w. j  a  v a 2 s .  c  o  m*/
 * Copyright (C) 2012-2016 Thales Services SAS.
 *
 * This file is part of AuthZForce CE.
 *
 * AuthZForce CE is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * AuthZForce CE is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with AuthZForce CE.  If not, see <http://www.gnu.org/licenses/>.
 */

import java.nio.file.Path;

public class Main {
    /**
     * Get part of filename before given suffix
     * 
     * @param file
     *            path
     * @param filenameSuffixLength
     *            length of the suffix
     * @return prefix
     * @throws IllegalArgumentException
     *             file has no filename (probably root of filesystem)
     */
    public static String getPrefix(final Path file,
            final int filenameSuffixLength) throws IllegalArgumentException {
        assert file != null;

        final Path fileName = file.getFileName();
        if (fileName == null) {
            throw new IllegalArgumentException(
                    "Invalid file (no filename, probably root?): " + file);
        }

        final String filename = fileName.toString();
        return filename.substring(0, filename.length()
                - filenameSuffixLength);

    }
}

Related

  1. getPathInTmpDir(String fileName)
  2. GetPathName(String path)
  3. getPathOfClass(Class cls, String filename)
  4. getPathProperty(Properties props, String propName)
  5. getPaths(Path dir, String fileNames)
  6. getPrintWriter(String className, String flushPath)
  7. getProvenanceLogFiles(final String baseName, final Collection allProvenanceLogs)
  8. getQualifiedName(String outputDir, Path path)
  9. getRelativePathFile(String fileName)