List of usage examples for java.io File toPath
public Path toPath()
From source file:com.stratio.mojo.scala.crossbuild.RewritePomTest.java
@Test public void rewriteBaseArtifactId() throws IOException, XMLStreamException { final RewritePom rewritePom = new RewritePom(); tempDir.create();/* w w w . j a v a 2s . c o m*/ final File file = tempDir.newFile(); file.delete(); Files.copy(getClass().getResourceAsStream("/basic_pom.xml"), file.toPath()); final MavenProject project = getMockMavenProject(file); final String newBinaryVersion = "2.11"; final String newVersion = "2.11.7"; rewritePom.rewrite(project, "scala.binary.version", "scala.version", newBinaryVersion, newVersion); assertEqualToResource(file, "/basic_pom_result.xml"); file.delete(); }
From source file:ca.viaware.dlna.streamserver.StreamServer.java
private void streamMedia(HttpExchange exchange) throws IOException { final int entryId = Integer.parseInt(StringUtils.cleanNumber(exchange.getRequestURI().getPath())); Log.info("STREAM-SERVER: Got request for library item %0", entryId); HttpUtils.emptyStream(exchange.getRequestBody()); LibraryEntry entry = (LibraryEntry) Library.runInstance(new LibraryInstanceRunner() { @Override/*from w ww . j a v a2s.co m*/ public Object run(LibraryFactory factory) { return factory.get(entryId); } }); if (entry != null) { File file = entry.getLocation(); String mime = Files.probeContentType(file.toPath().toAbsolutePath()); Log.info("STREAM-SERVER: Entry is %0 %1", file.getAbsolutePath(), mime); Headers headers = exchange.getResponseHeaders(); headers.set("CONTENT-TYPE", mime); headers.set("USER-AGENT", Globals.SERVER); headers.set("CONTENT-LANGUAGE", "en"); if (exchange.getRequestMethod().equals("GET")) { Log.info("Starting stream upload."); exchange.sendResponseHeaders(200, 0); InputStream fileIn = new FileInputStream(file); OutputStream output = exchange.getResponseBody(); byte[] buffer = new byte[1024]; int read; while ((read = fileIn.read(buffer)) != -1) { output.write(buffer, 0, read); } output.close(); } else { exchange.sendResponseHeaders(200, -1); exchange.getResponseBody().close(); Log.info("Not streaming to HEAD request."); } Log.info("STREAM-SERVER: Finished stream transaction."); } else { String html = ""; html += "<!DOCTYPE html><html>"; html += "<head><title>ViaWare UPnP - Stream Server</title></head>"; html += "<body>"; html += "<h1>ViaWare UPnP Server v" + ViaWareDLNA.VERSION + " - Stream Server</h1><hr>"; html += "Unable to find the specified stream<br>"; html += "Copyright 2015 Seth Traverse"; html += "</body></html>"; byte[] bytes = html.getBytes("UTF-8"); Headers headers = exchange.getResponseHeaders(); headers.set("CONTENT-TYPE", "text/html"); headers.set("CONTENT-LANGUAGE", "en"); exchange.sendResponseHeaders(404, bytes.length); exchange.getResponseBody().write(bytes); exchange.getResponseBody().close(); } }
From source file:act.installer.reachablesexplorer.WordCloudGenerator.java
public File generateWordCloud(String inchi) { // TODO: improve wordcloud generation. Currently, each instance open a mongo connection on the R side. // By doing data manipulation in Java and utilizing Rengine, we could make this much better // Wordclouds could be generated ahead of time this way, using the inchi coprus File wordcloud = getWordcloudFile(inchi); if (!Files.exists(wordcloud.toPath()) && inchisSet.contains(inchi)) { try {//from w w w . j av a2s .co m ProcessRunner.runProcess(rScriptExePath, // TODO: remove hardcoded database from R script Arrays.asList(rScript.getAbsolutePath(), inchi, wordcloud.getAbsolutePath(), host, port.toString(), database), CHILD_PROCESS_TIMEOUT_IN_SECONDS); FileChecker.verifyInputFile(wordcloud); } catch (IOException e) { LOGGER.error("Unable to generate wordcloud for %s at location %s", inchi, wordcloud.toPath().toString()); return null; } catch (InterruptedException e) { LOGGER.error("Child process was interrupted: %s", e.getMessage()); return null; } } return wordcloud; }
From source file:com.android.tradefed.util.ZipUtil2Test.java
/** * Utility method to assert that provided file has expected permission per standard Unix * notation, e.g. file should have permission "rwxrwxrwx" * @param file/* w w w . ja va 2 s . c o m*/ */ private void verifyFilePermission(File file, String permString) throws IOException { Set<PosixFilePermission> actual = Files.getPosixFilePermissions(file.toPath()); Set<PosixFilePermission> expected = PosixFilePermissions.fromString(permString); Assert.assertEquals(expected, actual); }
From source file:com.fizzed.blaze.ssh.SshBaseTest.java
@Before public void setup() throws Exception { File sshdTestTxtFile = FileHelper.resourceAsFile("/sshd/ssh-test.txt"); File sshdTestDir = sshdTestTxtFile.getParentFile(); config = ConfigHelper.create(null);/*w w w . j a v a 2 s . c o m*/ context = spy(new ContextImpl(null, sshdTestDir.toPath(), null, config)); prompter = new ExpectPrompter(); context.prompter(prompter); ContextHolder.set(context); sshd = SshServer.setUpDefaultServer(); sshd.setHost("localhost"); sshd.setPort(0); // auto sshd.setKeyPairProvider(new SimpleGeneratorHostKeyProvider()); sshd.setPasswordAuthenticator((String username, String password, ServerSession ss) -> { log.info("Authenticate {} with {}", username, password); return "blaze".equals(username) && "test".equals(password); }); sshd.setCommandFactory((String line) -> { return new SshCommand(commandHandler, line); }); }
From source file:com.stratio.mojo.scala.crossbuild.RewritePomTest.java
/** * Regression test for https://github.com/Stratio/scala-cross-build-maven-plugin/issues/23 * @throws IOException//from ww w .j a va 2s. co m * @throws XMLStreamException */ @Test public void rewriteWithoutStackOverflow_Issue32() throws IOException, XMLStreamException { final RewritePom rewritePom = new RewritePom(); tempDir.create(); final File file = tempDir.newFile(); file.delete(); Files.copy(getClass().getResourceAsStream("/issue_23_pom.xml"), file.toPath()); final MavenProject project = getMockMavenProject(file); final String newBinaryVersion = "2.10"; final String newVersion = "2.10.4"; rewritePom.rewrite(project, "scala.binary.version", "scala.version", newBinaryVersion, newVersion); assertEqualToResource(file, "/issue_23_pom_result.xml"); file.delete(); }
From source file:controller.FileWatcher.java
@Override public void onDirectoryCreate(File arg0) { // TODO Auto-generated method stub if (!Files.isSymbolicLink(arg0.toPath())) { String directoryName = ServerUtil.convertPath(arg0.getAbsolutePath(), MyDropboxSwing.urls); String log = "Directory is created " + arg0.getName() + "\n"; System.out.println(log);// w ww . j av a2s . co m jTextArea1.append(log); FileCreate fileCreate = new FileCreate(directoryName, Constants.IS_FOLDER); lstCommit.add(fileCreate); } }
From source file:caillou.company.clonemanager.gui.service.task.impl.EnqueueImplTask.java
@Override protected VisitDirectoriesResult call() throws Exception { workerMonitor.addWorker(WorkerMonitor.HASH_WORKER, this); Set<ApplicationFile> myFileToTreat = new HashSet<>(); Long byteToTreat = (long) 0; Filter<ApplicationFile> filter = mainModel.getCritereModel().getFilters(); LocationsModel locationsModel = mainModel.getLocationsModel(); Iterator<LocationModel> ite = locationsModel.iterator(); while (ite.hasNext()) { FileVisitor fileVisitor = new FileVisitor(filter); LocationModel locationModel = ite.next(); fileVisitor.addFilter(locationModel.getExcludeModel().getFilters()); if (locationModel.getPath() != null) { File file = new File(locationModel.getPath()); if (file.exists() && file.isDirectory()) { fileVisitor.visit(this, file.toPath(), locationModel.getGroup()); myFileToTreat.addAll(fileVisitor.getFilesToTreat()); byteToTreat += fileVisitor.getBytesToTreat(); }// w ww. j a v a2s . co m } } this.setMyFilesToTreat(myFileToTreat); this.updateProgress(1.0, 1.0); VisitDirectoriesResult visitDirectoriesResult = new VisitDirectoriesResult(); visitDirectoriesResult.setByteToTreat(byteToTreat); visitDirectoriesResult.setFilesToTreat(myFileToTreat); workerMonitor.removeWorker(WorkerMonitor.HASH_WORKER, this); return visitDirectoriesResult; }
From source file:com.ibm.liberty.starter.unit.GitHubWriterTest.java
private void assertFileExistsWithContent(String pathToFile, byte[] expectedContents, File localGitRepo) throws IOException { File rootFile = new File(localGitRepo, pathToFile); assertThat(rootFile, is(anExistingFile())); assertThat(Files.readAllBytes(rootFile.toPath()), is(expectedContents)); }
From source file:com.sonar.javascript.it.plugin.SonarLintTest.java
private ClientInputFile prepareInputFile(String relativePath, String content, final boolean isTest) throws IOException { File file = new File(baseDir, relativePath); FileUtils.write(file, content, StandardCharsets.UTF_8); return createInputFile(file.toPath(), isTest); }