當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。