List of usage examples for java.nio.file Path toFile
default File toFile()
From source file:com.haulmont.yarg.formatters.impl.doc.connector.OfficeResourceProvider.java
protected File createTempFile(byte[] bytes) { try {//from www. j a va 2s.c o m String tempFileName = String.format("document%d", counter.incrementAndGet()); String tempFileExt = ".tmp"; if (StringUtils.isNotBlank(officeIntegration.getTemporaryDirPath())) { Path tempDir = Paths.get(officeIntegration.getTemporaryDirPath()); tempDir.toFile().mkdirs(); temporaryFile = Files.createTempFile(tempDir, tempFileName, tempFileExt).toFile(); } else { temporaryFile = File.createTempFile(tempFileName, tempFileExt); } FileUtils.writeByteArrayToFile(temporaryFile, bytes); return temporaryFile; } catch (java.io.IOException e) { throw new ReportFormattingException("Could not create temporary file for pdf conversion", e); } }
From source file:at.ac.tuwien.ims.latex2mobiformulaconv.tests.unit.FormulaConverterTest.java
@Before public void setUp() throws Exception { // Mock abstract class to implementing class for testing its non-abstract methods formulaConverter = Mockito.mock(FormulaConverter.class, Mockito.CALLS_REAL_METHODS); this.applicationContext = new ClassPathXmlApplicationContext("/application-context.xml"); Path latexHtmlPath = applicationContext.getResource("html+css/latex.html").getFile().toPath(); SAXBuilder sax = new SAXBuilder(); document = sax.build(latexHtmlPath.toFile()); }
From source file:io.syndesis.git.GitWorkflow.java
private void removeWorkingDir(Path workingDir) throws IOException { // cleanup tmp dir if (!FileSystemUtils.deleteRecursively(workingDir.toFile())) { LOG.warn("Could not delete temporary directory {}", workingDir); }/*w w w. j ava2 s .c o m*/ }
From source file:es.ucm.fdi.storage.business.entity.StorageObject.java
public void save(InputStream input) throws IOException { Path file = root.resolve(UUID.randomUUID().toString()); try (FileOutputStream out = new FileOutputStream(file.toFile())) { MessageDigest sha2sum = MessageDigest.getInstance("SHA-256"); byte[] dataBytes = new byte[4 * 1024]; int nread = 0; long length = 0; while ((nread = input.read(dataBytes)) != -1) { sha2sum.update(dataBytes, 0, nread); out.write(dataBytes, 0, nread); length += nread;/*from ww w . j ava2 s . c om*/ } this.internalName = toHexString(sha2sum.digest()); this.length = length; out.close(); String folder = internalName.substring(0, 2); Path parent = Files.createDirectories(root.resolve(folder)); Files.move(file, parent.resolve(internalName), StandardCopyOption.REPLACE_EXISTING); } catch (NoSuchAlgorithmException nsae) { throw new IOException("Cant save file", nsae); } }
From source file:grakn.core.daemon.executor.Executor.java
public boolean isProcessRunning(Path pidFile) { String processPid;//from www . j a v a2 s . co m if (pidFile.toFile().exists()) { try { processPid = new String(Files.readAllBytes(pidFile), StandardCharsets.UTF_8); if (processPid.trim().isEmpty()) { return false; } Result command = executeAndWait(checkPIDRunningCommand(processPid), null); if (command.exitCode() != 0) { System.out.println(command.stderr()); } return command.exitCode() == 0; } catch (NumberFormatException | IOException e) { return false; } } return false; }
From source file:com.arpnetworking.test.junitbenchmarks.JsonBenchmarkConsumerTest.java
@Test public void testMultipleClose() throws IOException { final Path path = Paths.get("target/tmp/test/testConsumerMultiClose.json"); path.toFile().deleteOnExit(); Files.deleteIfExists(path);/*w w w .j av a2 s.c om*/ final JsonBenchmarkConsumer consumer = new JsonBenchmarkConsumer(path); final Result result = DataCreator.createResult(); consumer.accept(result); consumer.close(); // Should not throw an exception consumer.close(); }
From source file:com.arpnetworking.test.junitbenchmarks.JsonBenchmarkConsumerTest.java
@Test(expected = IllegalStateException.class) public void testWriteAfterClose() throws IOException { final Path path = Paths.get("target/tmp/test/testConsumerMultiClose.json"); path.toFile().deleteOnExit(); Files.deleteIfExists(path);/*from w w w .jav a2s . co m*/ final JsonBenchmarkConsumer consumer = new JsonBenchmarkConsumer(path); final Result result = DataCreator.createResult(); consumer.accept(result); consumer.close(); // Should throw consumer.accept(result); }
From source file:com.marklogic.hub.RestAssetLoader.java
/** * FileVisitor method that loads the file into the modules database if the fileFilter accepts it. *//*from w ww. j av a 2s . c o m*/ @Override public FileVisitResult visitFile(Path path, BasicFileAttributes attributes) throws IOException { if (fileFilter.accept(path.toFile())) { Path relPath = currentAssetPath.relativize(path); String uri = "/" + relPath.toString().replace("\\", "/"); if (this.currentRootPath != null) { String name = this.currentRootPath.toFile().getName(); // A bit of a hack to support the special "root" directory. if (!"root".equals(name)) { uri = "/" + name + uri; } } uri = "/ext" + uri; loadFile(uri, path.toFile()); filesLoaded.add(path.toFile()); } return FileVisitResult.CONTINUE; }
From source file:net.minecrell.quartz.launch.mappings.MappingsLoader.java
public static Mappings load(Logger logger) throws IOException { URI source;/*www . j a v a 2 s . co m*/ try { source = requireNonNull(Mapping.class.getProtectionDomain().getCodeSource(), "Unable to find class source").getLocation().toURI(); } catch (URISyntaxException e) { throw new IOException("Failed to find class source", e); } Path location = Paths.get(source); logger.debug("Mappings location: {}", location); List<ClassNode> mappingClasses = new ArrayList<>(); // Load the classes from the source if (Files.isDirectory(location)) { // We're probably in development environment or something similar // Search for the class files Files.walkFileTree(location.resolve(PACKAGE), new SimpleFileVisitor<Path>() { @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { if (file.getFileName().toString().endsWith(".class")) { try (InputStream in = Files.newInputStream(file)) { ClassNode classNode = MappingsParser.loadClassStructure(in); mappingClasses.add(classNode); } } return FileVisitResult.CONTINUE; } }); } else { // Go through the JAR file try (ZipFile zip = new ZipFile(location.toFile())) { Enumeration<? extends ZipEntry> entries = zip.entries(); while (entries.hasMoreElements()) { ZipEntry entry = entries.nextElement(); String name = StringUtils.removeStart(entry.getName(), MAPPINGS_DIR); if (entry.isDirectory() || !name.endsWith(".class") || !name.startsWith(PACKAGE_PREFIX)) { continue; } // Ok, we found something try (InputStream in = zip.getInputStream(entry)) { ClassNode classNode = MappingsParser.loadClassStructure(in); mappingClasses.add(classNode); } } } } return new Mappings(mappingClasses); }
From source file:com.codealot.textstore.FileStore.java
@Override public Reader getTextReader(final String id) throws IOException { checkId(id);//from ww w . jav a 2 s.c o m final Path textPath = idToPath(id); return new FileReader(textPath.toFile()); }