List of usage examples for java.nio.file.attribute BasicFileAttributes isDirectory
boolean isDirectory();
From source file:org.cryptomator.frontend.webdav.servlet.DavFolder.java
@Override public DavResourceIterator getMembers() { try (DirectoryStream<Path> stream = Files.newDirectoryStream(path)) { List<DavResource> children = new ArrayList<>(); for (Path childPath : stream) { BasicFileAttributes childAttr = Files.readAttributes(childPath, BasicFileAttributes.class); DavLocatorImpl childLocator = locator.resolveChild(childPath.getFileName().toString()); if (childAttr.isDirectory()) { DavFolder childFolder = factory.createFolder(childLocator, childPath, Optional.of(childAttr), session);/* w ww . j ava2s. co m*/ children.add(childFolder); } else if (childAttr.isRegularFile()) { DavFile childFile = factory.createFile(childLocator, childPath, Optional.of(childAttr), session); children.add(childFile); } } return new DavResourceIteratorImpl(children); } catch (IOException e) { throw new UncheckedIOException(e); } }
From source file:org.fim.internal.StateGenerator.java
private void scanFileTree(BlockingDeque<Path> filesToHashQueue, Path directory, FimIgnore parentFimIgnore) throws NoSuchAlgorithmException { try (DirectoryStream<Path> stream = Files.newDirectoryStream(directory)) { FimIgnore fimIgnore = fimIgnoreManager.loadLocalIgnore(directory, parentFimIgnore); for (Path file : stream) { if (!fileHashersStarted && filesToHashQueue.size() > FILES_QUEUE_CAPACITY / 2) { startFileHashers();//w w w .j a va 2 s .c o m } BasicFileAttributes attributes = Files.readAttributes(file, BasicFileAttributes.class, LinkOption.NOFOLLOW_LINKS); String fileName = file.getFileName().toString(); if (fimIgnoreManager.isIgnored(fileName, attributes, fimIgnore)) { fimIgnoreManager.ignoreThisFiles(file, attributes); } else { if (attributes.isRegularFile()) { enqueueFile(filesToHashQueue, file); } else if (attributes.isDirectory()) { scanFileTree(filesToHashQueue, file, fimIgnore); } } } } catch (IOException ex) { Console.newLine(); Logger.error("Skipping - Error scanning directory '" + directory + "'", ex, context.isDisplayStackTrace()); } }
From source file:org.nuxeo.connect.update.standalone.PackageTestCase.java
/** Zips a directory into the given ZIP file. */ protected void createZip(File zip, Path basePath) throws IOException { try (ZipOutputStream zout = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(zip)))) { Files.walkFileTree(basePath, new SimpleFileVisitor<Path>() { @Override//from ww w . ja v a 2s .c o m public FileVisitResult visitFile(Path path, BasicFileAttributes attrs) throws IOException { if (attrs.isDirectory()) { return FileVisitResult.CONTINUE; } String rel = basePath.relativize(path).toString(); if (rel.startsWith(".")) { return FileVisitResult.CONTINUE; } zout.putNextEntry(new ZipEntry(rel)); try (InputStream in = Files.newInputStream(path)) { org.apache.commons.io.IOUtils.copy(in, zout); } zout.closeEntry(); return FileVisitResult.CONTINUE; } }); zout.flush(); } }
From source file:org.olat.core.util.ZipUtil.java
/** * Add the content of a directory to a zip stream. * // w w w . j a va 2 s . c om * @param path * @param dirName * @param zout */ public static void addDirectoryToZip(final Path path, final String baseDirName, final ZipOutputStream zout) { try { Files.walkFileTree(path, new SimpleFileVisitor<Path>() { @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { if (!attrs.isDirectory()) { Path relativeFile = path.relativize(file); String names = baseDirName + "/" + relativeFile.toString(); zout.putNextEntry(new ZipEntry(names)); try (InputStream in = Files.newInputStream(file)) { FileUtils.copy(in, zout); } catch (Exception e) { log.error("", e); } zout.closeEntry(); } return FileVisitResult.CONTINUE; } }); } catch (IOException e) { log.error("", e); } }
From source file:org.phenotips.variantstore.input.exomiser6.tsv.Exomiser6TSVManager.java
@Override public List<String> getAllIndividuals() { final List<String> list = new ArrayList<>(); try {//from w w w . j a va2 s . c o m Files.walkFileTree(this.path, new SimpleFileVisitor<Path>() { @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { if (attrs.isDirectory()) { return FileVisitResult.CONTINUE; } String filename = file.getFileName().toString(); String id = StringUtils.removeEnd(filename, suffix); list.add(id); return FileVisitResult.CONTINUE; } }); } catch (IOException e) { logger.error("Error getting all individuals", e); } return list; }
From source file:org.phenotips.variantstore.input.vcf.VCFManager.java
@Override public List<String> getAllIndividuals() { final List<String> list = new ArrayList<>(); try {// w ww .j ava 2 s .c om Files.walkFileTree(this.path, new SimpleFileVisitor<Path>() { @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { if (attrs.isDirectory()) { return FileVisitResult.CONTINUE; } String id = file.getFileName().toString(); id = StringUtils.removeEnd(id, suffix); list.add(id); return FileVisitResult.CONTINUE; } }); } catch (IOException e) { logger.error("Error getting all individuals"); } return list; }
From source file:org.structr.web.maintenance.deploy.PageImportVisitor.java
@Override public FileVisitResult visitFile(final Path file, final BasicFileAttributes attrs) throws IOException { try {//from w w w .j a v a2 s . c om if (attrs.isDirectory()) { createFolder(file); } else if (attrs.isRegularFile()) { final String fileName = file.getFileName().toString(); if (fileName.endsWith(".html")) { try { createPage(file, fileName); } catch (FrameworkException fex) { logger.warn("Exception while importing page {}: {}", new Object[] { fileName, fex.toString() }); } } } } catch (Throwable t) { logger.warn("", t); } return FileVisitResult.CONTINUE; }
From source file:org.structr.web.maintenance.DirectFileImportCommand.java
private FileVisitResult createFileOrFolder(final SecurityContext ctx, final App app, final Path path, final Path file, final BasicFileAttributes attrs, final String sourcePath, final String targetPath, final Mode mode, final Existing existing, final boolean doIndex) { ctx.setDoTransactionNotifications(false); final String name = file.getFileName().toString(); try (final Tx tx = app.tx()) { final String relativePath = PathHelper.getRelativeNodePath(path.toString(), file.toString()); String parentPath = targetPath + PathHelper.getFolderPath(relativePath); // fix broken path concatenation if (parentPath.startsWith("//")) { parentPath = parentPath.substring(1); }// w ww.j a v a 2 s . c o m if (attrs.isDirectory()) { final Folder newFolder = app.create(Folder.class, new NodeAttribute(Folder.name, name), new NodeAttribute(StructrApp.key(File.class, "parent"), FileHelper.createFolderPath(securityContext, parentPath))); folderCount++; logger.info("Created folder " + newFolder.getPath()); } else if (attrs.isRegularFile()) { final File existingFile = app.nodeQuery(File.class) .and(StructrApp.key(AbstractFile.class, "path"), parentPath + name).getFirst(); if (existingFile != null) { switch (existing) { case SKIP: logger.info("Skipping import of {}, file exists and mode is SKIP.", parentPath + name); return FileVisitResult.CONTINUE; case OVERWRITE: logger.info("Overwriting {}, file exists and mode is OVERWRITE.", parentPath + name); app.delete(existingFile); break; case RENAME: logger.info("Renaming existing file {}, file exists and mode is RENAME.", parentPath + name); existingFile.setProperty(AbstractFile.name, existingFile.getProperty(AbstractFile.name) .concat("_").concat(FileHelper.getDateString())); break; } } final String contentType = FileHelper.getContentMimeType(file.toFile(), file.getFileName().toString()); boolean isImage = (contentType != null && contentType.startsWith("image")); boolean isVideo = (contentType != null && contentType.startsWith("video")); Class cls = null; if (isImage) { cls = Image.class; } else if (isVideo) { cls = SchemaHelper.getEntityClassForRawType("VideoFile"); if (cls == null) { logger.warn("Unable to create entity of type VideoFile, class is not defined."); } } else { cls = File.class; } final File newFile = (File) app.create(cls, new NodeAttribute(File.name, name), new NodeAttribute(StructrApp.key(File.class, "parent"), FileHelper.createFolderPath(securityContext, parentPath)), new NodeAttribute(AbstractNode.type, cls.getSimpleName())); final java.io.File fileOnDisk = newFile.getFileOnDisk(false); final Path fullFolderPath = fileOnDisk.toPath(); Files.createDirectories(fullFolderPath.getParent()); switch (mode) { case MOVE: Files.move(file, fullFolderPath); break; case COPY: Files.copy(file, fullFolderPath); break; } FileHelper.updateMetadata(newFile); if (doIndex) { indexer.addToFulltextIndex(newFile); } fileCount++; } tx.success(); } catch (IOException | FrameworkException ex) { logger.debug("File: " + name + ", path: " + sourcePath, ex); } return FileVisitResult.CONTINUE; }
From source file:org.tinymediamanager.core.Utils.java
/** * this is the TMM variant of isRegularFiles()<br> * because deduplication creates windows junction points, we check here if it is<br> * not a directory, and either a regular file or "other" one.<br> * see http://serverfault.com/a/667220//w w w.j a v a 2 s. c o m * * @param file * @return */ public static boolean isRegularFile(Path file) { // see windows impl http://grepcode.com/file/repository.grepcode.com/java/root/jdk/openjdk/7u40-b43/sun/nio/fs/WindowsFileAttributes.java#451 try { BasicFileAttributes attr = Files.readAttributes(file, BasicFileAttributes.class); return (attr.isRegularFile() || attr.isOther()) && !attr.isDirectory(); } catch (IOException e) { return false; } }
From source file:org.tinymediamanager.core.Utils.java
/** * this is the TMM variant of isRegularFiles()<br> * because deduplication creates windows junction points, we check here if it is<br> * not a directory, and either a regular file or "other" one.<br> * see http://serverfault.com/a/667220//from ww w .j a va 2s. co m * * @param attr * @return */ public static boolean isRegularFile(BasicFileAttributes attr) { // see windows impl http://grepcode.com/file/repository.grepcode.com/java/root/jdk/openjdk/7u40-b43/sun/nio/fs/WindowsFileAttributes.java#451 return (attr.isRegularFile() || attr.isOther()) && !attr.isDirectory(); }