List of usage examples for java.nio.file Path getName
Path getName(int index);
From source file:org.roda.core.plugins.plugins.characterization.ExifToolPlugin.java
private void processAIP(IndexService index, ModelService model, StorageService storage, Report report, SimpleJobPluginInfo jobPluginInfo, Job job, AIP aip) { LOGGER.debug("Processing AIP {}", aip.getId()); boolean inotify = false; Report reportItem = PluginHelper.initPluginReportItem(this, aip.getId(), AIP.class, AIPState.INGEST_PROCESSING); PluginHelper.updatePartialJobReport(this, model, reportItem, false, job); PluginState reportState = PluginState.SUCCESS; ValidationReport validationReport = new ValidationReport(); List<LinkingIdentifier> sources = new ArrayList<>(); for (Representation representation : aip.getRepresentations()) { LOGGER.debug("Processing representation {} from AIP {}", representation.getId(), aip.getId()); DirectResourceAccess directAccess = null; try {/*from w w w. ja v a2 s.c o m*/ StoragePath representationDataPath = ModelUtils.getRepresentationDataStoragePath(aip.getId(), representation.getId()); directAccess = storage.getDirectAccess(representationDataPath); sources.add(PluginHelper.getLinkingIdentifier(aip.getId(), representation.getId(), RodaConstants.PRESERVATION_LINKING_OBJECT_SOURCE)); CloseableIterable<OptionalWithCause<org.roda.core.data.v2.ip.File>> allFiles = model .listFilesUnder(aip.getId(), representation.getId(), true); if (!CloseableIterables.isEmpty(allFiles)) { Path metadata = Files.createTempDirectory("metadata"); ExifToolPluginUtils.runExifToolOnPath(directAccess.getPath(), metadata); try (DirectoryStream<Path> directoryStream = Files.newDirectoryStream(metadata)) { for (Path path : directoryStream) { ContentPayload payload = new FSPathContentPayload(path); List<String> fileDirectoryPath = new ArrayList<>(); Path relativePath = metadata.relativize(path); for (int i = 0; i < relativePath.getNameCount() - 2; i++) { fileDirectoryPath.add(relativePath.getName(i).toString()); } String fileId = path.getFileName().toString(); model.createOrUpdateOtherMetadata(aip.getId(), representation.getId(), fileDirectoryPath, fileId, ".xml", RodaConstants.OTHER_METADATA_TYPE_EXIFTOOL, payload, inotify); } } FSUtils.deletePath(metadata); } } catch (RODAException | IOException e) { LOGGER.error("Error processing AIP {}: {}", aip.getId(), e.getMessage()); reportState = PluginState.FAILURE; validationReport.addIssue(new ValidationIssue(e.getMessage())); } finally { IOUtils.closeQuietly(directAccess); } } try { model.notifyAipUpdated(aip.getId()); } catch (RequestNotValidException | GenericException | NotFoundException | AuthorizationDeniedException e) { LOGGER.error("Error notifying of AIP update", e); } if (reportState.equals(PluginState.SUCCESS)) { jobPluginInfo.incrementObjectsProcessedWithSuccess(); reportItem.setPluginState(PluginState.SUCCESS); } else { jobPluginInfo.incrementObjectsProcessedWithFailure(); reportItem.setHtmlPluginDetails(true).setPluginState(PluginState.FAILURE); reportItem.setPluginDetails(validationReport.toHtml(false, false, false, "Error list")); } try { PluginHelper.createPluginEvent(this, aip.getId(), model, index, sources, null, reportItem.getPluginState(), "", true); } catch (ValidationException | RequestNotValidException | NotFoundException | GenericException | AuthorizationDeniedException | AlreadyExistsException e) { LOGGER.error("Error creating event: {}", e.getMessage(), e); } report.addReport(reportItem); PluginHelper.updatePartialJobReport(this, model, reportItem, true, job); }
From source file:com.surevine.gateway.scm.IncomingProcessorImpl.java
public boolean isTarGz(final Path archivePath) { try {/* ww w . j a v a 2s. c om*/ openTarGz(archivePath); return true; } catch (final Exception e) { LOGGER.debug("Verification of " + archivePath.getName(archivePath.getNameCount() - 1) + " failed: " + e.getMessage()); return false; } }
From source file:edu.illinois.cs.cogcomp.nlp.corpusreaders.ereReader.EREDocumentReader.java
private String getFileStem(Path filePath, String extension) { String fileName = filePath.getName(filePath.getNameCount() - 1).toString(); int lastIndex = fileName.lastIndexOf(extension); return fileName.substring(0, lastIndex); }
From source file:org.restcomm.connect.http.ProfileEndpoint.java
private String retrieveSid(URI uri) { Path paths = Paths.get(uri.getPath()); return paths.getName(paths.getNameCount() - 1).toString(); }
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 a2s .co m } return Integer.compare(other.getNameCount(), getNameCount()); }
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; }//from w w w .ja v a2 s . 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.codice.ddf.configuration.migration.ImportMigrationEntryImpl.java
/** * Instantiates a new migration entry by parsing the provided zip entry's name for a migratable * identifier and an entry relative name. * * @param contextProvider a provider for migration contexts given a migratable id * @param ze the zip entry for which we are creating an entry */// w ww . j a v a2 s . co m ImportMigrationEntryImpl(Function<String, ImportMigrationContextImpl> contextProvider, ZipEntry ze) { // we still must sanitize because there could be a mix of / and \ and Paths.get() doesn't // support that final Path fqn = Paths.get(FilenameUtils.separatorsToSystem(ze.getName())); final int count = fqn.getNameCount(); if (count > 1) { this.context = contextProvider.apply(fqn.getName(0).toString()); this.path = fqn.subpath(1, count); } else { // system entry this.context = contextProvider.apply(null); this.path = fqn; } this.absolutePath = context.getPathUtils().resolveAgainstDDFHome(path); this.file = absolutePath.toFile(); this.name = FilenameUtils.separatorsToUnix(path.toString()); this.entry = ze; this.isFile = true; }
From source file:io.undertow.server.handlers.file.FileHandlerSymlinksTestCase.java
@Test public void testCreateSymlinks() throws IOException, URISyntaxException { Path rootPath = Paths.get(getClass().getResource("page.html").toURI()).getParent(); Path newDir = rootPath.resolve("newDir"); Assert.assertFalse(Files.isSymbolicLink(newDir)); Path innerDir = newDir.resolve("innerDir"); Assert.assertFalse(Files.isSymbolicLink(innerDir)); Path newSymlink = rootPath.resolve("newSymlink"); Assert.assertTrue(Files.isSymbolicLink(newSymlink)); Path innerSymlink = newSymlink.resolve("innerSymlink"); Assert.assertTrue(Files.isSymbolicLink(innerSymlink)); Path f = innerSymlink.getRoot(); for (int i = 0; i < innerSymlink.getNameCount(); i++) { f = f.resolve(innerSymlink.getName(i).toString()); System.out.println(f + " " + Files.isSymbolicLink(f)); }/*from w ww. ja v a 2 s .co m*/ f = f.resolve("."); System.out.println(f + " " + Files.isSymbolicLink(f)); }
From source file:com.liferay.blade.cli.CreateCommand.java
private List<String> getTemplates() throws Exception { List<String> templateNames = new ArrayList<>(); File templatesZip = getGradleTemplatesZip(); try (Jar jar = new Jar(templatesZip)) { Map<String, Map<String, Resource>> directories = jar.getDirectories(); for (String key : directories.keySet()) { Path path = Paths.get(key); if (path.getNameCount() == 2 && path.startsWith("standalone")) { templateNames.add(path.getName(1).toString()); }/*w ww. j a va2 s. c o m*/ } } return templateNames; }
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 w w .j a v 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; } }