当前位置: 首页>>代码示例>>Java>>正文


Java BasicFileAttributes类代码示例

本文整理汇总了Java中java.nio.file.attribute.BasicFileAttributes的典型用法代码示例。如果您正苦于以下问题:Java BasicFileAttributes类的具体用法?Java BasicFileAttributes怎么用?Java BasicFileAttributes使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


BasicFileAttributes类属于java.nio.file.attribute包,在下文中一共展示了BasicFileAttributes类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: ArchiveContainer

import java.nio.file.attribute.BasicFileAttributes; //导入依赖的package包/类
public ArchiveContainer(Path archivePath) throws IOException, ProviderNotFoundException, SecurityException {
    this.archivePath = archivePath;
    if (multiReleaseValue != null && archivePath.toString().endsWith(".jar")) {
        Map<String,String> env = Collections.singletonMap("multi-release", multiReleaseValue);
        FileSystemProvider jarFSProvider = fsInfo.getJarFSProvider();
        Assert.checkNonNull(jarFSProvider, "should have been caught before!");
        this.fileSystem = jarFSProvider.newFileSystem(archivePath, env);
    } else {
        this.fileSystem = FileSystems.newFileSystem(archivePath, null);
    }
    packages = new HashMap<>();
    for (Path root : fileSystem.getRootDirectories()) {
        Files.walkFileTree(root, EnumSet.noneOf(FileVisitOption.class), Integer.MAX_VALUE,
                new SimpleFileVisitor<Path>() {
                    @Override
                    public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) {
                        if (isValid(dir.getFileName())) {
                            packages.put(new RelativeDirectory(root.relativize(dir).toString()), dir);
                            return FileVisitResult.CONTINUE;
                        } else {
                            return FileVisitResult.SKIP_SUBTREE;
                        }
                    }
                });
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:27,代码来源:JavacFileManager.java

示例2: visitFile

import java.nio.file.attribute.BasicFileAttributes; //导入依赖的package包/类
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attr) {
    // NOTE if we are searching for Directories also file may be NULL ??
    if (file == null) {
        System.out.println("visitFile File: is NULL");
        return CONTINUE;
    }
    if (file.getFileName().equals(fileName)) {
        System.out.println("Located file: " + file);
        if (!matchWithoutSuffix) {
            MFM_FindFile.file = file;
            exists = true;
            return TERMINATE;
        }
    }  // Do we have a base file name, extension not included, match??
    else if (compareFileBaseName(file.getFileName(), fileName)) {
        System.out.println("Located file: " + file);
        files.add(file);
        exists = true;
    }
    return CONTINUE;
}
 
开发者ID:phweda,项目名称:MFM,代码行数:23,代码来源:FileUtils.java

示例3: folderSize

import java.nio.file.attribute.BasicFileAttributes; //导入依赖的package包/类
/**
 * Get the size of a directory in bytes
 * @param folder The directory for which we need size.
 * @return The size of the directory
 */
public static long folderSize(File folder)
{
    final long [] sizeArr = {0L};
    try
    {
        Files.walkFileTree(folder.toPath(), new SimpleFileVisitor<Path>()
        {
            @Override
            public FileVisitResult visitFile(Path file, BasicFileAttributes attrs)
            {
                sizeArr[0] += attrs.size();
                return FileVisitResult.CONTINUE;
            }
        });
    }
    catch (IOException e)
    {
        logger.error("Error while getting {} folder size. {}", folder, e);
    }
    return sizeArr[0];
}
 
开发者ID:Netflix,项目名称:sstable-adaptor,代码行数:27,代码来源:FileUtils.java

示例4: showFiles

import java.nio.file.attribute.BasicFileAttributes; //导入依赖的package包/类
/**
 * This method is primarily used to give visual confirmation that a test case
 * generated files when the compilation succeeds and so generates no other output,
 * such as error messages.
 */
List<Path> showFiles(Path dir) throws IOException {
    List<Path> files = new ArrayList<>();
    Files.walkFileTree(dir, new SimpleFileVisitor<Path>() {
        @Override
        public FileVisitResult visitFile(Path file, BasicFileAttributes attrs)
                throws IOException {
            if (Files.isRegularFile(file)) {
                out.println("Found " + file);
                files.add(file);
            }
            return FileVisitResult.CONTINUE;
        }
    });
    return files;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:21,代码来源:SourcePathTest.java

示例5: deleteDirectoryIfExists

import java.nio.file.attribute.BasicFileAttributes; //导入依赖的package包/类
protected static boolean deleteDirectoryIfExists(final Path directory) throws IOException {
    if (Files.exists(directory)) {
        Files.walkFileTree(directory, new SimpleFileVisitor<Path>() {
            @Override
            public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
                Files.delete(file);
                return FileVisitResult.CONTINUE;
            }

            @Override
            public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {
                Files.delete(dir);
                return FileVisitResult.CONTINUE;
            }
        });
        return true;
    }
    return false;
}
 
开发者ID:Sproutigy,项目名称:LucenePlus,代码行数:20,代码来源:FSLuceneIndices.java

示例6: scanCfgPaths

import java.nio.file.attribute.BasicFileAttributes; //导入依赖的package包/类
public static List<Path> scanCfgPaths() {

        List<String> logcfg = Constants.V8_Dirs();

        ArrayList<Path> cfgFiles = new ArrayList<Path>();
        SimpleFileVisitor<Path> visitor = new SimpleFileVisitor<Path>() {
            @Override
            public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
                Path lastName = file.getFileName();
                if (lastName != null && lastName.toString().matches("(?i)logcfg.xml"))
                    cfgFiles.add(file);
                return FileVisitResult.CONTINUE;
            }
        };

        try {
            for (String location : logcfg) {
                Files.walkFileTree(Paths.get(location), visitor);
            }
        } catch (IOException e) {
            //to do: need a feature that add log location specified by user
            ///ExcpReporting.LogError(LogsOperations.class, e);
        }
        return cfgFiles;
    }
 
开发者ID:ripreal,项目名称:V8LogScanner,代码行数:26,代码来源:LogsOperations.java

示例7: computeFileDigest

import java.nio.file.attribute.BasicFileAttributes; //导入依赖的package包/类
/**
 * Computes the digest of the contents of the file this database belongs to.
 *
 * @return a digest, representing the contents of the file
 * @throws IOException in the case of an error during IO operations
 */
private String computeFileDigest() throws IOException {
    final BasicFileAttributes attr =
            Files.readAttributes(Paths.get(fileDatabase.getFileName()), BasicFileAttributes.class);

    return DigestUtils.sha512Hex(fileDatabase.getFileName() + attr.lastModifiedTime() + attr.size());
}
 
开发者ID:ProgrammingLife2017,项目名称:hygene,代码行数:13,代码来源:FileMetadata.java

示例8: deleteDirectory

import java.nio.file.attribute.BasicFileAttributes; //导入依赖的package包/类
/**
 * Deletes a directory recursively
 *
 * @param directory
 * @return true if deletion succeeds, false otherwise
 */
public static boolean deleteDirectory(Path directory) {
    if (directory != null) {
        try {
            Files.walkFileTree(directory, new SimpleFileVisitor<Path>() {
                @Override
                public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
                    Files.delete(file);
                    return FileVisitResult.CONTINUE;
                }

                @Override
                public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {
                    Files.delete(dir);
                    return FileVisitResult.CONTINUE;
                }
            });
        } catch (IOException ignored) {
            return false;
        }
    }
    return true;
}
 
开发者ID:fabric8-launcher,项目名称:launcher-backend,代码行数:29,代码来源:FileUploadHelper.java

示例9: preVisitDirectory

import java.nio.file.attribute.BasicFileAttributes; //导入依赖的package包/类
@Override
public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException {
	
	// --- Check if the current folder is in the skipList ------
	if(this.skipList != null){
 	for(Path pathToSkip : skipList){
 		if(pathToSkip.equals(dir)){
 			return FileVisitResult.SKIP_SUBTREE;
 		}
 	}
	}
	
	// --- If not, create a corresponding folder in the target path ---------------
    Path targetPath = toPath.resolve(fromPath.relativize(dir));
    if(!Files.exists(targetPath)){
        Files.createDirectory(targetPath);
    }
    
    return FileVisitResult.CONTINUE;
}
 
开发者ID:EnFlexIT,项目名称:AgentWorkbench,代码行数:21,代码来源:RecursiveFolderCopier.java

示例10: cleanDirectory

import java.nio.file.attribute.BasicFileAttributes; //导入依赖的package包/类
/**
 * Deletes all content of a directory (but not the directory itself).
 * @param root the directory to be cleaned
 * @throws IOException if an error occurs while cleaning the directory
 */
public void cleanDirectory(Path root) throws IOException {
    if (!Files.isDirectory(root)) {
        throw new IOException(root + " is not a directory");
    }
    Files.walkFileTree(root, new SimpleFileVisitor<Path>() {
        @Override
        public FileVisitResult visitFile(Path file, BasicFileAttributes a) throws IOException {
            Files.delete(file);
            return FileVisitResult.CONTINUE;
        }

        @Override
        public FileVisitResult postVisitDirectory(Path dir, IOException e) throws IOException {
            if (e != null) {
                throw e;
            }
            if (!dir.equals(root)) {
                Files.delete(dir);
            }
            return FileVisitResult.CONTINUE;
        }
    });
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:29,代码来源:ToolBox.java

示例11: deleteDirectory

import java.nio.file.attribute.BasicFileAttributes; //导入依赖的package包/类
private void deleteDirectory(Path directory) throws IOException {
	Files.walkFileTree(directory, new SimpleFileVisitor<Path>() {

		@Override
		public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
			Files.delete(file);
			return FileVisitResult.CONTINUE;
		}

		@Override
		public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {
			Files.delete(dir);
			return FileVisitResult.CONTINUE;
		}

	});
}
 
开发者ID:maenu,项目名称:kowalski,代码行数:18,代码来源:ApplicationTest.java

示例12: LocalTranslog

import java.nio.file.attribute.BasicFileAttributes; //导入依赖的package包/类
public LocalTranslog(TranslogConfig config) throws IOException {
    super(config.getShardId(), config.getIndexSettings());
    ReadWriteLock rwl = new ReentrantReadWriteLock();
    readLock = new ReleasableLock(rwl.readLock());
    writeLock = new ReleasableLock(rwl.writeLock());
    this.translogPath = config.getTranslogPath();
    // clean all files
    Files.createDirectories(this.translogPath);
    Files.walkFileTree(this.translogPath, new SimpleFileVisitor<Path>() {
        @Override
        public FileVisitResult visitFile(Path file,
                BasicFileAttributes attrs) throws IOException {
            Files.delete(file);
            return FileVisitResult.CONTINUE;
        }
    });
    
    // create a new directory
    writeChannel = FileChannel.open(this.translogPath.resolve(getFileNameFromId(tmpTranslogGeneration.get())), StandardOpenOption.CREATE_NEW, StandardOpenOption.WRITE);
    writtenOffset = 0;
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:22,代码来源:LocalTranslog.java

示例13: list

import java.nio.file.attribute.BasicFileAttributes; //导入依赖的package包/类
public List<String> list() {
    List<String> files = new ArrayList<>();
    try {
        Files.walkFileTree(Paths.get(this.path), new SimpleFileVisitor<Path>() {
            @Override
            public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) {
                Path name = regExMatch ? file.toAbsolutePath() : file.getFileName();
                if (name != null && matcher.matches(name)) {
                    files.add(file.toAbsolutePath().toString());
                }
                return FileVisitResult.CONTINUE;
            }
        });
    } catch (IOException e) {
        logger.error(e);
    }
    return files;
}
 
开发者ID:qamatic,项目名称:mintleaf,代码行数:19,代码来源:FileFinder.java

示例14: get

import java.nio.file.attribute.BasicFileAttributes; //导入依赖的package包/类
public static Source get(File file, boolean toDelete) throws IOException {
    Key key = new Key(file,
                      Files.readAttributes(file.toPath(), BasicFileAttributes.class));
    Source src = null;
    synchronized (files) {
        src = files.get(key);
        if (src != null) {
            src.refs++;
            return src;
        }
    }
    src = new Source(key, toDelete);

    synchronized (files) {
        if (files.containsKey(key)) {    // someone else put in first
            src.close();                 // close the newly created one
            src = files.get(key);
            src.refs++;
            return src;
        }
        files.put(key, src);
        return src;
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:25,代码来源:ZipFile.java

示例15: visitFile

import java.nio.file.attribute.BasicFileAttributes; //导入依赖的package包/类
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
    if (!attrs.isRegularFile()) return CONTINUE;

    if (partOfNameCheck && file.getFileName().toString().indexOf(this.partOfName) == -1)
        return CONTINUE;

    if (minSizeCheck && attrs.size() < minSize)
        return CONTINUE;

    if (maxSizeCheck && attrs.size() > maxSize)
        return CONTINUE;

    if (partOfContentCheck && new String(Files.readAllBytes(file)).indexOf(partOfContent) == -1)
        return CONTINUE;

    foundFiles.add(file);

    return CONTINUE;
}
 
开发者ID:avedensky,项目名称:JavaRushTasks,代码行数:21,代码来源:SearchFileVisitor.java


注:本文中的java.nio.file.attribute.BasicFileAttributes类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。