本文整理汇总了Java中java.nio.file.attribute.FileTime.fromMillis方法的典型用法代码示例。如果您正苦于以下问题:Java FileTime.fromMillis方法的具体用法?Java FileTime.fromMillis怎么用?Java FileTime.fromMillis使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.nio.file.attribute.FileTime
的用法示例。
在下文中一共展示了FileTime.fromMillis方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: test
import java.nio.file.attribute.FileTime; //导入方法依赖的package包/类
/**
* Exercise Files.setLastModifiedTime on the given file
*/
void test(Path path) throws Exception {
FileTime now = Files.getLastModifiedTime(path);
FileTime zero = FileTime.fromMillis(0L);
Path result = Files.setLastModifiedTime(path, zero);
assertTrue(result == path);
assertEquals(Files.getLastModifiedTime(path), zero);
result = Files.setLastModifiedTime(path, now);
assertTrue(result == path);
assertEquals(Files.getLastModifiedTime(path), now);
}
示例2: setTimes
import java.nio.file.attribute.FileTime; //导入方法依赖的package包/类
/**
* Sets the {@link Path}'s last modified time and last access time to
* the given valid times.
*
* @param mtime the modification time to set (only if no less than zero).
* @param atime the access time to set (only if no less than zero).
* @throws IOException if setting the times fails.
*/
@Override
public void setTimes(Path p, long mtime, long atime) throws IOException {
try {
BasicFileAttributeView view = Files.getFileAttributeView(
pathToFile(p).toPath(), BasicFileAttributeView.class);
FileTime fmtime = (mtime >= 0) ? FileTime.fromMillis(mtime) : null;
FileTime fatime = (atime >= 0) ? FileTime.fromMillis(atime) : null;
view.setTimes(fmtime, fatime, null);
} catch (NoSuchFileException e) {
throw new FileNotFoundException("File " + p + " does not exist");
}
}
示例3: download
import java.nio.file.attribute.FileTime; //导入方法依赖的package包/类
/**
* Download the resource specified by its URI to the target directory using the provided file name.
*/
Path download(URI uri, Path targetDirectory, String targetFileName, Predicate<Path> useTimeStamp) throws IOException {
URL url = requireNonNull(uri, "uri must not be null").toURL();
requireNonNull(targetDirectory, "targetDirectory must be null");
if (requireNonNull(targetFileName, "targetFileName must be null").isEmpty()) {
throw new IllegalArgumentException("targetFileName must be blank");
}
Files.createDirectories(targetDirectory);
Path targetPath = targetDirectory.resolve(targetFileName);
URLConnection urlConnection = url.openConnection();
FileTime urlLastModifiedTime = FileTime.fromMillis(urlConnection.getLastModified());
if (Files.exists(targetPath)) {
if (Files.getLastModifiedTime(targetPath).equals(urlLastModifiedTime)) {
if (Files.size(targetPath) == urlConnection.getContentLengthLong()) {
if (useTimeStamp.test(targetPath)) {
log.log(Level.FINE, "download skipped - using `%s`%n", targetPath);
return targetPath;
}
}
}
Files.delete(targetPath);
}
log.log(Level.FINE, "download `%s` in progress...%n", uri);
try (InputStream sourceStream = url.openStream(); OutputStream targetStream = Files.newOutputStream(targetPath)) {
sourceStream.transferTo(targetStream);
}
Files.setLastModifiedTime(targetPath, urlLastModifiedTime);
log.log(Level.CONFIG, "download `%s` completed%n", uri);
log.info("stored `%s` [timestamp=%s]%n", targetPath, urlLastModifiedTime.toString());
return targetPath;
}
示例4: setTime
import java.nio.file.attribute.FileTime; //导入方法依赖的package包/类
@Override
public boolean setTime(
final BitField<FsAccessOption> options,
final FsNodeName name,
final BitField<Access> types,
final long value)
throws IOException {
final Path file = target.resolve(name.getPath());
final FileTime time = FileTime.fromMillis(value);
getBasicFileAttributeView(file).setTimes(
types.get(WRITE) ? time : null,
types.get(READ) ? time : null,
types.get(CREATE) ? time : null);
return types.clear(WRITE).clear(READ).clear(CREATE).isEmpty();
}
示例5: setLastModifiedTime
import java.nio.file.attribute.FileTime; //导入方法依赖的package包/类
/**
* altera o longtime da última modificação no arquivo
*
* @param time data no formato longtime
*/
public static void setLastModifiedTime(File file, long time) {
try {
Path path = file.toPath();
FileTime fileTime = FileTime.fromMillis(time);
Files.setLastModifiedTime(path, fileTime);
} catch (IOException ex) {
}
}
示例6: setFileCreationDate
import java.nio.file.attribute.FileTime; //导入方法依赖的package包/类
public static void setFileCreationDate(String filePath, Date creationDate) throws IOException
{
BasicFileAttributeView attributes = Files.getFileAttributeView(Paths.get(filePath), BasicFileAttributeView.class);
FileTime time = FileTime.fromMillis(creationDate.getTime());
attributes.setTimes(time, time, time);
}
示例7: getLastModifiedTime
import java.nio.file.attribute.FileTime; //导入方法依赖的package包/类
public FileTime getLastModifiedTime() {
return FileTime.fromMillis(lastModifiedTime);
}
开发者ID:GoogleCloudPlatform,项目名称:minikube-build-tools-for-java,代码行数:4,代码来源:CacheMetadataLayerPropertiesObjectTemplate.java
示例8: testFilter_bySourceFiles
import java.nio.file.attribute.FileTime; //导入方法依赖的package包/类
@Test
public void testFilter_bySourceFiles()
throws LayerPropertyNotFoundException, DuplicateLayerException,
CacheMetadataCorruptedException {
List<CachedLayer> mockLayers =
Stream.generate(CacheMetadataTest::mockCachedLayer).limit(5).collect(Collectors.toList());
LayerMetadata fakeExpectedSourceFilesClassesLayerMetadata =
new LayerMetadata(
Arrays.asList("some/source/file", "some/source/directory"), FileTime.fromMillis(0));
LayerMetadata fakeExpectedSourceFilesResourcesLayerMetadata =
new LayerMetadata(
Arrays.asList("some/source/file", "some/source/directory"), FileTime.fromMillis(0));
LayerMetadata fakeOtherSourceFilesLayerMetadata =
new LayerMetadata(
Collections.singletonList("not/the/same/source/file"), FileTime.fromMillis(0));
List<CachedLayerWithMetadata> cachedLayers =
Arrays.asList(
new CachedLayerWithMetadata(
mockLayers.get(0), CachedLayerType.CLASSES, fakeOtherSourceFilesLayerMetadata),
new CachedLayerWithMetadata(
mockLayers.get(1),
CachedLayerType.RESOURCES,
fakeExpectedSourceFilesResourcesLayerMetadata),
new CachedLayerWithMetadata(
mockLayers.get(2), CachedLayerType.CLASSES, fakeOtherSourceFilesLayerMetadata),
new CachedLayerWithMetadata(
mockLayers.get(3),
CachedLayerType.CLASSES,
fakeExpectedSourceFilesClassesLayerMetadata),
new CachedLayerWithMetadata(
mockLayers.get(4),
CachedLayerType.RESOURCES,
fakeExpectedSourceFilesResourcesLayerMetadata));
CacheMetadata cacheMetadata = new CacheMetadata();
for (CachedLayerWithMetadata cachedLayer : cachedLayers) {
cacheMetadata.addLayer(cachedLayer);
}
ImageLayers<CachedLayerWithMetadata> filteredLayers =
cacheMetadata
.filterLayers()
.bySourceFiles(
new HashSet<>(
Arrays.asList(
Paths.get("some/source/file"), Paths.get("some/source/directory"))))
.filter();
Assert.assertEquals(3, filteredLayers.size());
Assert.assertEquals(
fakeExpectedSourceFilesResourcesLayerMetadata, filteredLayers.get(0).getMetadata());
Assert.assertEquals(
fakeExpectedSourceFilesClassesLayerMetadata, filteredLayers.get(1).getMetadata());
Assert.assertEquals(
fakeExpectedSourceFilesResourcesLayerMetadata, filteredLayers.get(2).getMetadata());
}
示例9: toFileTime
import java.nio.file.attribute.FileTime; //导入方法依赖的package包/类
private static @Nullable FileTime toFileTime(long time) {
return UNKNOWN == time ? null : FileTime.fromMillis(time);
}
示例10: File
import java.nio.file.attribute.FileTime; //导入方法依赖的package包/类
public File(String name) {
this.name = name;
lastModified = FileTime.fromMillis(0);
}
示例11: setFileCreationDate
import java.nio.file.attribute.FileTime; //导入方法依赖的package包/类
private void setFileCreationDate(File f, long time) throws IOException {
BasicFileAttributeView attributes = Files.getFileAttributeView(f.toPath(), BasicFileAttributeView.class);
FileTime creationTime = FileTime.fromMillis(time);
attributes.setTimes(creationTime, creationTime, creationTime);
}
示例12: creationTime
import java.nio.file.attribute.FileTime; //导入方法依赖的package包/类
@Override
public FileTime creationTime() {
if (e.ctime != -1)
return FileTime.fromMillis(e.ctime);
return null;
}
示例13: lastAccessTime
import java.nio.file.attribute.FileTime; //导入方法依赖的package包/类
@Override
public FileTime lastAccessTime() {
if (e.atime != -1)
return FileTime.fromMillis(e.atime);
return null;
}
示例14: lastModifiedTime
import java.nio.file.attribute.FileTime; //导入方法依赖的package包/类
@Override
public FileTime lastModifiedTime() {
return FileTime.fromMillis(e.mtime);
}
示例15: setLastModified
import java.nio.file.attribute.FileTime; //导入方法依赖的package包/类
private static void setLastModified(String fileName, long newTime) throws IOException {
Path path = Paths.get(fileName);
FileTime fileTime = FileTime.fromMillis(newTime);
Files.setLastModifiedTime(path, fileTime);
}