List of usage examples for java.nio.file Path toFile
default File toFile()
From source file:ru.xxlabaza.popa.pack.PackingService.java
@SneakyThrows public String pack(Path path) { log.info("Packing '{}'", path); val document = Jsoup.parse(path.toFile(), "UTF-8").outputSettings(outputSettings); processCss(document);//from ww w. j a v a2 s . co m processJavaScript(document); return processHtml(document); }
From source file:eu.over9000.skadi.io.PersistenceHandler.java
private void writeToFile(final StateContainer state) throws IOException, JAXBException { final Path stateFile = this.getStateFilePath(); synchronized (this.fileLock) { this.marshaller.marshal(state, stateFile.toFile()); }/*from w ww . j a va 2 s . c o m*/ LOGGER.debug("wrote state to file"); }
From source file:com.spectralogic.ds3cli.command.Recover.java
@Override public DefaultResult call() throws Exception { try {//from ww w. j a v a 2 s . com if (listOnly) { return new DefaultResult( RecoveryFileManager.printSearchFiles(this.id, this.bucketName, this.jobType)); } if (deleteFiles) { return new DefaultResult(RecoveryFileManager.deleteFiles(this.id, this.bucketName, this.jobType)); } // get exactly file to recover final Iterable<Path> files = RecoveryFileManager.searchFiles(this.id, this.bucketName, this.jobType); if (Iterables.isEmpty(files)) { return new DefaultResult("No matching recovery files found."); } if (Iterables.size(files) > 1) { return new DefaultResult("Multiple matching recovery files found:\n" + RecoveryFileManager.printSearchFiles(this.id, this.bucketName, this.jobType) + "Please restrict search criteria."); } final Path file = files.iterator().next(); final RecoveryJob job = RecoveryFileManager.getRecoveryJobByFile(file.toFile()); return new DefaultResult(recover(job)); } catch (final IOException e) { throw new CommandException("Recovery Job failed", 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--;/*w w w . jav a 2s . com*/ } assertEquals(0, count); super.tearDown(); }
From source file:grakn.core.daemon.executor.Executor.java
public String retrievePid(Path pidFile) { if (!pidFile.toFile().exists()) { return null; }//from w w w . j a v a 2 s.c om try { String pid = new String(Files.readAllBytes(pidFile), StandardCharsets.UTF_8); return pid.trim(); } catch (NumberFormatException | IOException e) { return null; } }
From source file:at.tfr.securefs.client.SecurefsFileServiceClient.java
public void run() { DateTime start = new DateTime(); try {/*from w w w . j av a 2s .c om*/ FileService svc = new FileService(new URL(fileServiceUrl)); BindingProvider binding = (BindingProvider) svc.getFileServicePort(); binding.getRequestContext().put(BindingProvider.USERNAME_PROPERTY, username); binding.getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, password); for (Path path : files) { if (write) { if (!path.toFile().exists()) { System.err.println(Thread.currentThread() + ": NoSuchFile: " + path + " currentWorkdir=" + Paths.get("./").toAbsolutePath()); continue; } System.out.println(Thread.currentThread() + ": Sending file: " + start + " : " + path); svc.getFileServicePort().write(path.toString(), IOUtils.toByteArray(Files.newInputStream(path))); } Path out = path.resolveSibling( path.getFileName() + (asyncTest ? "." + Thread.currentThread().getId() : "") + ".out"); if (read) { System.out.println(Thread.currentThread() + ": Reading file: " + new DateTime() + " : " + out); if (out.getParent() != null) { Files.createDirectories(out.getParent()); } byte[] arr = svc.getFileServicePort().read(path.toString()); IOUtils.write(arr, Files.newOutputStream(out)); } if (write && read) { long inputChk = FileUtils.checksumCRC32(path.toFile()); long outputChk = FileUtils.checksumCRC32(out.toFile()); if (inputChk != outputChk) { throw new IOException(Thread.currentThread() + ": Checksum Failed: failure to write/read: in=" + path + ", out=" + out); } System.out.println(Thread.currentThread() + ": Checked Checksums: " + new DateTime() + " : " + inputChk + " / " + outputChk); } if (delete) { boolean deleted = svc.getFileServicePort().delete(path.toString()); if (!deleted) { throw new IOException( Thread.currentThread() + ": Delete Failed: failure to delete: in=" + path); } else { System.out.println(Thread.currentThread() + ": Deleted File: in=" + path); } } } } catch (Throwable t) { t.printStackTrace(); throw new RuntimeException(t); } }
From source file:com.github.rwhogg.git_vcr.review.php.PhpmdReviewTool.java
@Override public List<String> getResults(File file) throws ReviewFailedException { // delete the cache first Path pathToCache = FileSystems.getDefault().getPath(System.getProperty("user.home"), ".pdepend"); try {//from w w w. j a va2 s . c om FileUtils.deleteQuietly(pathToCache.toFile()); } catch (Exception e) { } List<Object> rules = configuration.getList("rules"); String commandTemplate = "\"%s\" text \"%s\""; List<String> results; try { StringBuffer ruleStringBuffer = new StringBuffer(); for (Object rule : rules) { ruleStringBuffer.append((String) rule + ","); } String ruleString = ruleStringBuffer.toString(); results = runProcess(String.format(commandTemplate, file.getAbsolutePath(), ruleString.substring(0, ruleString.length() - 1))); } catch (IOException e) { throw new ReviewFailedException(e.getLocalizedMessage(), this, file.getAbsolutePath()); } // first result is always an empty line if ((results != null) && (results.size() > 0)) { List<String> copy = new LinkedList<>(); copy.addAll(results); copy.remove(0); results = copy; } return results; }
From source file:ee.ria.xroad.signer.certmanager.FileBasedOcspCache.java
void reloadFromDisk() throws Exception { Path path = Paths.get(getOcspCachePath()); try (DirectoryStream<Path> stream = Files.newDirectoryStream(path, this::isOcspFile)) { for (Path entry : stream) { loadResponseFromFileIfNotExpired(entry.toFile(), new Date()); }/*from www. ja v a2 s . c om*/ } }
From source file:misc.FileHandler.java
/** * Returns a <code>MESSAGE_DIGEST</code> checksum of the given file. * /*from ww w . j a v a 2 s. c o m*/ * @param file * the file to checksum. * @return the checksum of the given file or <code>null</code>, if an error * occurs. */ public static byte[] getChecksum(Path file) { if ((file == null) || !Files.isReadable(file)) { throw new IllegalArgumentException("file must exist and be readable!"); } byte[] checksum = null; try (FileInputStream in = new FileInputStream(file.toFile());) { checksum = getChecksum(in, Files.size(file)); } catch (IOException | NoSuchAlgorithmException e) { Logger.logError(e); } return checksum; }
From source file:at.ac.tuwien.qse.sepm.service.impl.WorkspaceServiceImpl.java
/** * Checks if <tt>path</tt> represents an existing directory. * * @param path Path to be checked// w ww . j a v a 2 s . co m * @return true iff <tt>path</tt> represents an existing directory */ private boolean isValid(Path path) { if (path == null) { return false; } File pathFile = path.toFile(); if (!pathFile.exists() || !pathFile.isDirectory()) { return false; } return true; }