List of usage examples for java.io File toPath
public Path toPath()
From source file:com.github.ukase.service.PdfRendererTest.java
private byte[] getFile(String file) throws IOException { File dataFile = new File(settings.getResources(), file); if (!dataFile.exists()) { return null; }/* w ww . j a va 2 s . c o m*/ return Files.readAllBytes(dataFile.toPath()); }
From source file:com.evolveum.midpoint.model.impl.ExtensionSchemaRestService.java
private String computeName(String midpointHome, SchemaDescription description) { String path = description.getPath(); if (path == null) { return null; }/*from ww w.j ava 2s.c o m*/ File file = new File(path); if (!file.exists()) { return null; } File home = new File(midpointHome, "/schema"); java.nio.file.Path homePath = home.toPath(); java.nio.file.Path filePath = file.toPath(); java.nio.file.Path relative = homePath.relativize(filePath); return relative.toString(); }
From source file:com.ericsson.eiffel.remrem.generate.EiffelRemremControllerIntegrationTest.java
private String loadEventBody(final String fileName) throws IOException { URL url = getClass().getClassLoader().getResource(fileName); assert url != null; String path = url.getPath().replace("%20", " "); File file = new File(path); final byte[] bytes = Files.readAllBytes(file.toPath()); return new String(bytes); }
From source file:de.alexkamp.sandbox.model.SandboxData.java
public SandboxData copyTo(InputStream source, String target) throws IOException { File targetFile = new File(basePath, target); ensureExistance(targetFile);/*from w w w .ja v a2 s .c o m*/ Files.copy(source, targetFile.toPath()); return this; }
From source file:com.igormaznitsa.sciareto.ui.tree.NodeProject.java
public NodeProject(@Nonnull final NodeProjectGroup group, @Nonnull final File folder) { super(group, true, folder.getName(), !Files.isWritable(folder.toPath())); this.folder = folder; reloadSubtree();// w w w . j av a2 s . c o m }
From source file:com.stratio.mojo.scala.crossbuild.RewriteJUnitXMLTest.java
@Test public void rewrite() throws IOException { for (final String[] reportPair : reports) { final String origReport = reportPair[0]; final String resultReport = reportPair[1]; final RewriteJUnitXML rewriter = new RewriteJUnitXML(); tempDir.create();/*ww w. j ava 2 s . c om*/ final File file = tempDir.newFile(); file.delete(); Files.copy(getClass().getResourceAsStream(origReport), file.toPath()); final String newBinaryVersion = "2.11"; rewriter.rewrite(file, newBinaryVersion); assertEqualToResource(file, resultReport); file.delete(); } }
From source file:com.stratio.mojo.scala.crossbuild.RewriteJUnitXMLTest.java
@Test public void idempotency() throws IOException { for (final String[] reportPair : reports) { final String resultReport = reportPair[1]; final RewriteJUnitXML rewriter = new RewriteJUnitXML(); tempDir.create();/*w w w . j av a 2 s . co m*/ final File file = tempDir.newFile(); file.delete(); Files.copy(getClass().getResourceAsStream(resultReport), file.toPath()); final String newBinaryVersion = "2.11"; rewriter.rewrite(file, newBinaryVersion); assertEqualToResource(file, resultReport); file.delete(); } }
From source file:de.ks.file.FileStore.java
private long getFileSize(File file) { try {/*from ww w. ja va 2 s . com*/ return Files.size(file.toPath()); } catch (IOException e) { log.error("Could not get filesize from {}", file, e); return -1; } }
From source file:ezbake.security.common.core.FileWatcherTest.java
@Test public void testEvents() throws IOException, InterruptedException { final String contents = "TESTSTSETSTSTETSTSETST"; FileWatcher w = new FileWatcher(Paths.get(folder.getRoot() + "/testFile"), new FileWatcher.FileWatchUpdater() { @Override//from w w w .ja v a2 s .co m public boolean loadUpdate(InputStream is) { try { byte[] bytes = new byte[contents.length()]; is.read(bytes, 0, contents.length()); logger.debug("Read bytes {}", bytes); Assert.assertEquals(contents, new String(bytes)); } catch (IOException e) { e.printStackTrace(); } return false; } @Override public void close() throws IOException { } }); Thread watchThread = new Thread(w); watchThread.start(); Thread.sleep(50); File f2 = folder.newFile("otherFile"); try (PrintWriter writer = new PrintWriter(Files.newBufferedWriter(f2.toPath(), Charset.defaultCharset()))) { writer.println("HTESTS"); } try (PrintWriter writer = new PrintWriter(Files.newBufferedWriter(f2.toPath(), Charset.defaultCharset()))) { writer.println("HTElkajsldkfjSTS"); } File watchPath = folder.newFile("testFile"); try (PrintWriter writer = new PrintWriter( Files.newBufferedWriter(watchPath.toPath(), Charset.defaultCharset()))) { writer.println(contents); } watchThread.join(10 * 1000); }
From source file:com.google.cloud.tools.gradle.appengine.sourcecontext.SourceContextPluginIntegrationTest.java
/** Create a test project with git source context. */ public void setUpTestProject() throws IOException { Path buildFile = testProjectDir.getRoot().toPath().resolve("build.gradle"); Path src = Files.createDirectory(testProjectDir.getRoot().toPath().resolve("src")); InputStream buildFileContent = getClass().getClassLoader() .getResourceAsStream("projects/sourcecontext-project/build.gradle"); Files.copy(buildFileContent, buildFile); Path gitContext = testProjectDir.getRoot().toPath().resolve("gitContext.zip"); InputStream gitContextContent = getClass().getClassLoader() .getResourceAsStream("projects/sourcecontext-project/gitContext.zip"); Files.copy(gitContextContent, gitContext); try (ZipFile zipFile = new ZipFile(gitContext.toFile())) { Enumeration<? extends ZipEntry> entries = zipFile.entries(); while (entries.hasMoreElements()) { ZipEntry entry = entries.nextElement(); File entryDestination = new File(testProjectDir.getRoot(), entry.getName()); if (entry.isDirectory()) { entryDestination.mkdirs(); } else { entryDestination.getParentFile().mkdirs(); InputStream in = zipFile.getInputStream(entry); OutputStream out = new FileOutputStream(entryDestination); IOUtils.copy(in, out);/*from www . j av a2 s . c o m*/ IOUtils.closeQuietly(in); out.close(); } } } FileUtils.delete(gitContext.toFile()); Path webInf = testProjectDir.getRoot().toPath().resolve("src/main/webapp/WEB-INF"); Files.createDirectories(webInf); File appengineWebXml = Files.createFile(webInf.resolve("appengine-web.xml")).toFile(); Files.write(appengineWebXml.toPath(), "<appengine-web-app/>".getBytes(Charsets.UTF_8)); }