List of usage examples for java.nio.file Path getFileName
Path getFileName();
From source file:com.yahoo.parsec.gradle.utils.FileUtils.java
/** * Find files in path./*from ww w.ja v a 2 s .c om*/ * * @param path find path * @param pattern find patttern * @return a set of path * @throws IOException IOException */ public Set<Path> findFiles(String path, String pattern) throws IOException { try { Set<Path> paths = new HashSet<>(); PathMatcher pathMatcher = FileSystems.getDefault().getPathMatcher(pattern); Files.walkFileTree(Paths.get(path), new SimpleFileVisitor<Path>() { @Override public FileVisitResult visitFile(Path filePath, BasicFileAttributes attrs) { if (pathMatcher.matches(filePath.getFileName())) { paths.add(filePath); } return FileVisitResult.CONTINUE; } }); return paths; } catch (IOException e) { throw e; } }
From source file:com.liferay.sync.engine.util.FileUtilTest.java
@Test public void testMoveFile() throws Exception { Path sourceFilePath = Files.createTempFile("test", null); Assert.assertTrue(FileUtil.exists(sourceFilePath)); Path targetDirectoryFilePath = Files.createTempDirectory("test"); Path targetFilePath = targetDirectoryFilePath.resolve(sourceFilePath.getFileName()); FileUtil.moveFile(sourceFilePath, targetFilePath); Assert.assertTrue(FileUtil.notExists(sourceFilePath)); Assert.assertTrue(FileUtil.exists(targetFilePath)); }
From source file:com.sastix.cms.server.services.content.HashedDirectoryServiceTest.java
private int listRecursive(Path path) throws IOException { final int[] counter = { 0 }; Files.walkFileTree(path, new SimpleFileVisitor<Path>() { @Override/*from w ww . j av a2 s.c om*/ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { counter[0]++; LOGGER.trace("Listing: [" + counter[0] + "]\t" + file.getParent() + "/" + file.getFileName()); return FileVisitResult.CONTINUE; } @Override public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException { return FileVisitResult.CONTINUE; } }); return counter[0]; }
From source file:org.eclipse.swt.snippets.SnippetExplorer.java
/** * Load Snippet metadata from the Java source file found at the given path. * * @param sourceFile the source file to load * @return the gathered Snippet metadata or <code>null</code> if failed * @throws IOException on errors loading the source file * @throws ClassNotFoundException if loading the Snippets corresponding class * file failed *//*from w w w . ja va 2 s.co m*/ private static Snippet snippetFromSource(Path sourceFile) throws IOException, ClassNotFoundException { final Pattern snippetNamePattern = Pattern.compile("Snippet([0-9]+)", Pattern.CASE_INSENSITIVE); sourceFile = sourceFile.normalize(); final String filename = sourceFile.getFileName().toString(); final String snippetName = filename.substring(0, filename.lastIndexOf('.')); final Class<?> snippeClass = Class.forName(SnippetsConfig.SNIPPETS_PACKAGE + "." + snippetName, false, SnippetExplorer.class.getClassLoader()); int snippetNum = Integer.MIN_VALUE; final Matcher snippetNameMatcher = snippetNamePattern.matcher(snippetName); if (snippetNameMatcher.matches()) { try { snippetNum = Integer.parseInt(snippetNameMatcher.group(1), 10); } catch (NumberFormatException e) { } } // do not load snippets without number yet if (snippetNum < 0) { return null; } final String src = getSnippetSource(sourceFile); final String description = extractSnippetDescription(src); final String[] arguments = SnippetsConfig.getSnippetArguments(snippetNum); return new Snippet(snippetNum, snippetName, snippeClass, src, description, arguments); }
From source file:com.movilizer.mds.webservice.services.UploadFileService.java
protected CompletableFuture<UploadResponse> uploadDocument(Path documentFilePath, long systemId, String password, String documentPool, String documentKey, String language, String ackKey, Integer connectionTimeoutInMillis) { String suffix = getSuffixFromFilename(documentFilePath.getFileName()); if (logger.isDebugEnabled()) { logger.debug(String.format(Messages.PERFORMING_UPLOAD, systemId)); }//w ww. j av a2 s. com return upload(movilizerUpload.getForm(documentFilePath.toFile(), systemId, password, documentPool, documentKey, language, suffix, ackKey), connectionTimeoutInMillis); }
From source file:com.boundlessgeo.geoserver.api.controllers.WorkspaceController.java
@RequestMapping(value = "/{wsName}/export", method = RequestMethod.POST, produces = APPLICATION_ZIP_VALUE) @ResponseStatus(value = HttpStatus.OK)/* w w w . ja v a 2 s . co m*/ public void export(@PathVariable String wsName, HttpServletResponse response) throws Exception { Catalog cat = geoServer.getCatalog(); WorkspaceInfo ws = findWorkspace(wsName, cat); BundleExporter exporter = new BundleExporter(cat, new ExportOpts(ws)); exporter.run(); Path zip = exporter.zip(); response.setContentType(APPLICATION_ZIP_VALUE); response.setHeader("Content-Disposition", "attachment; filename=\"" + zip.getFileName() + "\""); FileUtils.copyFile(zip.toFile(), response.getOutputStream()); }
From source file:com.gwac.job.FileTransferServiceImpl.java
public void transFile() { System.out.println("123"); try {//from ww w.jav a2 s. com System.out.println("123"); watcher = FileSystems.getDefault().newWatchService(); Path dir = Paths.get("E:/TestData/gwacTest"); dir.register(watcher, ENTRY_CREATE, ENTRY_MODIFY); System.out.println("Watch Service registered for dir: " + dir.getFileName()); isSuccess = true; } catch (IOException ex) { isSuccess = false; ex.printStackTrace(); } if (isBeiJingServer || !isSuccess) { return; } if (running == true) { log.debug("start job fileTransferJob..."); running = false; } else { log.warn("job fileTransferJob is running, jump this scheduler."); return; } try { WatchKey key = watcher.poll(); if (key != null) { for (WatchEvent<?> event : key.pollEvents()) { WatchEvent.Kind<?> kind = event.kind(); WatchEvent<Path> ev = (WatchEvent<Path>) event; Path fileName = ev.context(); System.out.println(kind.name() + ": " + fileName); if (kind == ENTRY_MODIFY) { System.out.println("My source file has changed!!!"); } } } boolean valid = key.reset(); if (!valid) { return; } } catch (Exception ex) { } if (running == false) { running = true; log.debug("job fileTransferJob is done."); } }
From source file:ru.xxlabaza.popa.pack.PackingService.java
private void processJavaScript(Document document) { document.select("script[src$=.js]:not([src^=http])").forEach(script -> { Path path = build.resolve(createPath(script.attr("src"))); log.info("Processing script '{}'", path); // String content = commentRemoveService.removeComments(path); String content = FileSystemUtils.getContent(path); if (!path.getFileName().toString().endsWith(".min.js")) { content = compressService.compress(content, JAVASCRIPT); }/* w w w . j a v a 2s. c o m*/ script.removeAttr("src"); script.html(content); }); }
From source file:de.bbe_consulting.mavento.MagentoInfoMojo.java
@Override public void execute() throws MojoExecutionException, MojoFailureException { initMojo();//from w w w . j a va 2 s. c o m getLog().info("Scanning: " + magentoPath); getLog().info(""); if (mVersion != null) { getLog().info("Version: Magento " + mVersion.toString()); } // parse sql properties from local.xml final Path localXmlPath = Paths.get(magentoPath + "/app/etc/local.xml"); Document localXml = null; if (Files.exists(localXmlPath)) { localXml = MagentoXmlUtil.readXmlFile(localXmlPath.toAbsolutePath().toString()); } else { throw new MojoExecutionException( "Could not read or parse /app/etc/local.xml." + " Use -DmagentoPath= to set Magento dir."); } final Map<String, String> dbSettings = MagentoXmlUtil.getDbValues(localXml); final String jdbcUrl = MagentoSqlUtil.getJdbcUrl(dbSettings.get("host"), dbSettings.get("port"), dbSettings.get("dbname")); // fetch installdate final String magentoInstallDate = MagentoXmlUtil.getMagentoInstallData(localXml); getLog().info("Installed: " + magentoInstallDate); getLog().info(""); // read baseUrl MagentoCoreConfig baseUrl = null; try { baseUrl = new MagentoCoreConfig("web/unsecure/base_url"); } catch (Exception e) { throw new MojoExecutionException("Error creating config entry. " + e.getMessage(), e); } String sqlError = SQL_CONNECTION_VALID; try { baseUrl = MagentoSqlUtil.getCoreConfigData(baseUrl, dbSettings.get("user"), dbSettings.get("password"), jdbcUrl, getLog()); getLog().info("URL: " + baseUrl.getValue()); getLog().info(""); } catch (MojoExecutionException e) { sqlError = e.getMessage(); } getLog().info("Database: " + dbSettings.get("dbname") + " via " + dbSettings.get("user") + "@" + dbSettings.get("host") + ":" + dbSettings.get("port")); getLog().info("Connection: " + sqlError); getLog().info(""); if (!skipSize) { MutableLong rootSizeTotal = new MutableLong(); try { FileSizeVisitor fs = new FileSizeVisitor(rootSizeTotal); Files.walkFileTree(Paths.get(magentoPath), fs); } catch (IOException e) { throw new MojoExecutionException(e.getMessage(), e); } getLog().info( "Magento files total: " + String.format("%,8d", rootSizeTotal.toLong()).trim() + " bytes"); if (SQL_CONNECTION_VALID.equals(sqlError)) { try { final Map<String, Integer> dbDetails = MagentoSqlUtil.getDbSize(dbSettings.get("dbname"), dbSettings.get("user"), dbSettings.get("password"), jdbcUrl, getLog()); final List<MysqlTable> logTableDetails = MagentoSqlUtil.getLogTablesSize( dbSettings.get("dbname"), dbSettings.get("user"), dbSettings.get("password"), jdbcUrl, getLog()); getLog().info("Database total: " + String.format("%,8d", dbDetails.get("totalRows")).trim() + " entries / " + String.format("%,8d", dbDetails.get("totalSize")).trim() + "mb"); int logSizeTotal = 0; int logRowsTotal = 0; for (MysqlTable t : logTableDetails) { logSizeTotal += t.getTableSizeInMb(); logRowsTotal += t.getTableRows(); if (showDetails) { getLog().info(" " + t.getTableName() + ": " + t.getFormatedTableEntries() + " entries / " + t.getFormatedTableSizeInMb() + "mb"); } } getLog().info("Log tables total: " + String.format("%,8d", logRowsTotal).trim() + " entries / " + String.format("%,8d", logSizeTotal).trim() + "mb"); } catch (MojoExecutionException e) { getLog().info("Error: " + e.getMessage()); } } getLog().info(""); } // parse modules final Path modulesXmlPath = Paths.get(magentoPath + "/app/etc/modules"); if (!Files.exists(modulesXmlPath)) { throw new MojoExecutionException("Could not find /app/etc/modules directory."); } DirectoryStream<Path> files = null; final ArrayList<MagentoModule> localModules = new ArrayList<MagentoModule>(); final ArrayList<MagentoModule> communityModules = new ArrayList<MagentoModule>(); try { files = Files.newDirectoryStream(modulesXmlPath); for (Path path : files) { if (!path.getFileName().toString().startsWith("Mage")) { MagentoModule m = new MagentoModule(path); if (m.getCodePool().equals("local")) { localModules.add(m); } else { communityModules.add(m); } } } } catch (IOException e) { throw new MojoExecutionException("Could not read modules directory. " + e.getMessage(), e); } finally { try { files.close(); } catch (IOException e) { throw new MojoExecutionException("Error closing directory stream. " + e.getMessage(), e); } } // print module sorted module list final MagentoModuleComperator mmc = new MagentoModuleComperator(); Collections.sort(localModules, mmc); Collections.sort(communityModules, mmc); getLog().info("Installed modules in.."); getLog().info("..local: "); for (MagentoModule m : localModules) { getLog().info(m.getNamespace() + "_" + m.getName() + " version: " + m.getVersion() + " active: " + m.isActive()); } if (localModules.size() == 0) { getLog().info("--none--"); } getLog().info(""); getLog().info("..community: "); for (MagentoModule m : communityModules) { getLog().info(m.getNamespace() + "_" + m.getName() + " version: " + m.getVersion() + " active: " + m.isActive()); } if (communityModules.size() == 0) { getLog().info("--none--"); } getLog().info(""); // check local overlays for content getLog().info("Overlay status.."); int fileCount = -1; final File localMage = new File(magentoPath + "/app/code/local/Mage"); if (localMage.exists()) { fileCount = localMage.list().length; if (fileCount > 0) { getLog().info("local/Mage: " + localMage.list().length + " file(s)"); } } final File localVarien = new File(magentoPath + "/app/code/local/Varien"); if (localVarien.exists()) { fileCount = localVarien.list().length; if (fileCount > 0) { getLog().info("local/Varien: " + localVarien.list().length + " file(s)"); } } if (fileCount == -1) { getLog().info("..not in use."); } }
From source file:business.services.FileService.java
public List<String> getAccessLogFilenames() { try {/*from www .j a v a 2 s .c o m*/ List<String> logFiles = new ArrayList<String>(); for (Path p : Files.newDirectoryStream(fileSystem.getPath("./logs/"), "dntp-access*.log")) { logFiles.add(p.getFileName().toString()); } Collections.sort(logFiles, Collections.reverseOrder()); return logFiles; } catch (IOException e) { log.error(e); throw new FileDownloadError(); } }