List of usage examples for java.nio.file.attribute BasicFileAttributes isRegularFile
boolean isRegularFile();
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();/*from w w w .j a v a 2 s. c om*/ } 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.structr.web.maintenance.deploy.ComponentImportVisitor.java
@Override public FileVisitResult visitFile(final Path file, final BasicFileAttributes attrs) throws IOException { if (attrs.isRegularFile()) { final String fileName = file.getFileName().toString(); if (fileName.endsWith(".html")) { try { createComponent(file, fileName); } catch (FrameworkException fex) { logger.warn("Exception while importing shared component {}: {}", fileName, fex.toString()); }// www . j a v a2 s. c om } } else { logger.warn("Unexpected directory {} found in components/ directory, ignoring", file.getFileName().toString()); } return FileVisitResult.CONTINUE; }
From source file:org.structr.web.maintenance.deploy.FileImportVisitor.java
@Override public FileVisitResult visitFile(final Path file, final BasicFileAttributes attrs) throws IOException { if (attrs.isRegularFile()) { createFile(file, file.getFileName().toString()); }/*from www . ja v a 2 s . c o m*/ return FileVisitResult.CONTINUE; }
From source file:org.structr.web.maintenance.deploy.PageImportVisitor.java
@Override public FileVisitResult visitFile(final Path file, final BasicFileAttributes attrs) throws IOException { try {/*ww w . j a va 2 s. c o m*/ 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.deploy.TemplateImportVisitor.java
@Override public FileVisitResult visitFile(final Path file, final BasicFileAttributes attrs) throws IOException { if (attrs.isRegularFile()) { final String fileName = file.getFileName().toString(); if (fileName.endsWith(".html")) { try { createTemplate(file, fileName); } catch (FrameworkException fex) { logger.warn("Exception while importing shared component {}: {}", new Object[] { name, fex.getMessage() }); }// w ww . j av a 2s . c o m } } else { logger.warn("Unexpected directory {} found in components/ directory, ignoring", file.getFileName().toString()); } 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); }/*from w w w. j a v a 2 s . com*/ 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/*from w w w . j a v a 2 s. co 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/* w ww . j a v a 2 s.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(); }
From source file:org.wso2.carbon.uuf.internal.io.StaticResolver.java
private ZonedDateTime getLastModifiedDate(Path resourcePath) { if (!Files.isReadable(resourcePath)) { throw new ResourceNotFoundException("Static resource file '" + resourcePath + "' is not readable."); }//from w ww. j a v a 2 s . co m BasicFileAttributes fileAttributes; try { fileAttributes = Files.readAttributes(resourcePath, BasicFileAttributes.class); } catch (NoSuchFileException | FileNotFoundException e) { // This shouldn't be happening because we checked the file's readability before. But just in case. throw new ResourceNotFoundException("Static resource file '" + resourcePath + "' does not exists.", e); } catch (Exception e) { // UnsupportedOperationException, IOException or any other Exception that might occur. throw new FileOperationException( "Cannot read file attributes from static resource file '" + resourcePath + "'.", e); } if (fileAttributes.isRegularFile()) { return ZonedDateTime.ofInstant(fileAttributes.lastModifiedTime().toInstant(), GMT_TIME_ZONE); } else { /* * From book "OCP: Oracle Certified Professional Java SE 8 Programmer II Study Guide" page 478: * Java defines a regular file as one that contains content, as opposed to a symbolic link, * directory, resource (e.g. port, pipe), or other non-regular files that may be present in some * operating systems. [...] It is possible for isRegularFile() to return true for a symbolic link, * as long as the link resolves to a regular file. * Hence, checking 'isRegularFile' of a file is enough to determine its existence and not being a directory. */ throw new ResourceNotFoundException( "Static resource file '" + resourcePath + "' is not a regular file."); } }