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


Java FileTime.fromMillis方法代码示例

本文整理汇总了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);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:16,代码来源:SetLastModifiedTime.java

示例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");
  }
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:21,代码来源:RawLocalFileSystem.java

示例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;
}
 
开发者ID:sormuras,项目名称:bach,代码行数:34,代码来源:Bach-06.java

示例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();
}
 
开发者ID:christian-schlichtherle,项目名称:truevfs,代码行数:16,代码来源:FileController.java

示例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) {
    }
}
 
开发者ID:limagiran,项目名称:hearthstone,代码行数:14,代码来源:Dir.java

示例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);
}
 
开发者ID:RetroFloppy,项目名称:transformenator,代码行数:7,代码来源:ExtractIBM8Files.java

示例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());
}
 
开发者ID:GoogleCloudPlatform,项目名称:minikube-build-tools-for-java,代码行数:59,代码来源:CacheMetadataTest.java

示例9: toFileTime

import java.nio.file.attribute.FileTime; //导入方法依赖的package包/类
private static @Nullable FileTime toFileTime(long time) {
    return UNKNOWN == time ? null : FileTime.fromMillis(time);
}
 
开发者ID:christian-schlichtherle,项目名称:truevfs,代码行数:4,代码来源:FileOutputSocket.java

示例10: File

import java.nio.file.attribute.FileTime; //导入方法依赖的package包/类
public File(String name) {
    this.name = name;
    lastModified = FileTime.fromMillis(0);
}
 
开发者ID:gaganis,项目名称:odoxSync,代码行数:5,代码来源:File.java

示例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);
}
 
开发者ID:instalint-org,项目名称:instalint,代码行数:6,代码来源:GlobalTempFolderProviderTest.java

示例12: creationTime

import java.nio.file.attribute.FileTime; //导入方法依赖的package包/类
@Override
public FileTime creationTime() {
    if (e.ctime != -1)
        return FileTime.fromMillis(e.ctime);
    return null;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:7,代码来源:ZipFileAttributes.java

示例13: lastAccessTime

import java.nio.file.attribute.FileTime; //导入方法依赖的package包/类
@Override
public FileTime lastAccessTime() {
    if (e.atime != -1)
        return FileTime.fromMillis(e.atime);
    return null;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:7,代码来源:ZipFileAttributes.java

示例14: lastModifiedTime

import java.nio.file.attribute.FileTime; //导入方法依赖的package包/类
@Override
public FileTime lastModifiedTime() {
    return FileTime.fromMillis(e.mtime);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:5,代码来源:ZipFileAttributes.java

示例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);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:6,代码来源:LingeredApp.java


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