List of usage examples for java.nio.file Path getParent
Path getParent();
From source file:com.codenvy.api.audit.server.AuditManager.java
void deleteReportDirectory(Path auditReport) { try {/* w w w.ja va2 s . c o m*/ FileUtils.deleteDirectory(auditReport.getParent().toFile()); } catch (IOException exception) { LOG.error(exception.getMessage(), exception); } }
From source file:org.openhab.tools.analysis.checkstyle.KarafFeatureCheck.java
private Path resolveRecursively(Path absolute, Path relativePath) { while (absolute.getNameCount() > 0) { absolute = absolute.getParent(); Path resolved = absolute.resolve(relativePath); if (Files.exists(resolved)) { return resolved; }/*from w w w . j a v a2s .co m*/ } return null; }
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:org.discosync.CreateSyncPack.java
/** * Create a syncpack in syncPackDir, using the fileOperations and taking the files from baseDir. *///from w ww . j a v a 2 s. co m protected void createSyncPack(String baseDir, List<FileListEntry> fileOperations, String syncPackDir) throws SQLException, IOException { Path syncPackDirPath = Paths.get(syncPackDir); Files.createDirectories(syncPackDirPath); // store file operations to database File fileOpDbFile = new File(syncPackDirPath.toFile(), "fileoperations"); FileOperationDatabase db = new FileOperationDatabase(fileOpDbFile.getAbsolutePath()); db.open(); db.createFileOperationTable(); db.insertFileOperations(fileOperations); db.close(); // delete 'files' directory in syncpack and create the directory again Path targetBaseDir = Paths.get(syncPackDirPath.toAbsolutePath().toString(), "files"); Utils.deleteDirectoryRecursively(targetBaseDir); if (!Files.exists(targetBaseDir)) { Files.createDirectories(targetBaseDir); } String targetBaseDirStr = targetBaseDir.toAbsolutePath().toString(); // copy all files that need a COPY or REPLACE to the syncpack for (FileListEntry e : fileOperations) { if (e.getOperation() != FileOperations.COPY && e.getOperation() != FileOperations.REPLACE) { continue; } // don't copy directories that should be created on target if (e.isDirectory()) { continue; } String path = e.getPath(); Path sourcePath = FileSystems.getDefault().getPath(baseDir, path); Path targetPath = Paths.get(targetBaseDirStr, path); if (!Files.exists(targetPath.getParent())) { Files.createDirectories(targetPath.getParent()); } Files.copy(sourcePath, targetPath); } }
From source file:fr.duminy.jbackup.core.archive.Compressor.java
public void compress(ArchiveParameters archiveParameters, List<SourceWithPath> files, final TaskListener listener, Cancellable cancellable) throws ArchiveException { final String name = archiveParameters.getArchive().toString(); final MutableLong processedSize = new MutableLong(); try (OutputStream fos = Files.newOutputStream(archiveParameters.getArchive()); ArchiveOutputStream output = factory.create(fos)) { LOG.info("Backup '{}': creating archive {}", name, archiveParameters.getArchive()); for (final SourceWithPath file : files) { if ((cancellable != null) && cancellable.isCancelled()) { break; }//from ww w.java2 s. c om LOG.info("Backup '{}': compressing file {}", name, file.getPath().toAbsolutePath()); try (InputStream input = createCountingInputStream(listener, processedSize, Files.newInputStream(file.getPath()))) { final String path; if (archiveParameters.isRelativeEntries()) { Path source = file.getSource(); if (Files.isDirectory(source)) { if (source.getParent() == null) { path = source.relativize(file.getPath()).toString(); } else { path = source.getParent().relativize(file.getPath()).toString(); } } else { path = file.getPath().getFileName().toString(); } } else { path = file.getPath().toString(); } LOG.info("Backup '{}': adding entry {}", new Object[] { name, path }); output.addEntry(path, input); } } LOG.info("Backup '{}': archive {} created ({})", new Object[] { name, archiveParameters.getArchive(), FileUtils.byteCountToDisplaySize(Files.size(archiveParameters.getArchive())) }); } catch (IOException e) { throw new ArchiveException(e); } catch (Exception e) { throw new ArchiveException(e); } }
From source file:com.opensymphony.xwork2.util.fs.JarEntryRevisionTest.java
@Override protected void tearDown() throws Exception { Path tmpFile = Files.createTempFile("jar_cache", null); Path tmpFolder = tmpFile.getParent(); int count = FileUtils.listFiles(tmpFolder.toFile(), new WildcardFileFilter("jar_cache*"), null).size(); if (tmpFile.toFile().delete()) { count--;/*from w ww .j a v a2s .c o m*/ } assertEquals(0, count); super.tearDown(); }
From source file:com.github.horrorho.liquiddonkey.cloud.CSVWriter.java
public void files(Collection<ICloud.MBSFile> files, Path path) throws IOException { logger.trace("<< write() < files: {} path: {}", files.size(), path); Files.createDirectories(path.getParent()); try (CSVPrinter printer = new CSVPrinter(new FileWriter(path.toFile()), csvFormat)) { printer.printRecord(HEADER);/*from w w w. j av a 2 s. c om*/ for (ICloud.MBSFile file : files) { String mode = file.getAttributes().hasMode() ? "0x" + Integer.toString(file.getAttributes().getMode(), 16) : ""; String size = file.hasSize() ? Long.toString(file.getSize()) : ""; String lastModified = file.getAttributes().hasLastModified() ? Long.toString(file.getAttributes().getLastModified()) : ""; printer.print(mode); printer.print(size); printer.print(lastModified); printer.print(file.getDomain()); printer.print(file.getRelativePath()); printer.println(); } } logger.trace(">> write()"); }
From source file:com.hpe.caf.worker.testing.preparation.PreparationResultProcessor.java
@Override protected Path getSaveFilePath(TestItem<TInput, TExpected> testItem, TaskMessage message) { Path saveFilePath = super.getSaveFilePath(testItem, message); if (configuration.isStoreTestCaseWithInput()) { Path fileName = saveFilePath.getFileName(); Path path = Paths.get(testItem.getInputData().getInputFile()); saveFilePath = Paths.get(configuration.getTestDataFolder(), path.getParent() == null ? "" : path.getParent().toString(), fileName.toString()); }// w w w . j a v a 2 s . c o m return saveFilePath; }
From source file:org.rdswicthboard.utils.xml.split.Processor.java
public int process() throws Exception { // test if source is an regular file and it is readable Path source = Paths.get(inputFile); if (!Files.isRegularFile(source)) throw new Exception("The input file: " + source.toString() + " is not an regular file"); if (!Files.isReadable(source)) throw new Exception("The input file: " + source.toString() + " is not readable"); // extrat parent path Path targetPrefix = Paths.get(outputPrefix); Path parent = targetPrefix.getParent(); // try to create parent path if it exists if (null != parent) Files.createDirectories(parent); // create file template String template = targetPrefix.getFileName().toString() + "%d.xml"; // generate expression String expression = String.format( "<\\?\\s*xml(\\s+version=\"[\\d\\.]+\")?(\\s+encoding=\"[-\\w]+\")?(\\s+standalone=\"(yes|no)\")?\\s*\\?>\\s*<\\s*%s[^>]*>[\\s\\S]*?<\\s*\\/\\s*%s\\s*>", rootNode, rootNode);/* ww w .jav a 2 s . c om*/ // create pattern Pattern pattern = Pattern.compile(expression); // read file into a string String content = new String(Files.readAllBytes(source), inputEncoding); // create matcher and apply it to the content Matcher matcher = pattern.matcher(content); // init file number int fileNumber = 0; // process all records while (matcher.find()) { String fileName = String.format(template, fileNumber++); Path path = null == parent ? Paths.get(fileName) : Paths.get(parent.toString(), fileName); Files.write(path, matcher.group()/*.replaceAll("\\?><", "?>\n<")*/.getBytes(outputEncoding)); } return fileNumber; }
From source file:com.arpnetworking.metrics.mad.performance.ApplicationPipelinePT.java
public ApplicationPipelinePT(final String name, final int uowCount, final int namesCount, final int samplesCount) { final Path path = Paths.get("target/tmp/perf/application-generated-sample-" + name + ".log"); final Path parent = path.getParent(); if (parent != null) { try {/* www.j a v a 2 s . c o m*/ Files.createDirectories(parent); } catch (final IOException e) { throw Throwables.propagate(e); } } final DateTime start = DateTime.now().minusDays(1).hourOfDay().roundFloorCopy(); final DateTime stop = start.plusMinutes(10); final TestFileGenerator generator = new TestFileGenerator.Builder().setRandom(RANDOM) .setUnitOfWorkCount(uowCount).setNamesCount(namesCount).setSamplesCount(samplesCount) .setStartTime(start).setEndTime(stop).setFileName(path).setClusterName("test_cluster") .setServiceName("test_service").build(); generator.generate(); _file = path; _uowCount = uowCount; _namesCount = namesCount; _samplesCount = samplesCount; }