List of usage examples for java.nio.file Path toString
String toString();
From source file:com.yqboots.fss.util.ZipUtils.java
/** * Compresses the specified directory to a zip file * * @param dir the directory to compress// w w w. j ava 2s . c o m * @return the compressed file * @throws IOException */ public static Path compress(Path dir) throws IOException { Assert.isTrue(Files.exists(dir), "The directory does not exist: " + dir.toAbsolutePath()); Assert.isTrue(Files.isDirectory(dir), "Should be a directory: " + dir.toAbsolutePath()); Path result = Paths.get(dir.toAbsolutePath() + FileType.DOT_ZIP); try (final ZipOutputStream out = new ZipOutputStream( new BufferedOutputStream(new FileOutputStream(result.toFile())))) { // out.setMethod(ZipOutputStream.DEFLATED); final byte data[] = new byte[BUFFER]; // get a list of files from current directory Files.walkFileTree(dir, new SimpleFileVisitor<Path>() { @Override public FileVisitResult visitFile(final Path path, final BasicFileAttributes attrs) throws IOException { final File file = path.toFile(); // compress to relative directory, not absolute final String root = StringUtils.substringAfter(file.getParent(), dir.toString()); try (final BufferedInputStream origin = new BufferedInputStream(new FileInputStream(file), BUFFER)) { final ZipEntry entry = new ZipEntry(root + File.separator + path.getFileName()); out.putNextEntry(entry); int count; while ((count = origin.read(data, 0, BUFFER)) != -1) { out.write(data, 0, count); } } return FileVisitResult.CONTINUE; } }); } return result; }
From source file:org.eclipse.vorto.remoterepository.dao.ModelDAOTest.java
@Before public void init() { Path modelPath = Paths.get("src/test/resources/modelexamples"); dao.setRepositoryBaseDirectory(modelPath.toString()); }
From source file:com.yahoo.rdl.maven.RdlFileFinderImpl.java
@Override public List<Path> findRdlFiles() throws MojoExecutionException, MojoFailureException { List<Path> rdlFiles = new ArrayList<Path>(); try {//from w ww.ja v a 2 s . c o m Files.walkFileTree(rdlDirectory, new SimpleFileVisitor<Path>() { @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { if (FilenameUtils.isExtension(file.toString(), "rdl")) { rdlFiles.add(file); } return super.visitFile(file, attrs); } }); } catch (IOException e) { throw new MojoExecutionException("Error walking " + rdlDirectory.toAbsolutePath(), e); } if (rdlFiles.isEmpty()) { throw new MojoFailureException("No files ending in .rdl were found in the directory " + rdlDirectory.toAbsolutePath() + ". Assign <rdlDirectory> in the configuration of rdl-maven-plugin to a folder containing your rdl files."); } return rdlFiles; }
From source file:de.kaixo.mubi.lists.store.MubiListsToElasticSearchLoader.java
public void loadFromJson(Path path) { logger.info("Processing " + path.toString()); try {/*from w w w. j a v a 2 s.c o m*/ JsonNode node = mapper.readTree(path.toFile()); if (node.isArray()) { node.elements().forEachRemaining(elem -> { StringWriter writer = new StringWriter(); try { JsonGenerator generator = factory.createGenerator(writer); mapper.writeTree(generator, elem); client.prepareIndex(INDEX_NAME, TYPE).setSource(writer.toString()).get(); } catch (IOException e) { logger.error("Failed to write item", e); } }); } } catch (IOException e) { logger.error("Failed to process " + path.toString(), e); } }
From source file:org.elasticsearch.xpack.security.authc.esnative.tool.SetupPasswordToolIT.java
@SuppressForbidden(reason = "need to set sys props for CLI tool") private void setSystemPropsForTool(Path configPath) { System.setProperty("es.path.conf", configPath.toString()); System.setProperty("es.path.home", configPath.getParent().toString()); }
From source file:com.notes.listen.FsWatchService.java
@Subscribe @AllowConcurrentEvents// w w w . ja va 2 s . com public void proc(PathEvent event) { try { Path path = event.getEventTarget(); String fileName = FilenameUtils.concat("D:\\temp\\", path.toString()); if (fileName.endsWith(".aspx")) { String fullPath = FilenameUtils.getFullPath(fileName); String srcName = FilenameUtils.getBaseName(fileName); } } catch (Error e) { e.printStackTrace(); } }
From source file:company.gonapps.loghut.utils.FileUtils.java
public List<String> scan(String pathString) throws IOException { paths = new LinkedList<>(); Files.walkFileTree(Paths.get(pathString), this); List<String> pathStrings = new LinkedList<>(); for (Path path : paths) { pathStrings.add(path.toString()); }// w ww. j a va 2 s .com return pathStrings; }
From source file:com.netflix.spinnaker.halyard.deploy.spinnaker.v1.profile.Profile.java
public void writeStagedFile(String stagingPath) { AtomicFileWriter writer = null;/* w w w.j a va 2 s . c o m*/ Path path = Paths.get(stagingPath, name); log.info("Writing profile to " + path.toString() + " with " + requiredFiles.size() + " required files"); try { writer = new AtomicFileWriter(path); writer.write(contents); writer.commit(); } catch (IOException ioe) { ioe.printStackTrace(); throw new HalException(Problem.Severity.FATAL, "Failed to write config for profile " + path.toFile().getName() + ": " + ioe.getMessage()); } finally { if (writer != null) { writer.close(); } } }
From source file:alliance.docs.DocumentationTest.java
private Path getPath() throws URISyntaxException { Path testPath = Paths.get(this.getClass().getResource(EMPTY_STRING).toURI()); Path targetDirectory = testPath.getParent().getParent().getParent(); return Paths.get(targetDirectory.toString()).resolve(DOCS_DIRECTORY).resolve(HTML_DIRECTORY); }
From source file:com.cisco.cta.taxii.adapter.ConfigTaskTest.java
@Test public void createsConfigDir() throws Exception { Path configDir = Paths.get("target/config"); FileUtils.deleteDirectory(configDir.toFile()); ConfigTask cfTask = new ConfigTask(configDir.toString()); cfTask.run();/*from ww w .j a v a 2 s .co m*/ assertTrue(Files.exists(configDir)); assertTrue(Files.exists(Paths.get(configDir.toString(), "application.yml"))); assertTrue(Files.exists(Paths.get(configDir.toString(), "logback.xml"))); assertTrue(Files.exists(Paths.get(configDir.toString(), "stix2cef.xsl"))); assertTrue(Files.exists(Paths.get(configDir.toString(), "stix2splunk.xsl"))); assertTrue(Files.exists(Paths.get(configDir.toString(), "stix2stix.xsl"))); assertTrue(Files.exists(Paths.get(configDir.toString(), "taxii-response.xsl"))); }