List of usage examples for java.io File toPath
public Path toPath()
From source file:com.playonlinux.containers.DefaultContainersManager.java
@Override public void init() { final File containersDirectory = playOnLinuxContext.makeContainersPath(); containersDirectoryObservable = new DirectoryWatcherFiles(executorService, containersDirectory.toPath()); containersDirectoryObservable.setOnChange(this::update); }
From source file:ch.silviowangler.dox.web.admin.RepositoryControllerTest.java
@Test public void testGetDocument2() throws Exception { final File file = folder.newFile("hello.txt"); InputStream in = new ByteArrayInputStream("hello".getBytes()); Files.copy(in, file.toPath(), StandardCopyOption.REPLACE_EXISTING); when(response.getOutputStream()).thenReturn(outputStream); doThrow(new IOException()).when(outputStream).write(any(byte[].class), any(int.class), any(int.class)); when(doxExporter.export()).thenReturn(file); when(mimeTypes.getProperty("zip")).thenReturn("my content type"); controller.getDocument(this.response); verify(response).setStatus(SC_INTERNAL_SERVER_ERROR); }
From source file:dk.dma.msiproxy.common.repo.FileTypes.java
/** * Returns the content type of the file, or null if unknown * @param file the file to check/* w ww.j a v a2 s . c o m*/ * @return the content type of the file, or null if unknown */ public String getContentType(File file) { return getContentType(file.toPath()); }
From source file:org.bonitasoft.web.designer.i18n.LanguagePackBuilderTest.java
@Test public void should_replace_a_previous_build_with_new_one() throws Exception { File poFile = folder.newFile("file.po"); File jsonFile = new File(poFile.getPath().replace(".po", ".json")); write(poFile.toPath(), aSimplePoFile()); write(jsonFile.toPath(), "previous content".getBytes()); builder.build(poFile.toPath());// www. j a va2 s . c o m assertThat(read(jsonFile)).isEqualTo("{\"francais\":{\"A page\":\"Une page\"}}"); }
From source file:org.italiangrid.storm.webdav.fs.attrs.DefaultExtendedFileAttributesHelper.java
@Override public boolean fileSupportsExtendedAttributes(File f) throws IOException { Assert.notNull(f);//from w ww . j av a2s . c o m UserDefinedFileAttributeView faView = Files.getFileAttributeView(f.toPath(), UserDefinedFileAttributeView.class); return (faView != null); }
From source file:com.joyent.manta.client.crypto.SecretKeyUtilsTest.java
public void writeKeyToPath() throws IOException { File file = File.createTempFile("ciphertext-", ".data"); FileUtils.forceDeleteOnExit(file);// w ww. ja v a2 s . co m Path path = file.toPath(); SupportedCipherDetails cipherDetails = AesGcmCipherDetails.INSTANCE_128_BIT; byte[] keyBytes = SecretKeyUtils.generate(cipherDetails).getEncoded(); SecretKey key = SecretKeyUtils.loadKey(keyBytes, cipherDetails); SecretKeyUtils.writeKeyToPath(key, path); SecretKey actual = SecretKeyUtils.loadKeyFromPath(path, cipherDetails); Assert.assertEquals(actual.getAlgorithm(), key.getAlgorithm()); Assert.assertTrue(Arrays.equals(key.getEncoded(), actual.getEncoded())); }
From source file:io.webfolder.cdp.ChromiumDownloader.java
private static void unpack(File archive, File destionation) throws IOException { try (ZipFile zip = new ZipFile(archive)) { Map<File, String> symLinks = new LinkedHashMap<>(); Enumeration<ZipArchiveEntry> iterator = zip.getEntries(); // Top directory name we are going to ignore String parentDirectory = iterator.nextElement().getName(); // Iterate files & folders while (iterator.hasMoreElements()) { ZipArchiveEntry entry = iterator.nextElement(); String name = entry.getName().substring(parentDirectory.length()); File outputFile = new File(destionation, name); if (name.startsWith("interactive_ui_tests")) { continue; }//from w w w. j a va 2s . co m if (entry.isUnixSymlink()) { symLinks.put(outputFile, zip.getUnixSymlink(entry)); } else if (!entry.isDirectory()) { if (!outputFile.getParentFile().isDirectory()) { outputFile.getParentFile().mkdirs(); } try (FileOutputStream outStream = new FileOutputStream(outputFile)) { IOUtils.copy(zip.getInputStream(entry), outStream); } } // Set permission if (!entry.isUnixSymlink() && outputFile.exists()) try { Files.setPosixFilePermissions(outputFile.toPath(), modeToPosixPermissions(entry.getUnixMode())); } catch (Exception e) { // ignore } } for (Map.Entry<File, String> entry : symLinks.entrySet()) { try { Path source = Paths.get(entry.getKey().getAbsolutePath()); Path target = source.getParent().resolve(entry.getValue()); if (!source.toFile().exists()) Files.createSymbolicLink(source, target); } catch (Exception e) { // ignore } } } }
From source file:jease.cmf.service.Backup.java
/** * Dump contents of node (and all children) into a file. *//*from ww w . ja va 2 s. c o m*/ public File dump(Node node) { if (node == null) { return null; } try { Node nodeCopy = node.copy(true); nodeCopy.setParent(null); String filename = (StringUtils.isEmpty(nodeCopy.getId()) ? nodeCopy.getType() : nodeCopy.getId()) + ".xml"; File tmpDirectory = Files.createTempDirectory("jease-backup").toFile(); tmpDirectory.deleteOnExit(); File dumpFile = new File(tmpDirectory, filename); dumpFile.deleteOnExit(); Writer writer = Files.newBufferedWriter(dumpFile.toPath()); toXML(nodeCopy, writer); writer.close(); File zipFile = Zipfiles.zip(dumpFile); zipFile.deleteOnExit(); return zipFile; } catch (IOException e) { throw new RuntimeException(e.getMessage(), e); } }
From source file:com.reactivetechnologies.platform.rest.dll.JarModuleLoader.java
/** * * @param f */ public JarModuleLoader(File f) { root = f.toPath(); }
From source file:org.italiangrid.storm.webdav.fs.attrs.DefaultExtendedFileAttributesHelper.java
@Override public List<String> getExtendedFileAttributeNames(File f) throws IOException { Assert.notNull(f);//from ww w . j a v a 2 s . co m UserDefinedFileAttributeView faView = Files.getFileAttributeView(f.toPath(), UserDefinedFileAttributeView.class); if (faView == null) { throw new IOException("UserDefinedFileAttributeView not supported on file " + f.getAbsolutePath()); } return faView.list(); }