List of usage examples for java.nio.file Path getNameCount
int getNameCount();
From source file:misc.FileHandler.java
/** * Returns whether the given path is a folder name. The current path * <code>.</code> is considered a folder name. * /*from ww w .j a v a 2 s .co m*/ * @param folderName * the folder name to check. * @return <code>true</code>, if the folder name is a folder name. * Otherwise, <code>false</code> is returned. */ public static boolean isFolderName(Path folderName) { if (folderName == null) { return false; } Path relativePath = ROOT_PATH.resolve(folderName).normalize(); return ROOT_PATH.equals(folderName) || (!"".equals(relativePath.toString()) && (relativePath.getNameCount() == 1)); }
From source file:com.ejisto.util.visitor.ConditionMatchingCopyFileVisitor.java
private void copy(Path srcFile) throws IOException { Path relative = options.srcRoot.relativize(srcFile); int count = relative.getNameCount(); StringBuilder newFileName = new StringBuilder(); if (count > 1) { newFileName.append(relative.getParent().toString()); newFileName.append(File.separator); }/*from w w w.ja v a 2 s .c om*/ newFileName.append(defaultString(options.filesPrefix)).append(srcFile.getFileName().toString()); Files.copy(srcFile, options.targetRoot.resolve(newFileName.toString()), StandardCopyOption.REPLACE_EXISTING); }
From source file:org.elasticsearch.plugins.SitePluginRelativePathConfigIT.java
private String getRelativePath(Path path) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < path.getNameCount(); i++) { sb.append(".."); sb.append(path.getFileSystem().getSeparator()); }/*from ww w. j a v a2s . c om*/ return sb.toString(); }
From source file:org.openhab.tools.analysis.checkstyle.KarafFeatureCheck.java
private Path resolveRecursively(Path absolute, Path relativePath) { while (absolute.getNameCount() > 0) { absolute = absolute.getParent(); Path resolved = absolute.resolve(relativePath); if (Files.exists(resolved)) { return resolved; }//from w w w . j ava2 s. c om } return null; }
From source file:io.cloudslang.intellij.lang.completion.macro.CurrentNamespaceMacro.java
private String fixNamespace(final String projectPath, final String filePath) { // Exclude file name from namespace value Path relativePath = get(projectPath).relativize(get(new File(filePath).getParent())); int nameCount = relativePath.getNameCount(); if ((nameCount <= 0) || StringUtils.isEmpty(relativePath.toString())) { return DEFAULT_NAMESPACE_TO_USE; }/* ww w .jav a 2s. com*/ StringBuilder strBuilder = new StringBuilder(relativePath.toString().length()); int nameCountMinusOne = nameCount - 1; for (int index = 0; index < nameCount; index++) { String cleanPart = fixPathPart(relativePath.getName(index).toString()); if (isNotEmpty(cleanPart)) { strBuilder.append(cleanPart.toLowerCase(ENGLISH)); // namespace should be lowercase if (index < nameCountMinusOne) { strBuilder.append(NAMESPACE_SEPARATOR); } } } return strBuilder.toString(); }
From source file:org.apache.beam.sdk.io.LocalResourceId.java
@Override public LocalResourceId getCurrentDirectory() { if (isDirectory) { return this; } else {//from w w w .ja v a 2s. c om Path path = getPath(); Path parent = path.getParent(); if (parent == null && path.getNameCount() == 1) { parent = Paths.get("."); } checkState(parent != null, "Failed to get the current directory for path: [%s].", pathString); return fromPath(parent, true /* isDirectory */); } }
From source file:org.sleuthkit.autopsy.casemodule.SingleUserCaseConverter.java
/** * Fix up any paths in the database that refer to items that have moved. * Candidates include events.db, input images, reports, file paths, etc. * * @param icd the Import Case Data for the current case * * @throws Exception// www .j av a 2s . co m * @throws SQLExceptionException */ private static void fixPaths(ImportCaseData icd) throws SQLException, Exception { /// Fix paths in reports, tsk_files_path, and tsk_image_names tables String input = icd.getImageInputFolder().toString(); String output = icd.getImageOutputFolder().toString(); Connection postgresqlConnection = getPostgreSQLConnection(icd); if (postgresqlConnection != null) { String hostName = NetworkUtils.getLocalHostName(); // add hostname to reports Statement updateStatement = postgresqlConnection.createStatement(); updateStatement.executeUpdate("UPDATE reports SET path=CONCAT('" + hostName + "/', path) WHERE path IS NOT NULL AND path != ''"); //NON-NLS // add hostname to tsk_files_path updateStatement = postgresqlConnection.createStatement(); updateStatement.executeUpdate("UPDATE tsk_files_path SET path=CONCAT('" + hostName + "\\', path) WHERE path IS NOT NULL AND path != ''"); //NON-NLS String caseName = icd.getRawFolderName().toLowerCase(); if (icd.getCopySourceImages()) { // update path for images Statement inputStatement = postgresqlConnection.createStatement(); ResultSet inputResultSet = inputStatement.executeQuery("SELECT * FROM tsk_image_names"); //NON-NLS while (inputResultSet.next()) { Path oldPath = Paths.get(inputResultSet.getString(2)); for (int x = 0; x < oldPath.getNameCount(); ++x) { if (oldPath.getName(x).toString().toLowerCase().equals(caseName)) { Path newPath = Paths.get(output, oldPath.subpath(x + 1, oldPath.getNameCount()).toString()); updateStatement = postgresqlConnection.createStatement(); updateStatement.executeUpdate("UPDATE tsk_image_names SET name='" + newPath.toString() + "' WHERE obj_id = " + inputResultSet.getInt(1)); //NON-NLS break; } } } } postgresqlConnection.close(); } else { throw new Exception(NbBundle.getMessage(SingleUserCaseConverter.class, "SingleUserCaseConverter.CanNotOpenDatabase")); //NON-NLS } }
From source file:platform.tooling.support.Runner.java
private Path getCurrentJdkHome() { Path executable = ProcessHandle.current().info().command().map(Paths::get).orElse(null); if (executable != null && executable.getNameCount() > 2) { // noinspection ConstantConditions -- count is 3 or higher: "<JDK_HOME>/bin/java[.exe]" return executable.getParent().getParent().toAbsolutePath(); }/*from ww w . jav a 2 s. c om*/ String jdkHome = System.getenv("JDK_HOME"); if (jdkHome != null) { return Paths.get(jdkHome).toAbsolutePath(); } String javaHome = System.getenv("JAVA_HOME"); if (javaHome != null) { return Paths.get(javaHome).toAbsolutePath(); } return Paths.get("jdk-" + Runtime.version().feature()).toAbsolutePath(); }
From source file:de.tudarmstadt.ukp.dkpro.core.api.datasets.internal.actions.Explode.java
private String stripLeadingFolders(String aName, int aLevels) { if (aLevels > 0) { Path p = Paths.get(aName); if (p.getNameCount() <= aLevels) { return null; } else {//from www .j a va 2 s . c om p = p.subpath(aLevels, p.getNameCount()); aName = p.toString(); return aName; } } else { return aName; } }
From source file:fr.lille1.car.burihabwa.rest.utils.FTPAdapterImpl.java
@Override public String getParentDirectory(final String path) { if (path == null) { return ""; }//from w ww . j a va2 s . c o m Path file = Paths.get(path); int nameCount = file.getNameCount(); String parentDirectory = ""; if (nameCount > 1) { parentDirectory = file.subpath(0, nameCount - 1).toString(); } return parentDirectory; }