本文整理汇总了Java中java.nio.file.Files.readAttributes方法的典型用法代码示例。如果您正苦于以下问题:Java Files.readAttributes方法的具体用法?Java Files.readAttributes怎么用?Java Files.readAttributes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.nio.file.Files
的用法示例。
在下文中一共展示了Files.readAttributes方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: toFilePath
import java.nio.file.Files; //导入方法依赖的package包/类
/**
* Returns a file path to a resource in a file tree. If the resource
* name has a trailing "/" then the file path will locate a directory.
* Returns {@code null} if the resource does not map to a file in the
* tree file.
*/
public static Path toFilePath(Path dir, String name) throws IOException {
boolean expectDirectory = name.endsWith("/");
if (expectDirectory) {
name = name.substring(0, name.length() - 1); // drop trailing "/"
}
Path path = toSafeFilePath(dir.getFileSystem(), name);
if (path != null) {
Path file = dir.resolve(path);
try {
BasicFileAttributes attrs;
attrs = Files.readAttributes(file, BasicFileAttributes.class);
if (attrs.isDirectory()
|| (!attrs.isDirectory() && !expectDirectory))
return file;
} catch (NoSuchFileException ignore) { }
}
return null;
}
示例2: listBlobsByPrefix
import java.nio.file.Files; //导入方法依赖的package包/类
@Override
public Map<String, BlobMetaData> listBlobsByPrefix(String blobNamePrefix) throws IOException {
// If we get duplicate files we should just take the last entry
Map<String, BlobMetaData> builder = new HashMap<>();
blobNamePrefix = blobNamePrefix == null ? "" : blobNamePrefix;
try (DirectoryStream<Path> stream = Files.newDirectoryStream(path, blobNamePrefix + "*")) {
for (Path file : stream) {
final BasicFileAttributes attrs = Files.readAttributes(file, BasicFileAttributes.class);
if (attrs.isRegularFile()) {
builder.put(file.getFileName().toString(), new PlainBlobMetaData(file.getFileName().toString(), attrs.size()));
}
}
}
return unmodifiableMap(builder);
}
示例3: accept
import java.nio.file.Files; //导入方法依赖的package包/类
@Override
public boolean accept(Path path) throws IOException {
if (!Files.isDirectory(path)) {
return false;
}
if (!path.getFileName().toString().startsWith(TMP_NAME_PREFIX)) {
return false;
}
long threshold = System.currentTimeMillis() - CLEAN_MAX_AGE;
// we could also check the timestamp in the name, instead
BasicFileAttributes attrs;
try {
attrs = Files.readAttributes(path, BasicFileAttributes.class);
} catch (IOException ioe) {
LOG.error(String.format("Couldn't read file attributes for %s : ", path), ioe);
return false;
}
long creationTime = attrs.creationTime().toMillis();
return creationTime < threshold;
}
示例4: getLastModifiedTime
import java.nio.file.Files; //导入方法依赖的package包/类
/**
* Retorna a data da última modificação no arquivo
*
* @param file local do arquivo
* @return data da última modificação no arquivo do banco de dados no
* formato longtime
*/
public static long getLastModifiedTime(File file) {
try {
Path path = file.toPath();
BasicFileAttributes attr = Files.readAttributes(path, BasicFileAttributes.class);
return attr.lastModifiedTime().toMillis();
} catch (IOException ex) {
return 0;
}
}
示例5: imageFileAttributes
import java.nio.file.Files; //导入方法依赖的package包/类
/**
* Returns the file attributes of the image file.
*/
BasicFileAttributes imageFileAttributes() {
BasicFileAttributes attrs = imageFileAttributes;
if (attrs == null) {
try {
Path file = getImagePath();
attrs = Files.readAttributes(file, BasicFileAttributes.class);
} catch (IOException ioe) {
throw new UncheckedIOException(ioe);
}
imageFileAttributes = attrs;
}
return attrs;
}
示例6: scanDirectory
import java.nio.file.Files; //导入方法依赖的package包/类
/**
* Scans the given directory for packaged or exploded modules.
*
* @return a map of module name to ModuleReference for the modules found
* in the directory
*
* @throws IOException if an I/O error occurs
* @throws FindException if an error occurs scanning the entry or the
* directory contains two or more modules with the same name
*/
private Map<String, ModuleReference> scanDirectory(Path dir)
throws IOException
{
// The map of name -> mref of modules found in this directory.
Map<String, ModuleReference> nameToReference = new HashMap<>();
try (DirectoryStream<Path> stream = Files.newDirectoryStream(dir)) {
for (Path entry : stream) {
BasicFileAttributes attrs;
try {
attrs = Files.readAttributes(entry, BasicFileAttributes.class);
} catch (NoSuchFileException ignore) {
// file has been removed or moved, ignore for now
continue;
}
ModuleReference mref = readModule(entry, attrs);
// module found
if (mref != null) {
// can have at most one version of a module in the directory
String name = mref.descriptor().name();
ModuleReference previous = nameToReference.put(name, mref);
if (previous != null) {
String fn1 = fileName(mref);
String fn2 = fileName(previous);
throw new FindException("Two versions of module "
+ name + " found in " + dir
+ " (" + fn1 + " and " + fn2 + ")");
}
}
}
}
return nameToReference;
}
示例7: bucketFromPath
import java.nio.file.Files; //导入方法依赖的package包/类
private Bucket bucketFromPath(final Path path) {
Bucket result = null;
final BasicFileAttributes attributes;
try {
attributes = Files.readAttributes(path, BasicFileAttributes.class);
result =
new Bucket(path,
path.getFileName().toString(),
S3_OBJECT_DATE_FORMAT.format(new Date(attributes.creationTime().toMillis())));
} catch (final IOException e) {
LOG.error("File can not be read!", e);
}
return result;
}
示例8: ExplodedImage
import java.nio.file.Files; //导入方法依赖的package包/类
ExplodedImage(Path modulesDir) throws IOException {
defaultFS = FileSystems.getDefault();
String str = defaultFS.getSeparator();
separator = str.equals("/") ? null : str;
modulesDirAttrs = Files.readAttributes(modulesDir, BasicFileAttributes.class);
initNodes();
}
示例9: putS3ObjectWithKMSEncryption
import java.nio.file.Files; //导入方法依赖的package包/类
/**
* Stores an encrypted File inside a Bucket
*
* @param bucketName Bucket to store the File in
* @param fileName name of the File to be stored
* @param contentType The files Content Type
* @param dataStream The File as InputStream
* @param useV4Signing If {@code true}, V4-style signing is enabled.
* @param encryption The Encryption Type
* @param kmsKeyId The KMS encryption key id
* @return {@link S3Object}
* @throws IOException if an I/O error occurs
*/
public S3Object putS3ObjectWithKMSEncryption(final String bucketName,
final String fileName,
final String contentType,
final InputStream dataStream,
final boolean useV4Signing,
final String encryption, final String kmsKeyId) throws IOException {
final S3Object s3Object = new S3Object();
s3Object.setName(fileName);
s3Object.setContentType(contentType);
s3Object.setEncrypted(true);
s3Object.setKmsEncryption(encryption);
s3Object.setKmsEncryptionKeyId(kmsKeyId);
final Bucket theBucket = getBucketOrCreateNewOne(bucketName);
final File objectRootFolder = createObjectRootFolder(theBucket, s3Object.getName());
final File dataFile =
inputStreamToFile(wrapStream(dataStream, useV4Signing),
objectRootFolder.toPath().resolve(DATA_FILE));
s3Object.setDataFile(dataFile);
s3Object.setSize(Long.toString(dataFile.length()));
final BasicFileAttributes attributes =
Files.readAttributes(dataFile.toPath(), BasicFileAttributes.class);
s3Object.setCreationDate(
S3_OBJECT_DATE_FORMAT.format(new Date(attributes.creationTime().toMillis())));
s3Object.setModificationDate(
S3_OBJECT_DATE_FORMAT.format(new Date(attributes.lastModifiedTime().toMillis())));
s3Object.setLastModified(attributes.lastModifiedTime().toMillis());
s3Object.setMd5(digest(kmsKeyId, dataFile));
objectMapper.writeValue(new File(objectRootFolder, META_FILE), s3Object);
return s3Object;
}
示例10: readAttributes
import java.nio.file.Files; //导入方法依赖的package包/类
@Override
public Map<String,Object> readAttributes(Path file, String attributes, LinkOption... options)
throws IOException
{
triggerEx(file, "readAttributes");
return Files.readAttributes(unwrap(file), attributes, options);
}
示例11: putS3Object
import java.nio.file.Files; //导入方法依赖的package包/类
/**
* Stores a File inside a Bucket
*
* @param bucketName Bucket to store the File in
* @param fileName name of the File to be stored
* @param contentType The files Content Type
* @param dataStream The File as InputStream
* @param useV4Signing If {@code true}, V4-style signing is enabled.
* @return {@link S3Object}
* @throws IOException if an I/O error occurs
*/
public S3Object putS3Object(final String bucketName,
final String fileName,
final String contentType,
final InputStream dataStream,
final boolean useV4Signing) throws IOException {
final S3Object s3Object = new S3Object();
s3Object.setName(fileName);
s3Object.setContentType(contentType);
final Bucket theBucket = getBucketOrCreateNewOne(bucketName);
final File objectRootFolder = createObjectRootFolder(theBucket, s3Object.getName());
final File dataFile =
inputStreamToFile(wrapStream(dataStream, useV4Signing),
objectRootFolder.toPath().resolve(DATA_FILE));
s3Object.setDataFile(dataFile);
s3Object.setSize(Long.toString(dataFile.length()));
final BasicFileAttributes attributes =
Files.readAttributes(dataFile.toPath(), BasicFileAttributes.class);
s3Object.setCreationDate(
S3_OBJECT_DATE_FORMAT.format(new Date(attributes.creationTime().toMillis())));
s3Object.setModificationDate(
S3_OBJECT_DATE_FORMAT.format(new Date(attributes.lastModifiedTime().toMillis())));
s3Object.setLastModified(attributes.lastModifiedTime().toMillis());
s3Object.setMd5(digest(null, dataFile));
objectMapper.writeValue(new File(objectRootFolder, META_FILE), s3Object);
return s3Object;
}
示例12: summaryAll
import java.nio.file.Files; //导入方法依赖的package包/类
public static void summaryAll() throws IOException{
int sel = jTabbedPane1.getSelectedIndex();
jLabel23.setText(jTabbedPane1.getTitleAt(sel));
jLabel24.setText("File Location : " + titleText.getText());
/**String[] {splitStrings = filesave.getSelectedFile().getName().split("\\.") ;
String extension = splitStrings[splitStrings.length-1] ;
fileext.setText(extension);}**/
jLabel16.setText("File Extention : " + titleExtLa.getText());
JTextArea textPane = (JTextArea) ((JScrollPane) ((JDesktopPane)jTabbedPane1.getComponentAt(sel)).getComponent(0)).getViewport().getComponent(0);
String totaltext= textPane.getText();
String totalwords[]=totaltext.split("\\s");
jLabel21.setText("Total Word Typed : " + totalwords.length);
jLabel5.setText("Total Characters With Spaces : " + totaltext.length());
jLabel22.setText("Total Line : " + BasicEvents.getLineCount(textPane));
if (titleText.getText().contains("Untitled")) {
DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
DateFormat date = new SimpleDateFormat("dd/MM/yyyy");
Calendar cal = Calendar.getInstance();
jLabel27.setText(dateFormat.format(cal.getTime()));
jLabel25.setText(dateFormat.format(cal.getTime()));
} else {
Path filepath = Paths.get(titleText.getText()) ;
BasicFileAttributes attr = Files.readAttributes(filepath, BasicFileAttributes.class);
String dateCreate = ""+attr.creationTime() ; String dateCreat = dateCreate.replace("T", " Time Created : ");
String lastModi = ""+attr.lastModifiedTime() ; String lastMod = lastModi.replace("T", " Last Time Modified : ");
jLabel25.setText("Date Created : " + dateCreat );
jLabel27.setText("Last Date Modified : " + lastMod );
}
}
示例13: checkAndNotify
import java.nio.file.Files; //导入方法依赖的package包/类
public void checkAndNotify() throws IOException {
boolean prevExists = exists;
boolean prevIsDirectory = isDirectory;
long prevLength = length;
long prevLastModified = lastModified;
exists = Files.exists(file);
// TODO we might use the new NIO2 API to get real notification?
if (exists) {
BasicFileAttributes attributes = Files.readAttributes(file, BasicFileAttributes.class);
isDirectory = attributes.isDirectory();
if (isDirectory) {
length = 0;
lastModified = 0;
} else {
length = attributes.size();
lastModified = attributes.lastModifiedTime().toMillis();
}
} else {
isDirectory = false;
length = 0;
lastModified = 0;
}
// Perform notifications and update children for the current file
if (prevExists) {
if (exists) {
if (isDirectory) {
if (prevIsDirectory) {
// Remained a directory
updateChildren();
} else {
// File replaced by directory
onFileDeleted();
onDirectoryCreated(false);
}
} else {
if (prevIsDirectory) {
// Directory replaced by file
onDirectoryDeleted();
onFileCreated(false);
} else {
// Remained file
if (prevLastModified != lastModified || prevLength != length) {
onFileChanged();
}
}
}
} else {
// Deleted
if (prevIsDirectory) {
onDirectoryDeleted();
} else {
onFileDeleted();
}
}
} else {
// Created
if (exists) {
if (isDirectory) {
onDirectoryCreated(false);
} else {
onFileCreated(false);
}
}
}
}
示例14: lastModified
import java.nio.file.Files; //导入方法依赖的package包/类
private static long lastModified(String fileName) throws IOException {
Path path = Paths.get(fileName);
BasicFileAttributes attr = Files.readAttributes(path, BasicFileAttributes.class);
return attr.lastModifiedTime().toMillis();
}
示例15: isSymbolicLink
import java.nio.file.Files; //导入方法依赖的package包/类
public static boolean isSymbolicLink(String path) throws Exception {
BasicFileAttributes attrs = Files.readAttributes(FileSystems.getDefault().getPath(polishFilePath(path)), BasicFileAttributes.
class, LinkOption.NOFOLLOW_LINKS);
return attrs.isSymbolicLink();
}