List of utility methods to do Path File Name nio
Path | getAbsolutePath(String name) get Absolute Path return Paths.get(name).toAbsolutePath();
|
String | getAbsolutePathName(File dir) get Absolute Path Name try { return getAbsolutePath(dir).toString(); } catch (IOException e) { return dir.getAbsolutePath(); |
List | getAllFiles(List Collect all the files in a given path recursively try (DirectoryStream<Path> stream = Files.newDirectoryStream(path)) { for (Path subPath : stream) { if (subPath.toFile().isDirectory()) { getAllFiles(fileNames, subPath); } else { String fileName = subPath.toAbsolutePath().toString(); fileNames.add(fileName); } catch (IOException e) { throw e; return fileNames; |
String | getArtifactName(Path artifactPath) utility method which returns the name of the web artifact specified String artifactFileName = artifactPath.getFileName().toString();
return artifactFileName.substring(0, artifactFileName.length() - 4);
|
String | getBandNameStr(Path filePath) Get the band name string from the specified 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)); |
String | getClassName(Path pluginImplementationDirectory, Path classFile) get Class Name String className = pluginImplementationDirectory.relativize(classFile).toString() .replace(JAR_DIRECTORY_SEPARATOR, PACKAGE_SEPARATOR).replace(CLASS_FILE_EXTENSION, ""); if (className.startsWith(PACKAGE_SEPARATOR) && className.length() > 1) { className = className.substring(1); return className; |
Path | getConfigurationFile(String installPath, String serverName) get Configuration File Path curServerPath = getServerDir(installPath, serverName);
return curServerPath.resolve(SERVER_CONFIG_FILE);
|
Path | getConfigurationFilePath(String name) get Configuration File Path return getConfigurationDirectoryPath().resolve(name);
|
Path | getContentPath(Path zipFilePath, String contentFileName) get Content Path try { FileSystem zipFile = FileSystems.newFileSystem(zipFilePath, null); Path packagedPath = zipFile.getPath(contentFileName); if (Files.exists(packagedPath)) { return packagedPath; } else { return null; } catch (IOException e) { throw new RuntimeException(e); |
Path | getDatabaseDirectoryPath(String databaseDirectory, String name) get Database Directory Path if (Paths.get(databaseDirectory).isAbsolute()) { return Paths.get(databaseDirectory, name); } else { return Paths.get(getProperty("user.dir"), databaseDirectory, name); |