List of usage examples for java.nio.file Path getFileName
Path getFileName();
From source file:org.alfresco.repo.bulkimport.impl.DirectoryAnalyserImpl.java
/** * @see org.alfresco.repo.bulkimport.DirectoryAnalyser#analyseDirectory(org.alfresco.repo.bulkimport.ImportableItem, java.nio.file.DirectoryStream.Filter) *///from ww w . j a v a 2s. c o m public AnalysedDirectory analyseDirectory(ImportableItem directory, DirectoryStream.Filter<Path> filter) { Path directoryFile = directory.getHeadRevision().getContentFile(); AnalysedDirectory result = new AnalysedDirectory(listFiles(directoryFile, filter)); if (log.isDebugEnabled()) { log.debug("Analysing directory " + FileUtils.getFileName(directoryFile) + "..."); } // Build up the list of ImportableItems from the directory listing for (Path file : result.getOriginalPaths()) { // MNT-9763 bulkimport fails when there is a very large LastModified timestamp. String isoDate = null; try { isoDate = ISO8601DateFormat .format(new Date(Files.getLastModifiedTime(file, LinkOption.NOFOLLOW_LINKS).toMillis())); ISO8601DateFormat.parse(isoDate); } catch (PlatformRuntimeException | IOException e) { log.warn("Failed to convert date " + isoDate + " to string for " + file.getFileName(), e); importStatus.incrementNumberOfUnreadableEntries(); continue; } if (log.isTraceEnabled()) { log.trace("Scanning file " + FileUtils.getFileName(file) + "..."); } if (Files.isReadable(file)) { try { nameChecker.evaluate(file.getFileName().toString()); } catch (ConstraintException e) { if (log.isWarnEnabled()) { log.warn("Skipping file with invalid name: '" + FileUtils.getFileName(file) + "'."); } // mark file with invalid name as unreadable importStatus.incrementNumberOfUnreadableEntries(); continue; } if (isVersionFile(file)) { addVersionFile(directory, result, file); importStatus.incrementNumberOfFilesScanned(); } else if (isMetadataFile(file)) { addMetadataFile(directory, result, file); importStatus.incrementNumberOfFilesScanned(); } else { boolean isDirectory = addParentFile(directory, result, file); if (isDirectory) { importStatus.incrementNumberOfFoldersScanned(); } else { importStatus.incrementNumberOfFilesScanned(); } } } else { if (log.isWarnEnabled()) { log.warn("Skipping unreadable file '" + FileUtils.getFileName(file) + "'."); } importStatus.incrementNumberOfUnreadableEntries(); } } // Finally, remove any items from the list that aren't valid (don't have either a // contentFile or a metadataFile) Iterator<ImportableItem> iter = result.getImportableItems().iterator(); while (iter.hasNext()) { ImportableItem importableItem = iter.next(); if (!importableItem.isValid() || !isMetadataValid(importableItem)) { iter.remove(); } } iter = result.getImportableDirectories().iterator(); while (iter.hasNext()) { ImportableItem importableItem = iter.next(); if (!importableItem.isValid()) { iter.remove(); } } if (log.isDebugEnabled()) { log.debug("Finished analysing directory " + FileUtils.getFileName(directoryFile) + "."); } return result; }
From source file:com.puppycrawl.tools.checkstyle.internal.XdocsPagesTest.java
@Test public void testAllCheckSectionsEx() throws Exception { final ModuleFactory moduleFactory = TestUtils.getPackageObjectFactory(); final Path path = Paths.get(XdocUtil.DIRECTORY_PATH + "/config.xml"); final String fileName = path.getFileName().toString(); final String input = new String(Files.readAllBytes(path), UTF_8); final Document document = XmlUtil.getRawXml(fileName, input, input); final NodeList sources = document.getElementsByTagName("section"); for (int position = 0; position < sources.getLength(); position++) { final Node section = sources.item(position); final String sectionName = section.getAttributes().getNamedItem("name").getNodeValue(); if (!"Checker".equals(sectionName) && !"TreeWalker".equals(sectionName)) { continue; }//w w w . ja va 2s .co m validateCheckSection(moduleFactory, fileName, sectionName, section); } }
From source file:me.ryandowling.allmightybot.AllmightyBot.java
private void loadUserChatLogs() { try (DirectoryStream<Path> directoryStream = Files.newDirectoryStream(Utils.getUsersDir())) { for (Path path : directoryStream) { if (Files.isDirectory(path)) { String username = path.getFileName().toString(); if (Files.exists(Utils.getUserChatFile(username))) { Type type = new TypeToken<List<ChatLog>>() { }.getType();/*from w w w.jav a2 s . co m*/ List<ChatLog> chatMessages = GSON.fromJson( FileUtils.readFileToString(Utils.getUserChatFile(username).toFile()), type); this.userLogs.put(username, chatMessages); } } } } catch (IOException ex) { } }
From source file:me.ryandowling.allmightybot.AllmightyBot.java
private void loadUserOnlineTime() { try (DirectoryStream<Path> directoryStream = Files.newDirectoryStream(Utils.getUsersDir())) { for (Path path : directoryStream) { if (Files.isDirectory(path)) { String username = path.getFileName().toString(); if (Files.exists(Utils.getUserLoginTimeFile(username))) { Type type = new TypeToken<Map<String, Integer>>() { }.getType();//ww w . ja v a2s . com Map<String, Integer> timeInChannel = GSON.fromJson( FileUtils.readFileToString(Utils.getUserLoginTimeFile(username).toFile()), type); this.userOnlineTime.put(username, timeInChannel); } } } } catch (IOException ex) { } }
From source file:io.github.swagger2markup.Swagger2MarkupMojo.java
private void swaggerToMarkup(Swagger2MarkupConverter converter, boolean inputIsLocalFolder) { if (outputFile != null) { Path useFile = outputFile.toPath(); /*/* ww w. jav a 2 s . com*/ * If user has specified input folder with multiple files to convert, * and has specified a single output file, then route all conversions * into one file under each 'new' sub-directory, which corresponds to * each input file. * Otherwise, specifying the output file with an input DIRECTORY means * last file converted wins. */ if (inputIsLocalFolder) { if (outputDir != null) { File effectiveOutputDir = outputDir; effectiveOutputDir = getEffectiveOutputDirWhenInputIsAFolder(converter); converter.getContext().setOutputPath(effectiveOutputDir.toPath()); useFile = Paths.get(effectiveOutputDir.getPath(), useFile.getFileName().toString()); } } if (getLog().isInfoEnabled()) { getLog().info("Converting input to one file: " + useFile); } converter.toFile(useFile); } else if (outputDir != null) { File effectiveOutputDir = outputDir; if (inputIsLocalFolder) { effectiveOutputDir = getEffectiveOutputDirWhenInputIsAFolder(converter); } if (getLog().isInfoEnabled()) { getLog().info("Converting input to multiple files in folder: '" + effectiveOutputDir + "'"); } converter.toFolder(effectiveOutputDir.toPath()); } else { throw new IllegalArgumentException("Either outputFile or outputDir parameter must be used"); } }
From source file:com.sesnu.orion.web.service.ReportService.java
private void sendApprovalEmail(Approval appr, String filePath, OrderView order) { Path path = new File(filePath).toPath(); String to = userDao.getUserName(appr.getRequestedBy()).getEmail(); String cc = userDao.getUserName(appr.getApprover()).getEmail(); String sfix = " (" + appr.getType() + ")"; String msg = "Attached file is a copy of the approval document for \n " + appr.getForName() + (appr.getType().equals("Order Authorization") ? "" : sfix); msg += " Invoice number " + order.getInvNo() + " , BL " + order.getBl(); String subject = "Approval for Order Autorisation - Inv No " + order.getInvNo(); if (appr.getType().equals("Payment")) { subject = "Payment Approval for " + appr.getForName() + " - Inv No " + order.getInvNo(); }// w w w.j a v a 2 s. c o m Util.sendMail(subject, to, msg, cc, path.getFileName().toString()); }
From source file:org.schedulesdirect.grabber.Grabber.java
private void loadSeriesInfoIds(Path root) throws IOException { Files.walkFileTree(root, new FileVisitor<Path>() { @Override// w ww .ja v a 2 s .c o m public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException { return FileVisitResult.SKIP_SUBTREE; } @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { String name = file.getFileName().toString(); name = name.substring(0, name.lastIndexOf('.')); cachedSeriesIds.add(name); return FileVisitResult.CONTINUE; } @Override public FileVisitResult visitFileFailed(Path file, IOException exc) throws IOException { throw exc; } @Override public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException { if (exc != null) throw exc; return FileVisitResult.CONTINUE; } }); }
From source file:org.orderofthebee.addons.support.tools.repo.AbstractLogFileWebScript.java
/** * Validates a single log file path and resolves it to a file handle. * * @param filePath/*from w ww .j ava2 s. c o m*/ * the file path to validate * @return the resolved file handle if the file path is valid and allowed to be accessed * * @throws WebScriptException * if access to the log file is prohibited */ protected File validateFilePath(final String filePath) { ParameterCheck.mandatoryString("filePath", filePath); final Path path = Paths.get(filePath); boolean pathAllowed = false; final List<Logger> allLoggers = this.getAllLoggers(); for (final Logger logger : allLoggers) { @SuppressWarnings("unchecked") final Enumeration<Appender> allAppenders = logger.getAllAppenders(); while (allAppenders.hasMoreElements() && !pathAllowed) { final Appender appender = allAppenders.nextElement(); if (appender instanceof FileAppender) { final String appenderFile = ((FileAppender) appender).getFile(); final File configuredFile = new File(appenderFile); final Path configuredFilePath = configuredFile.toPath().toAbsolutePath().getParent(); pathAllowed = pathAllowed || (path.startsWith(configuredFilePath) && path.getFileName().toString().startsWith(configuredFile.getName())); } } } if (!pathAllowed) { throw new WebScriptException(Status.STATUS_FORBIDDEN, "The log file path " + filePath + " could not be resolved to a valid log file - access to any other file system contents is forbidden via this web script"); } final File file = path.toFile(); if (!file.exists()) { throw new WebScriptException(Status.STATUS_NOT_FOUND, "The log file path " + filePath + " could not be resolved to an existing log file"); } return file; }
From source file:org.apache.taverna.databundle.TestDataBundles.java
protected List<String> ls(Path path) throws IOException { List<String> paths = new ArrayList<>(); try (DirectoryStream<Path> ds = Files.newDirectoryStream(path)) { for (Path p : ds) { paths.add(p.getFileName() + ""); }// w w w . j av a 2 s .c o m } Collections.sort(paths); return paths; }
From source file:com.puppycrawl.tools.checkstyle.internal.XdocsPagesTest.java
@Test public void testAllCheckSections() throws Exception { final ModuleFactory moduleFactory = TestUtils.getPackageObjectFactory(); for (Path path : XdocUtil.getXdocsConfigFilePaths(XdocUtil.getXdocsFilePaths())) { final String fileName = path.getFileName().toString(); if ("config_reporting.xml".equals(fileName)) { continue; }/*from ww w . j av a2 s.co m*/ final String input = new String(Files.readAllBytes(path), UTF_8); final Document document = XmlUtil.getRawXml(fileName, input, input); final NodeList sources = document.getElementsByTagName("section"); String lastSectionName = null; for (int position = 0; position < sources.getLength(); position++) { final Node section = sources.item(position); final String sectionName = section.getAttributes().getNamedItem("name").getNodeValue(); if ("Content".equals(sectionName) || "Overview".equals(sectionName)) { Assert.assertNull(fileName + " section '" + sectionName + "' should be first", lastSectionName); continue; } Assert.assertTrue(fileName + " section '" + sectionName + "' shouldn't end with 'Check'", !sectionName.endsWith("Check")); if (lastSectionName != null) { Assert.assertTrue( fileName + " section '" + sectionName + "' is out of order compared to '" + lastSectionName + "'", sectionName.toLowerCase(Locale.ENGLISH) .compareTo(lastSectionName.toLowerCase(Locale.ENGLISH)) >= 0); } validateCheckSection(moduleFactory, fileName, sectionName, section); lastSectionName = sectionName; } } }