Java Path File Name nio getBandNameStr(Path filePath)

Here you can find the source of getBandNameStr(Path filePath)

Description

Get the band name string from the specified filepath.

License

Open Source License

Parameter

Parameter Description
filePath The given file path.

Return

Returns band name if found otherwise null.

Declaration

public static String getBandNameStr(Path filePath) 

Method Source Code

//package com.java2s;
/*/*from w  w  w  .j a v  a2  s  .  c  o m*/
 * This file is part of the Raster Storage Archive (RSA).
 *
 * The RSA 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.
 *
 * The RSA 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
 * the RSA.  If not, see <http://www.gnu.org/licenses/>.
 *
 * Copyright 2013 CRCSI - Cooperative Research Centre for Spatial Information
 * http://www.crcsi.com.au/
 */

import java.nio.file.Path;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main {
    protected static Pattern LANDSAT_BAND_PATTERN = Pattern.compile(".*_[0-9]{8}_(B[0-9]+).[a-zA-Z]+$");

    /**
     * Get the band name string from the specified filepath.
     * @param filePath The given file path.
     * @return Returns band name if found otherwise null.
     */
    public static String getBandNameStr(Path filePath) {
        String fileNameStr = filePath.getFileName().toString();

        Matcher m = LANDSAT_BAND_PATTERN.matcher(fileNameStr);
        if (m.matches()) {
            return m.group(1);
        }

        throw new IllegalArgumentException(String.format("Could not find band name in file name %s.", fileNameStr));
    }
}

Related

  1. getAbsolutePath(String fileName)
  2. getAbsolutePath(String name)
  3. getAbsolutePathName(File dir)
  4. getAllFiles(List fileNames, Path path)
  5. getArtifactName(Path artifactPath)
  6. getClassName(Path pluginImplementationDirectory, Path classFile)
  7. getConfigurationFile(String installPath, String serverName)
  8. getConfigurationFilePath(String name)
  9. getContentPath(Path zipFilePath, String contentFileName)