List of usage examples for java.nio.file Path getNameCount
int getNameCount();
From source file:fr.lille1.car.burihabwa.rest.utils.FTPAdapterImpl.java
public String getFile(final String path) { Path completePath = Paths.get(path); int nameCount = completePath.getNameCount(); return completePath.getName(nameCount - 1).toString(); }
From source file:org.xwiki.filter.xff.internal.input.ClassesReader.java
private void routeProperty(Path path, InputStream inputStream) throws FilterException { String filename = path.getFileName().toString(); String filePropertyName = path.getName(path.getNameCount() - 2).toString(); for (Property property : this.xClass.getProperties()) { String propertyName = property.getName(); if (filePropertyName.equals(propertyName)) { for (Attribute attribute : property.getAttributes()) { String attributeName = attribute.getName(); if (filename.startsWith(attributeName + '.')) { try { attribute.setValue(IOUtils.toString(inputStream)); } catch (IOException e) { String message = String.format("Unable to read a string from '%s'.", path.toString()); throw new FilterException(message, e); }//from w ww . j a v a 2 s. c om } } } } }
From source file:fr.lille1.car.burihabwa.rest.utils.FTPAdapterImpl.java
@Override public boolean isDirectory(final String path) throws IOException { if (path == null) { throw new IllegalArgumentException("path argument cannot be null!"); }/* w ww.j a va 2 s . com*/ if (!this.client.isConnected()) { this.authenticate(); } Path filePath = Paths.get(path); int nameCount = filePath.getNameCount(); FTPFile[] directories = this.client.listDirectories(); for (FTPFile directory : directories) { if (directory.getName().equalsIgnoreCase(path)) { return true; } } return false; }
From source file:de.elomagic.carafile.client.CaraCloud.java
String getSubPath(final Path path) { Path p = path.subpath(basePath.getNameCount(), path.getNameCount()); return p.toString().replace("\\", "/"); }
From source file:at.tfr.securefs.process.ProcessFilesBean.java
/** * Copy from path to path, decrypting with activated secret and encrypting using provided newSecret. *///from w ww. j a v a 2s. co m @Override public void copy(Path from, final Path to, CrypterProvider crypterProvider, BigInteger newSecret, ProcessFilesData cfd) throws IOException { Files.createDirectories(to); int fromStartIndex = from.getNameCount(); Files.walk(from).filter(d -> !d.equals(from)).forEach((fromPath) -> { if (cfd.isProcessActive()) { copy(fromPath, fromStartIndex, to, crypterProvider, newSecret, cfd); } }); }
From source file:com.basistech.yca.FlatteningConfigFileManager.java
private String[] parsePid(Path path) { String filename = path.getName(path.getNameCount() - 1).toString(); String pid = filename.substring(0, filename.lastIndexOf('.')); int n = pid.indexOf('-'); if (n > 0) { String factoryPid = pid.substring(n + 1); pid = pid.substring(0, n);//from ww w . j av a2 s . c om return new String[] { pid, factoryPid }; } else { return new String[] { pid, null }; } }
From source file:at.tfr.securefs.process.ProcessFilesBean.java
public void copy(Path fromPath, int fromStartIndex, Path toRootPath, CrypterProvider cp, BigInteger newSecret, ProcessFilesData cfd) {/* w w w. j a v a 2s . c om*/ Path toPath = toRootPath.resolve(fromPath.subpath(fromStartIndex, fromPath.getNameCount())); try { if (Files.isRegularFile(fromPath)) { if (Files.isRegularFile(toPath)) { if (!cfd.isAllowOverwriteExisting()) { throw new SecureFSError("overwrite of existing file not allowed: " + toPath); } if (cfd.isUpdate() && Files.getLastModifiedTime(fromPath).toInstant() .isBefore(Files.getLastModifiedTime(toPath).toInstant())) { log.info("not overwriting from: " + fromPath.toAbsolutePath() + " to: " + toPath.toAbsolutePath()); return; } } // write source to target cfd.setCurrentFromPath(fromPath.toAbsolutePath().toString()); cfd.setCurrentToPath(toPath.toAbsolutePath().toString()); updateCache(cfd); try (OutputStream os = cp.getEncrypter(toPath, newSecret); InputStream is = cp.getDecrypter(fromPath)) { IOUtils.copy(is, os); } log.info("copied from: " + fromPath.toAbsolutePath() + " to: " + toPath.toAbsolutePath()); } if (Files.isDirectory(fromPath)) { Path subDir = Files.createDirectories(toPath); log.info("created subDir: " + subDir.toAbsolutePath()); } } catch (Exception e) { throw new SecureFSError("cannot copy from: " + fromPath + " to: " + toPath, e); } }
From source file:org.openhab.tools.analysis.checkstyle.ServiceComponentManifestCheck.java
private int getIndex(Path path, String dirName) { int result = -1; for (int i = 0; i < path.getNameCount(); i++) { if (path.getName(i).toString().equals(dirName)) { result = i;/* www .j a va2s . co m*/ break; } } return result; }
From source file:com.surevine.gateway.scm.IncomingProcessorImpl.java
private Path findFileEndsWith(final Collection<Path> paths, final String endsWith) { for (final Path entry : paths) { final String lastPath = entry.getName(entry.getNameCount() - 1).toString(); if (StringUtils.endsWith(lastPath, endsWith)) { return entry; }//w w w . j a v a2 s. co m } return null; }
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 {//www . j a v a 2 s . co 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); }