List of usage examples for java.io File toPath
public Path toPath()
From source file:de.alexkamp.sandbox.ChrootSandbox.java
@Override public void walkDirectoryTree(String basePath, final DirectoryWalker walker) throws IOException { final int baseNameCount = data.getBaseDir().toPath().getNameCount(); File base = new File(data.getBaseDir(), basePath); Files.walkFileTree(base.toPath(), new FileVisitor<Path>() { @Override//from www.jav a2 s. c o m public FileVisitResult preVisitDirectory(Path path, BasicFileAttributes basicFileAttributes) throws IOException { if (walker.visitDirectory(calcSubpath(path))) { return FileVisitResult.CONTINUE; } return FileVisitResult.SKIP_SUBTREE; } private String calcSubpath(Path path) { if (path.getNameCount() == baseNameCount) { return "/"; } return "/" + path.subpath(baseNameCount, path.getNameCount()).toString(); } @Override public FileVisitResult visitFile(Path path, BasicFileAttributes basicFileAttributes) throws IOException { String subpath = calcSubpath(path); if (walker.visitFile(subpath)) { try (InputStream is = Files.newInputStream(path)) { walker.visitFileContent(subpath, is); } } return FileVisitResult.CONTINUE; } @Override public FileVisitResult visitFileFailed(Path path, IOException e) throws IOException { if (walker.failed(e)) { return FileVisitResult.CONTINUE; } else { return FileVisitResult.TERMINATE; } } @Override public FileVisitResult postVisitDirectory(Path path, IOException e) throws IOException { return FileVisitResult.CONTINUE; } }); }
From source file:easyproject.bean.CommentBean.java
public String doUpdateFile() throws IOException { String path = "/Users/csalas/NetBeansProjects/easyprojectSpring/web/uploaded/"; String urlPath = "http://localhost:8080/easyprojectSpring/uploaded/"; String fileName = String.valueOf(System.currentTimeMillis()) + getFilename(file); Comment comment = new Comment(); message = "Ha subido el fichero: <a href='" + urlPath + fileName + "'>" + fileName + "</a>"; file.write(getFilename(file));// w w w. j a v a2 s .c om comment.setCommentText(message); comment.setId(String.valueOf(System.currentTimeMillis())); comment.setUserName(userBean.getUser().getName()); int indexOf = userBean.getProjectSelected().getListTasks().indexOf(userBean.getTaskSelected()); userBean.getProjectSelected().getListTasks().get(indexOf).getComments().add(comment); File dowloadFile = new File( "/Applications/NetBeans/glassfish-4.1/glassfish/domains/domain1/generated/jsp/SpringMongoJSF/" + getFilename(file)); File newFile = new File(path + fileName); Path sourcePath = dowloadFile.toPath(); Path newtPath = newFile.toPath(); Files.copy(sourcePath, newtPath, REPLACE_EXISTING); userBean.getProjectSelected().getListTasks().get(indexOf).getFiles().add(urlPath + getFilename(file)); projectService.editProject(userBean.getProjectSelected()); message = ""; return ""; }
From source file:junit.org.rapidpm.microdao.HsqlDBBaseTestUtils.java
private boolean deleteDirectory(final String path) { final File indexDirectory = new File(path); if (indexDirectory.exists()) { try {/*from w w w. j a va 2s . c o m*/ Files.walkFileTree(indexDirectory.toPath(), new SimpleFileVisitor<Path>() { @Override public FileVisitResult visitFile(final Path file, final BasicFileAttributes attrs) throws IOException { Files.delete(file); return FileVisitResult.CONTINUE; } @Override public FileVisitResult postVisitDirectory(final Path dir, final IOException exc) throws IOException { Files.delete(dir); return FileVisitResult.CONTINUE; } }); } catch (IOException e) { e.printStackTrace(); return false; } return true; } return false; }
From source file:com.synopsys.integration.util.CommonZipExpander.java
private void expandUnknownFile(File unknownFile, File targetExpansionDirectory) throws IOException, IntegrationException, ArchiveException { String format;/*www. j a v a 2s .c o m*/ // we need to use an InputStream where inputStream.markSupported() == true try (InputStream i = new BufferedInputStream(Files.newInputStream(unknownFile.toPath()))) { format = new ArchiveStreamFactory().detect(i); } beforeExpansion(unknownFile, targetExpansionDirectory); // in the case of zip files, commons-compress creates, but does not close, the ZipFile. To avoid this unclosed resource, we handle it ourselves. try { if (ArchiveStreamFactory.ZIP.equals(format)) { try (ZipFile zipFile = new ZipFile(unknownFile)) { expander.expand(zipFile, targetExpansionDirectory); } } else { expander.expand(unknownFile, targetExpansionDirectory); } } catch (IOException | ArchiveException e) { logger.error("Couldn't extract the archive file - check the file's permissions: " + e.getMessage()); throw e; } afterExpansion(unknownFile, targetExpansionDirectory); }
From source file:com.itemanalysis.jmetrik.file.JmetrikFileWriter.java
public JmetrikFileWriter(File file, LinkedHashMap<VariableName, VariableAttributes> variableAttributeMap, boolean printScoredValues) { this(file.toPath(), variableAttributeMap, printScoredValues); }
From source file:jhi.buntata.server.NodeMedia.java
@Put public boolean putMedia(Representation entity) { if (entity != null && MediaType.MULTIPART_FORM_DATA.equals(entity.getMediaType(), true)) { try {//from w w w . ja v a 2 s . c o m BuntataNode node = nodeDAO.get(id); DiskFileItemFactory factory = new DiskFileItemFactory(); RestletFileUpload upload = new RestletFileUpload(factory); FileItemIterator fileIterator = upload.getItemIterator(entity); if (fileIterator.hasNext()) { String nodeName = node.getName().replace(" ", "-"); File dir = new File(dataDir, nodeName); dir.mkdirs(); FileItemStream fi = fileIterator.next(); String name = fi.getName(); File file = new File(dir, name); int i = 1; while (file.exists()) file = new File(dir, (i++) + name); // Copy the file to its target location Files.copy(fi.openStream(), file.toPath()); // Create the media entity String relativePath = new File(dataDir).toURI().relativize(file.toURI()).getPath(); BuntataMedia media = new BuntataMedia(null, new Date(), new Date()) .setInternalLink(relativePath).setName(name).setDescription(name).setMediaTypeId(1L); mediaDAO.add(media); // Create the node media entity nodeMediaDAO.add(new BuntataNodeMedia().setMediaId(media.getId()).setNodeId(node.getId())); return true; } } catch (Exception e) { e.printStackTrace(); } } else { throw new ResourceException(Status.CLIENT_ERROR_UNSUPPORTED_MEDIA_TYPE); } return false; }
From source file:algorithm.OpenStegoRandomLSBSteganography.java
private String getPayload(File carrier, File payload) throws IOException { PayloadSegment payloadSegment = new PayloadSegment(carrier, payload, this); File payloadSemgentFile = new File("tmp"); FileUtils.writeByteArrayToFile(payloadSemgentFile, payloadSegment.getPayloadSegmentBytes()); return "" + payloadSemgentFile.toPath(); }
From source file:edu.emory.cci.aiw.cvrg.eureka.etl.resource.OutputResource.java
@DELETE @Path("/output/{destinationId}") public Response doDelete(@PathParam("destinationId") String inId) { try {// w w w. j a v a 2 s .com final File outputFile = new File(this.etlProperties.outputFileDirectory(inId), this.patientSetSenderSupport.getOutputName(inId)); if (!outputFile.exists()) { throw new HttpStatusException(Status.NOT_FOUND); } Files.delete(outputFile.toPath()); return Response.noContent().build(); } catch (IOException ex) { throw new HttpStatusException(Status.INTERNAL_SERVER_ERROR, ex); } }
From source file:io.syndesis.git.GitWorkflow.java
/** * Write files to the file system// w w w .j a v a 2 s . c o m * * @param workingDir * @param files * @throws IOException */ @SuppressWarnings("unused") private void writeFiles(Path workingDir, Map<String, byte[]> files) throws IOException { for (Map.Entry<String, byte[]> entry : files.entrySet()) { File file = new File(workingDir.toString(), entry.getKey()); if (!file.getParentFile().exists() && !file.getParentFile().mkdirs()) { throw new IOException("Cannot create directory " + file.getParentFile()); } Files.write(file.toPath(), entry.getValue()); } }
From source file:de.fau.osr.util.VisibleFilesTraverser.java
protected void handleFile(File file, int depth, Collection results) throws IOException { // Using unix-style file paths. String filename = file.toString().replaceAll(Matcher.quoteReplacement("\\"), "/"); for (String eachIgnore : ignoreList) if (filename.contains(eachIgnore)) return; results.add(startDirectory.relativize(file.toPath())); }