List of usage examples for java.nio.file Path toFile
default File toFile()
From source file:com.thoughtworks.go.remote.work.ArtifactsPublisherTest.java
private File getFileUploaded(String s) throws IOException { return Files.walk(Paths.get(workingFolder.toURI())).filter(new Predicate<Path>() { @Override//from w w w . j a v a 2 s.c om public boolean test(Path file) { return file.toFile().getName().equals(s); } }).findFirst().get().toFile(); }
From source file:gov.gtas.job.scheduler.LoaderScheduler.java
/** * Loader Scheduler running on configured schedule *//*from w w w . j a va2 s . c o m*/ @Scheduled(fixedDelayString = "${loader.fixedDelay.in.milliseconds}", initialDelayString = "${loader.initialDelay.in.milliseconds}") public void jobScheduling() { logger.info("entering jobScheduling()"); boolean exitStatus = false; Path dInputDir = Paths.get(messageOriginDir).normalize(); File inputDirFile = dInputDir.toFile(); Path dOutputDir = Paths.get(messageProcessedDir).normalize(); File outputDirFile = dOutputDir.toFile(); if (!inputDirFile.exists() || !outputDirFile.exists()) { logger.error("directory does not exist."); Exception fileNotExist = new RuntimeException("directory does not exist."); ErrorDetailInfo errInfo = ErrorHandlerFactory.createErrorDetails(fileNotExist); errorPersistenceService.create(errInfo); exitStatus = true; } else if (!inputDirFile.isDirectory() || !outputDirFile.isDirectory()) { logger.error("Not a directory: '" + inputDirFile + "'"); Exception notADirectory = new RuntimeException("Not a directory."); ErrorDetailInfo errInfo = ErrorHandlerFactory.createErrorDetails(notADirectory); errorPersistenceService.create(errInfo); exitStatus = true; } if (exitStatus) { Thread.currentThread().interrupt(); } LoaderStatistics stats = new LoaderStatistics(); if (inputType.equalsIgnoreCase(InputType.TWO_DIRS.name())) { processInputAndOutputDirectories(dInputDir, dOutputDir, stats); } else { logger.warn("No inputType selection."); } writeAuditLog(stats); logger.info("entering rule running portion of jobScheduling()"); try { targetingService.preProcessing(); Set<Long> uniqueFlights = targetingService.runningRuleEngine(); } catch (Exception exception) { logger.error(exception.getCause().getMessage()); ErrorDetailInfo errInfo = ErrorHandlerFactory .createErrorDetails(RuleServiceConstants.RULE_ENGINE_RUNNER_ERROR_CODE, exception); errorPersistenceService.create(errInfo); } logger.info("exiting rule running portion of jobScheduling()"); logger.info("exiting jobScheduling()"); }
From source file:ch.ifocusit.livingdoc.plugin.publish.HtmlPostProcessor.java
/** * @param path : html file * @param attachmentCollector : map that will contains attachement * @return a clean html with attachement derived *///from www.j av a2 s .c o m public String process(Path path, Map<String, String> attachmentCollector) throws IOException { // read input String content = FileUtils.readFileToString(path.toFile(), Charset.defaultCharset()); if (isAdoc(path)) { // convert adoc to html content = asciidoctor.convert(content, options); } return postProcessContent(content, replaceCrossReferenceTargets(path), collectAndReplaceAttachmentFileNames(attachmentCollector), unescapeCdataHtmlContent()); }
From source file:fr.cnrs.sharp.test.GenProvenanceForFile.java
@Test public void hello() throws FileNotFoundException, IOException { StopWatch sw = new StopWatch(); sw.start();//www. ja v a 2s.c om Path p = Paths.get("/Users/gaignard-a/Desktop/access.log-20150818"); String label = p.getFileName().toString(); System.out.println(); FileInputStream fis = new FileInputStream(p.toFile()); String sha512 = DigestUtils.sha512Hex(fis); System.out.println(""); System.out.println(sha512); System.out.println("SHA512 calculated in " + sw.getTime() + " ms."); StringBuffer sb = new StringBuffer(); sb.append("@base <http://fr.symetric> .\n" + "@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .\n" + "@prefix foaf: <http://xmlns.com/foaf/0.1/> .\n" + "@prefix sioc: <http://rdfs.org/sioc/ns#> .\n" + "@prefix prov: <http://www.w3.org/ns/prov#> .\n" + "@prefix sym: <http://fr.symetric/vocab#> .\n" + "@prefix dcterms: <http://purl.org/dc/terms/> .\n" + "@prefix tavernaprov: <http://ns.taverna.org.uk/2012/tavernaprov/> .\n" + "@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .\n"); sb.append("<#" + UUID.randomUUID().toString() + ">\n" + "\t a prov:Entity ;\n"); sb.append("\t rdfs:label \"" + label + "\"^^xsd:String ;\n"); sb.append("\t tavernaprov:sha512 \"" + sha512 + "\"^^xsd:String ."); System.out.println(""); System.out.println(""); System.out.println(sb.toString()); fis.close(); }
From source file:cn.codepub.redis.directory.RedisLockFactory.java
@Override public Lock obtainLock(@NonNull Directory dir, String lockName) throws IOException { if (!(dir instanceof RedisDirectory)) { throw new IllegalArgumentException("Expect argument of type [" + RedisDirectory.class.getName() + "]!"); }//from ww w . j av a 2 s. co m Path lockFile = lockFileDirectory.resolve(lockName); try { Files.createFile(lockFile); log.debug("Lock file path = {}", lockFile.toFile().getAbsolutePath()); } catch (IOException ignore) { //ignore log.debug("Lock file already exists!"); } final Path realPath = lockFile.toRealPath(); final FileTime creationTime = Files.readAttributes(realPath, BasicFileAttributes.class).creationTime(); if (LOCK_HELD.add(realPath.toString())) { FileChannel fileChannel = null; FileLock lock = null; try { fileChannel = FileChannel.open(realPath, StandardOpenOption.CREATE, StandardOpenOption.WRITE); lock = fileChannel.tryLock(); if (lock != null) { return new RedisLock(lock, fileChannel, realPath, creationTime); } else { throw new LockObtainFailedException("Lock held by another program: " + realPath); } } finally { if (lock == null) { IOUtils.closeQuietly(fileChannel); clearLockHeld(realPath); } } } else { throw new LockObtainFailedException("Lock held by this virtual machine: " + realPath); } }
From source file:eu.itesla_project.sampling.tools.DataComparatorTool.java
private eu.itesla_project.computation.Command createConcatMatFilesCmd(Path dataPath, String pattern, Path outFile, SamplerWp41Config config) throws IOException { List<String> args1 = new ArrayList<>(); args1.add(dataPath.toFile().getAbsolutePath() + "/"); args1.add(pattern);//w w w . j a v a 2s . c o m args1.add(outFile.toFile().getAbsolutePath()); String wp41CatMatFiles; if (config.getBinariesDir() != null) { wp41CatMatFiles = config.getBinariesDir().resolve(WP41_CAT_MAT_FILES).toAbsolutePath().toString(); } else { wp41CatMatFiles = WP41_CAT_MAT_FILES; } return new SimpleCommandBuilder().id(WP41_CAT_MAT_FILES).program(wp41CatMatFiles).args(args1) // .inputFiles(m1InputFilesList) // .outputFiles(new OutputFile(outFile.toString())) .build(); }
From source file:net.sf.jabref.logic.xmp.XMPUtil.java
public static PDDocument loadWithAutomaticDecryption(Path filePath) throws IOException { return loadWithAutomaticDecryption(new FileInputStream(filePath.toFile())); }
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 a v a2 s .c o m*/ 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:deepschema.ExtractingTool.java
/** * Opens output file./* w ww . j a v a2 s.c o m*/ * * @param filename * @return FileOutputStream */ FileOutputStream openOutput(String filename) throws IOException { Path directoryPath = Paths.get("results"); try { Files.createDirectory(directoryPath); } catch (FileAlreadyExistsException e) { if (!Files.isDirectory(directoryPath)) { throw e; } } Path filePath = directoryPath.resolve(filename); return new FileOutputStream(filePath.toFile()); }
From source file:org.kawakicchi.bookshelf.infrastructure.storage.fs.FSContentStorage.java
public void store(final String key, final InputStream stream) { String[] s = key.split("/"); Path path = Paths.get(BASE_DIR.getAbsolutePath(), s); if (2 <= s.length) { File parent = path.getParent().toFile(); parent.mkdirs();/*from www .j ava2s. co m*/ } OutputStream out = null; try { out = new FileOutputStream(path.toFile()); byte[] buf = new byte[1024]; int size = -1; while (-1 != (size = stream.read(buf, 0, 1024))) { out.write(buf, 0, size); } } catch (IOException ex) { ex.printStackTrace(); } finally { if (null != out) { try { out.close(); } catch (IOException ex) { } } if (null != stream) { try { stream.close(); } catch (IOException ex) { } } } }