List of usage examples for java.io File toPath
public Path toPath()
From source file:gr.upatras.ece.nam.baker.testclasses.MockRepositoryWebClient.java
@Override public Path fetchPackageFromLocation(String uuid, String packageLocation) { logger.info("TEST fetchMetadata after 2sec from (dummy): " + packageLocation); try {/*from w w w. j a v a 2 s.c om*/ Thread.sleep(2000); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } try { URL res = getClass().getResource(packageLocation); logger.info("TEST RESOURCE FILE: " + res); File sourceFile = new File(res.getFile()); Path tempDir = Files.createTempDirectory("baker"); File destFile = new File(tempDir + "/" + uuid + "/bun.tar.gz"); Files.createDirectory(Paths.get(tempDir + "/" + uuid)); Path targetPath = destFile.toPath(); logger.info(" to:" + targetPath); Files.copy(sourceFile.toPath(), targetPath); if (mockRepositoryBehavior != MockRepositoryBehavior.RETURN_NULLPACKAGEFILE) { return targetPath; } } catch (IOException e) { e.printStackTrace(); } return null; }
From source file:com.rptools.io.TableFileParser.java
/** * Save new json file if it doesn't exist. Delete the text file. * * @param file Path to file//from w w w. ja v a2s. c om * @param builder RPTable builder to print to JSON file * @return Boolean: If the .json file already existed and will be parsed separately */ private boolean updateResourceFiles(Path file, RPTable.Builder builder) throws IOException { File json = new File(file.toString().replace(EXT_TXT, EXT_JSON)); Files.delete(file); boolean isNew = json.createNewFile(); Files.write(json.toPath(), Lists.newArrayList(JsonFormat.printer().print(builder)), UTF_8); return isNew; }
From source file:com.ibm.liberty.starter.api.v1.LibertyFileUploader.java
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String tech = request.getParameter(PARAMETER_TECH); String workspaceId = request.getParameter(PARAMETER_WORKSPACE); //specify the unique workspace directory to upload the file(s) to. Collection<Part> filePartCollection = request.getParts(); String serverHostPort = request.getRequestURL().toString().replace(request.getRequestURI(), ""); int schemeLength = request.getScheme().toString().length(); String internalHostPort = "http" + serverHostPort.substring(schemeLength); log.log(Level.FINER, "serverHostPort : " + serverHostPort); final ServiceConnector serviceConnector = new ServiceConnector(serverHostPort, internalHostPort); HashMap<Part, String> fileNames = new HashMap<Part, String>(); if (!isValidRequest(request, response, tech, workspaceId, filePartCollection, serviceConnector, fileNames)) {/* w ww . j av a 2s . c om*/ return; } Service techService = serviceConnector.getServiceObjectFromId(tech); String techDirPath = StarterUtil.getWorkspaceDir(workspaceId) + "/" + techService.getId(); File techDir = new File(techDirPath); if (techDir.exists() && techDir.isDirectory() && "true".equalsIgnoreCase(request.getParameter(PARAMETER_CLEANUP))) { FileUtils.cleanDirectory(techDir); log.log(Level.FINER, "Cleaned up tech workspace directory : " + techDirPath); } for (Part filePart : filePartCollection) { if (!techDir.exists()) { FileUtils.forceMkdir(techDir); log.log(Level.FINER, "Created tech directory :" + techDirPath); } String filePath = techDirPath + "/" + fileNames.get(filePart); log.log(Level.FINER, "File path : " + filePath); File uploadedFile = new File(filePath); Files.copy(filePart.getInputStream(), uploadedFile.toPath(), StandardCopyOption.REPLACE_EXISTING); log.log(Level.FINE, "Copied file to " + filePath); } if ("true".equalsIgnoreCase(request.getParameter(PARAMETER_PROCESS))) { // Process uploaded file(s) String processResult = serviceConnector.processUploadedFiles(techService, techDirPath); if (!processResult.equalsIgnoreCase("success")) { log.log(Level.INFO, "Error processing the files uploaded to " + techDirPath + " : Result=" + processResult); response.sendError(500, processResult); return; } log.log(Level.FINE, "Processed the files uploaded to " + techDirPath); } response.setContentType("text/html"); PrintWriter out = response.getWriter(); out.println("success"); out.close(); }
From source file:com.arpnetworking.configuration.jackson.JsonNodeDirectorySourceTest.java
@Test(expected = RuntimeException.class) public void testInvalidJson() throws IOException { final File directory = new File("./target/tmp/filter/JsonNodeDirectorySourceTest/testInvalidJson.json"); deleteDirectory(directory);//w w w .j av a2 s .com Files.createDirectory(directory.toPath()); Files.write(directory.toPath().resolve("foo.json"), "this=not-json".getBytes(Charsets.UTF_8)); Files.write(directory.toPath().resolve("bar.txt"), "\"two\"".getBytes(Charsets.UTF_8)); new JsonNodeDirectorySource.Builder().setDirectory(directory).build(); }
From source file:algorithm.OpenStegoRandomLSBSteganography.java
private String getCover(File carrier) { return "" + carrier.toPath(); }
From source file:com.squareup.wire.schema.internal.parser.RpcMethodScanner.java
private List<RpcMethodDefinition> inspectProtoFile(InputStream instream, String serviceName) throws IOException { File tempFile = File.createTempFile("proto", null); tempFile.delete();//from w w w. j ava 2 s . co m Files.copy(instream, tempFile.toPath()); SixtProtoParser parser = new SixtProtoParser(tempFile, serviceName); List<RpcMethodDefinition> methodDefinitions = parser.getRpcMethods(); tempFile.delete(); instream.close(); return methodDefinitions; }
From source file:com.arpnetworking.configuration.jackson.JsonNodeDirectorySourceTest.java
@Test public void testDirectoryAll() throws IOException { final File directory = new File("./target/tmp/filter/JsonNodeDirectorySourceTest/testDirectoryAll"); deleteDirectory(directory);/*from ww w.j a v a2 s . com*/ Files.createDirectory(directory.toPath()); Files.write(directory.toPath().resolve("foo.json"), "[\"one\"]".getBytes(Charsets.UTF_8)); Files.write(directory.toPath().resolve("bar.txt"), "[\"two\"]".getBytes(Charsets.UTF_8)); final JsonNodeDirectorySource source = new JsonNodeDirectorySource.Builder().setDirectory(directory) .build(); Assert.assertTrue(source.getJsonNode().isPresent()); Assert.assertTrue(source.getJsonNode().get().isArray()); final ArrayNode arrayNode = (ArrayNode) source.getJsonNode().get(); Assert.assertEquals(2, arrayNode.size()); Assert.assertTrue(arrayNodeContains(arrayNode, "one")); Assert.assertTrue(arrayNodeContains(arrayNode, "two")); }
From source file:org.italiangrid.storm.webdav.fs.attrs.DefaultExtendedFileAttributesHelper.java
@Override public String getExtendedFileAttributeValue(File f, String attributeName) throws IOException { Assert.notNull(f);/*from w ww . ja va 2 s . c om*/ Assert.hasText(attributeName); UserDefinedFileAttributeView faView = Files.getFileAttributeView(f.toPath(), UserDefinedFileAttributeView.class); if (faView == null) { throw new IOException("UserDefinedFileAttributeView not supported on file " + f.getAbsolutePath()); } return getAttributeValue(faView, attributeName); }
From source file:eu.crowdrec.flume.plugins.source.DirectIdomaarSource.java
private BufferedReader createReader() { try {/*from w ww .ja v a 2 s .c om*/ if (url != null) return createReaderFromUrl(); File inputFile = new File(fileName); if (format.equals("plain")) { return Files.newBufferedReader(inputFile.toPath(), charset); } else if (format.equals("gzip")) { InputStream fileStream = new FileInputStream(inputFile); InputStream gzipStream = new GZIPInputStream(fileStream); Reader decoder = new InputStreamReader(gzipStream, "UTF-8"); return new BufferedReader(decoder); } } catch (IOException exception) { throw new RuntimeException(exception); } throw new RuntimeException( "Unrecognized settings in DirectIdomaarSource: cannot figure out input source location."); }
From source file:net.larry1123.elec.util.logger.LoggerDirectoryHandler.java
protected void packFile(File file, ZipArchiveOutputStream zipArchiveOutputStream) throws IOException { String relative = getDirectoryPath().relativize(file.toPath()).toString(); // Make an Entry in the archive ArchiveEntry archiveEntry = zipArchiveOutputStream.createArchiveEntry(file, relative); FileInputStream fileInputStream = FileUtils.openInputStream(file); zipArchiveOutputStream.putArchiveEntry(archiveEntry); // Copy file content into archive IOUtils.copy(fileInputStream, zipArchiveOutputStream); zipArchiveOutputStream.closeArchiveEntry(); }