Here you can find the source of getBandNameStr(Path filePath)
Parameter | Description |
---|---|
filePath | The given file path. |
public static String getBandNameStr(Path filePath)
//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)); } }