List of usage examples for java.nio.file Path toAbsolutePath
Path toAbsolutePath();
From source file:org.jboss.as.test.integration.domain.SlaveHostControllerAuthenticationTestCase.java
private void createCredentialStore(String storeName, Path storageFile) throws IOException { ModelNode op = new ModelNode(); op.get(OP).set(ADD);//w ww. j a va 2s . com op.get(OP_ADDR).add(HOST, "slave").add(SUBSYSTEM, "elytron").add("credential-store", storeName); op.get("location").set(storageFile.toAbsolutePath().toString()); op.get("create").set(true); ModelNode credentialRefParams = new ModelNode(); credentialRefParams.get("clear-text").set("password123"); op.get("credential-reference").set(credentialRefParams); getDomainSlaveClient().execute(new OperationBuilder(op).build()); }
From source file:com.facebook.buck.util.unarchive.UnzipTest.java
@Test public void testExtractWeirdIndex() throws InterruptedException, IOException { try (ZipArchiveOutputStream zip = new ZipArchiveOutputStream(zipFile.toFile())) { zip.putArchiveEntry(new ZipArchiveEntry("foo/bar/baz")); zip.write(DUMMY_FILE_CONTENTS, 0, DUMMY_FILE_CONTENTS.length); zip.closeArchiveEntry();/*from ww w. j ava 2 s. c o m*/ zip.putArchiveEntry(new ZipArchiveEntry("foo/")); zip.closeArchiveEntry(); zip.putArchiveEntry(new ZipArchiveEntry("qux/")); zip.closeArchiveEntry(); } Path extractFolder = tmpFolder.newFolder(); ImmutableList<Path> result = ArchiveFormat.ZIP.getUnarchiver().extractArchive( new DefaultProjectFilesystemFactory(), zipFile.toAbsolutePath(), extractFolder.toAbsolutePath(), ExistingFileMode.OVERWRITE_AND_CLEAN_DIRECTORIES); assertTrue(Files.exists(extractFolder.toAbsolutePath().resolve("foo"))); assertTrue(Files.exists(extractFolder.toAbsolutePath().resolve("foo/bar/baz"))); assertEquals(ImmutableList.of(extractFolder.resolve("foo/bar/baz")), result); }
From source file:com.qwazr.library.archiver.ArchiverTool.java
public void decompress(final Path source, final Path destFile) throws IOException, CompressorException { if (Files.exists(destFile) && Files.size(destFile) > 0) throw new IOException("The file already exists: " + destFile.toAbsolutePath()); try (final InputStream input = getCompressorNewInputStream( new BufferedInputStream(Files.newInputStream(source)))) { IOUtils.copy(input, destFile);// w ww . j a va 2s . com } catch (IOException e) { throw new IOException("Unable to decompress the file: " + source.toAbsolutePath(), e); } }
From source file:org.sakuli.utils.SakuliPropertyPlaceholderConfigurerTest.java
@Test public void testAddPropertiesFromFile() throws Exception { Path sakuliPropFile = Paths.get(getClass().getResource("/JUnit-sakuli.properties").toURI()); assertTrue(Files.exists(sakuliPropFile)); Properties props = new Properties(); testling.addPropertiesFromFile(props, sakuliPropFile.toAbsolutePath().toString(), true); assertTrue(props.size() > 0);//from w ww . ja va2s . c o m assertEquals(props.getProperty(ActionProperties.TAKE_SCREENSHOTS), "true", "assert of property " + ActionProperties.TAKE_SCREENSHOTS); }
From source file:org.opencb.opencga.app.cli.CommandExecutor.java
/** * This method attempts to load general configuration from CLI 'conf' parameter, if not exists then loads JAR storage-configuration.yml. * * @throws IOException If any IO problem occurs *//*from ww w .ja v a 2 s.c o m*/ public void loadCatalogConfiguration() throws IOException { FileUtils.checkDirectory(Paths.get(this.conf)); // We load configuration file either from app home folder or from the JAR Path path = Paths.get(this.conf).resolve("catalog-configuration.yml"); if (path != null && Files.exists(path)) { logger.debug("Loading configuration from '{}'", path.toAbsolutePath()); this.catalogConfiguration = CatalogConfiguration.load(new FileInputStream(path.toFile())); } else { logger.debug("Loading configuration from JAR file"); this.catalogConfiguration = CatalogConfiguration.load( ClientConfiguration.class.getClassLoader().getResourceAsStream("catalog-configuration.yml")); } // logLevel parameter has preference in CLI over configuration file if (this.logLevel == null || this.logLevel.isEmpty()) { this.logLevel = this.catalogConfiguration.getLogLevel(); configureDefaultLog(this.logLevel); } else { if (!this.logLevel.equalsIgnoreCase(this.catalogConfiguration.getLogLevel())) { this.catalogConfiguration.setLogLevel(this.logLevel); configureDefaultLog(this.logLevel); } } // logFile parameter has preference in CLI over configuration file, we first set the logFile passed if (this.logFile != null && !this.logFile.isEmpty()) { this.catalogConfiguration.setLogFile(logFile); } // If user has set up a logFile we redirect logs to it if (this.catalogConfiguration.getLogFile() != null && !this.catalogConfiguration.getLogFile().isEmpty()) { org.apache.log4j.Logger rootLogger = LogManager.getRootLogger(); // If a log file is used then console log is removed rootLogger.removeAppender("stderr"); // Creating a RollingFileAppender to output the log RollingFileAppender rollingFileAppender = new RollingFileAppender( new PatternLayout("%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - " + "%m%n"), this.catalogConfiguration.getLogFile(), true); rollingFileAppender.setThreshold(Level.toLevel(catalogConfiguration.getLogLevel())); rootLogger.addAppender(rollingFileAppender); } // logger.debug("Loading configuration from '{}'", loadedConfigurationFile); }
From source file:com.facebook.buck.util.unarchive.UnzipTest.java
@Test public void testExtractZipFile() throws InterruptedException, IOException { try (ZipArchive zipArchive = new ZipArchive(this.zipFile, true)) { zipArchive.add("1.bin", DUMMY_FILE_CONTENTS); zipArchive.add("subdir/2.bin", DUMMY_FILE_CONTENTS); zipArchive.addDir("emptydir"); }/*from www .j ava 2 s. c om*/ Path extractFolder = tmpFolder.newFolder(); ImmutableList<Path> result = ArchiveFormat.ZIP.getUnarchiver().extractArchive( new DefaultProjectFilesystemFactory(), zipFile.toAbsolutePath(), extractFolder.toAbsolutePath(), ExistingFileMode.OVERWRITE); assertTrue(Files.exists(extractFolder.toAbsolutePath().resolve("1.bin"))); Path bin2 = extractFolder.toAbsolutePath().resolve("subdir/2.bin"); assertTrue(Files.exists(bin2)); assertTrue(Files.isDirectory(extractFolder.toAbsolutePath().resolve("emptydir"))); try (InputStream input = Files.newInputStream(bin2)) { byte[] buffer = new byte[DUMMY_FILE_CONTENTS.length]; int bytesRead = input.read(buffer, 0, DUMMY_FILE_CONTENTS.length); assertEquals(DUMMY_FILE_CONTENTS.length, bytesRead); for (int i = 0; i < DUMMY_FILE_CONTENTS.length; i++) { assertEquals(DUMMY_FILE_CONTENTS[i], buffer[i]); } } assertEquals(ImmutableList.of(extractFolder.resolve("1.bin"), extractFolder.resolve("subdir/2.bin")), result); }
From source file:io.github.robwin.diff.DiffAssert.java
/** * Verifies that the content of the actual File is equal to the given one. * * @param expected the given value to compare the actual value to. * @param reportPath the path to the report which should be generated if the files differ. * @return {@code this} assertion object. * @throws AssertionError if the actual value is not equal to the given one or if the actual value is {@code null}.. *//* w ww. j a v a 2 s. com*/ public DiffAssert isEqualTo(Path expected, Path reportPath) { LinkedList<DiffMatchPatch.Diff> diffs = diff(actual, expected); boolean allDiffsAreEqual = assertThatAllDiffsAreEqual(diffs); if (!allDiffsAreEqual) { writeHtmlReport(reportPath, diffs); } assertThat(allDiffsAreEqual).as( "The content of the following files differ. Actual: %s, Expected %s. Check the HTML report for more details: %s", actual.toAbsolutePath(), expected.toAbsolutePath(), reportPath.toAbsolutePath()).isTrue(); return myself; }
From source file:com.facebook.buck.util.unarchive.UnzipTest.java
@Test public void testExtractZipFilePreservesExecutePermissionsAndModificationTime() throws InterruptedException, IOException { // getFakeTime returs time with some non-zero millis. By doing division and multiplication by // 1000 we get rid of that. long time = ZipConstants.getFakeTime() / 1000 * 1000; // Create a simple zip archive using apache's commons-compress to store executable info. try (ZipArchiveOutputStream zip = new ZipArchiveOutputStream(zipFile.toFile())) { ZipArchiveEntry entry = new ZipArchiveEntry("test.exe"); entry.setUnixMode((int) MorePosixFilePermissions.toMode(PosixFilePermissions.fromString("r-x------"))); entry.setSize(DUMMY_FILE_CONTENTS.length); entry.setMethod(ZipEntry.STORED); entry.setTime(time);/*from w w w . j a v a 2s . c o m*/ zip.putArchiveEntry(entry); zip.write(DUMMY_FILE_CONTENTS); zip.closeArchiveEntry(); } // Now run `Unzip.extractZipFile` on our test zip and verify that the file is executable. Path extractFolder = tmpFolder.newFolder(); ImmutableList<Path> result = ArchiveFormat.ZIP.getUnarchiver().extractArchive( new DefaultProjectFilesystemFactory(), zipFile.toAbsolutePath(), extractFolder.toAbsolutePath(), ExistingFileMode.OVERWRITE); Path exe = extractFolder.toAbsolutePath().resolve("test.exe"); assertTrue(Files.exists(exe)); assertThat(Files.getLastModifiedTime(exe).toMillis(), Matchers.equalTo(time)); assertTrue(Files.isExecutable(exe)); assertEquals(ImmutableList.of(extractFolder.resolve("test.exe")), result); }
From source file:fr.duminy.jbackup.core.archive.FileCollector.java
private long collect(final List<SourceWithPath> collectedFiles, final Path source, final IOFileFilter directoryFilter, final IOFileFilter fileFilter, final Cancellable cancellable) throws IOException { final long[] totalSize = { 0L }; SimpleFileVisitor<Path> visitor = new SimpleFileVisitor<Path>() { @Override// www. ja va 2s. co m public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException { super.preVisitDirectory(dir, attrs); if ((directoryFilter == null) || source.equals(dir) || directoryFilter.accept(dir.toFile())) { return CONTINUE; } else { return SKIP_SUBTREE; } } @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { if ((cancellable != null) && cancellable.isCancelled()) { return TERMINATE; } super.visitFile(file, attrs); if (!Files.isSymbolicLink(file)) { if ((fileFilter == null) || fileFilter.accept(file.toFile())) { LOG.trace("visitFile {}", file.toAbsolutePath()); collectedFiles.add(new SourceWithPath(source, file)); totalSize[0] += Files.size(file); } } return CONTINUE; } }; Files.walkFileTree(source, visitor); return totalSize[0]; }
From source file:org.apache.lucene.benchmark.byTask.tasks.WriteLineDocTaskTest.java
private PerfRunData createPerfRunData(Path file, boolean allowEmptyDocs, String docMakerName) throws Exception { Properties props = new Properties(); props.setProperty("doc.maker", docMakerName); props.setProperty("line.file.out", file.toAbsolutePath().toString()); props.setProperty("directory", "RAMDirectory"); // no accidental FS dir. if (allowEmptyDocs) { props.setProperty("sufficient.fields", ","); }//w ww . ja v a 2 s . c om if (docMakerName.equals(LegalJustDateDocMaker.class.getName())) { props.setProperty("line.fields", DocMaker.DATE_FIELD); props.setProperty("sufficient.fields", DocMaker.DATE_FIELD); } Config config = new Config(props); return new PerfRunData(config); }