List of usage examples for java.nio.file Path getNameCount
int getNameCount();
From source file:org.apache.gobblin.config.store.zip.ZipFileConfigStore.java
/** * Retrieves all the children of the given {@link ConfigKeyPath} using {@link Files#walk} to list files *//*www . j ava2 s.co m*/ @Override public Collection<ConfigKeyPath> getChildren(ConfigKeyPath configKey, String version) throws VersionDoesNotExistException { Preconditions.checkNotNull(configKey, "configKey cannot be null!"); Preconditions.checkArgument(version.equals(getCurrentVersion())); List<ConfigKeyPath> children = new ArrayList<>(); Path datasetDir = getDatasetDirForKey(configKey); try { if (!Files.exists(this.fs.getPath(datasetDir.toString()))) { return children; } Stream<Path> files = Files.walk(datasetDir, 1); for (Iterator<Path> it = files.iterator(); it.hasNext();) { Path path = it.next(); if (Files.isDirectory(path) && !path.equals(datasetDir)) { children.add(configKey .createChild(StringUtils.removeEnd(path.getName(path.getNameCount() - 1).toString(), SingleLinkedListConfigKeyPath.PATH_DELIMETER))); } } return children; } catch (IOException e) { throw new RuntimeException( String.format("Error while getting children for configKey: \"%s\"", configKey), e); } }
From source file:com.surevine.gateway.scm.IncomingProcessorImpl.java
public Path getTmpExtractionPath(final Path archivePath) { String tmpDir = PropertyUtil.getTempDir(); final String filename = archivePath.getName(archivePath.getNameCount() - 1).toString(); tmpDir += "/" + filename.substring(0, filename.indexOf('.')); return new File(tmpDir).toPath(); }
From source file:com.thinkbiganalytics.metadata.modeshape.support.JcrPath.java
@Override public int compareTo(Path other) { int len = Math.min(other.getNameCount(), getNameCount()); for (int idx = 0; idx < len; idx++) { int value = other.getName(idx).toString().compareTo(getName(idx).toString()); if (value != 0) { return value; }/*from www.j a v a 2 s .c om*/ } return Integer.compare(other.getNameCount(), getNameCount()); }
From source file:api.wiki.WikiGenerator.java
private Path copyToReleaseDirectory(Path file, Path releaseDirectory) { try {//from ww w .j a v a 2s. com Path target = releaseDirectory .resolve(file.subpath(wikiDirectory().getNameCount(), file.getNameCount())); Files.createDirectories(target.subpath(1, target.getNameCount() - 1)); return Files.copy(file, target); } catch (IOException e) { throw new IllegalStateException(e); } }
From source file:com.thinkbiganalytics.metadata.modeshape.support.JcrPath.java
@Override public boolean endsWith(Path other) { int offset = getNameCount() - other.getNameCount(); if (offset < 0) { return false; } else {/* w ww.j av a 2 s . c o m*/ for (int idx = getNameCount() - 1; idx - offset >= 0; idx--) { Path otherElem = other.getName(idx - offset); if (otherElem.getFileName().equals(this.elements.get(idx))) { return false; } } return true; } }
From source file:com.thinkbiganalytics.metadata.modeshape.support.JcrPath.java
@Override public Path relativize(Path other) { if (other.isAbsolute() != isAbsolute() || other.getNameCount() < getNameCount()) { return other; } else if (other.getNameCount() == 0) { return this; } else {// w w w . j a v a 2 s . c om int idx = 0; for (; idx < getNameCount(); idx++) { if (!other.getName(idx).equals(getName(idx))) { return other; } } return other.subpath(idx - 1, other.getNameCount()); } }
From source file:de.ncoder.studipsync.Syncer.java
public boolean areFilesInSync(List<Download> downloads, List<Path> localFiles) throws IOException { if (!checkLevel.includes(CheckLevel.Files)) { return true; }//from w ww . j a va 2 s .c o m for (Download download : downloads) { //Find matching candidates List<Path> localCandidates = new LinkedList<>(); for (Path local : localFiles) { // Check candidate name if (local.getName(local.getNameCount() - 1).toString().equals(download.getFileName())) { if (!localCandidates.isEmpty()) { //Already found a candidate log.debug(marker, "Local files " + localCandidates + " and " + local + " match " + download + "!"); } localCandidates.add(local); //Check LastModifiedTime if (!checkLevel.includes(CheckLevel.ModTime)) { continue; } Date localLastMod = new Date(Files.getLastModifiedTime(local).toMillis()); if (!localLastMod.after(download.getLastModified())) { //Candidate *potentially* outdated log.warn(marker, "Local file " + local + "(" + localLastMod + ") older than online Version " + download + "(" + download.getLastModified() + ")!"); return false; } } } //Require at least one candidate if (localCandidates.isEmpty()) { //No candidates found log.warn(marker, "No local file matching " + download + " (~" + download.getFileName() + ")!"); return false; } } return true; }
From source file:com.thinkbiganalytics.metadata.modeshape.support.JcrPath.java
@Override public Path resolveSibling(Path other) { if (other.isAbsolute()) { return other; } else if (other.getNameCount() == 0) { return this; } else {/*from w w w . ja v a2 s .c o m*/ return getParent().resolve(other); } }
From source file:com.thinkbiganalytics.metadata.modeshape.support.JcrPath.java
@Override public Path resolve(Path other) { if (other.isAbsolute()) { return other; } else if (other.getNameCount() == 0) { return this; } else {/*from w w w . j a va 2s . c om*/ List<String> elements = new ArrayList<>(this.elements); for (int idx = 0; idx < other.getNameCount(); idx++) { elements.add(other.getName(idx).toString()); } return new JcrPath(this.absolute, elements); } }
From source file:com.mkl.websuites.internal.tests.ScenarioFolderTest.java
private void processRecursivelyFolder(Path folderPath, TestSuite parentSuite) { TestSuite currentFolderSuite;/* w ww .ja v a 2 s . c om*/ if (isTopTest) { currentFolderSuite = new TestSuite(folderPath.toString()); isTopTest = false; } else { currentFolderSuite = new TestSuite( folderPath.subpath(folderPath.getNameCount() - 1, folderPath.getNameCount()).toString()); } List<Test> testsInCurrentFolder = processScenarioFilesInFolder(folderPath.toString()); for (Test test : testsInCurrentFolder) { currentFolderSuite.addTest(test); } parentSuite.addTest(currentFolderSuite); if (ignoreSubfolders) { return; } File folder = new File(folderPath.toString()); File[] nestedFolders = folder.listFiles(new FileFilter() { @Override public boolean accept(File file) { return file.isDirectory(); } }); if (nestedFolders == null) { throw new WebServiceException(String.format("Error while traversing through folder " + "structure starting from path '%s'. Probably there is something wrong " + "in the path string.", folderPath)); } sort(nestedFolders); for (File nested : nestedFolders) { processRecursivelyFolder(Paths.get(nested.toURI()), currentFolderSuite); } }