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


Java FileTime.from方法代码示例

本文整理汇总了Java中java.nio.file.attribute.FileTime.from方法的典型用法代码示例。如果您正苦于以下问题:Java FileTime.from方法的具体用法?Java FileTime.from怎么用?Java FileTime.from使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.nio.file.attribute.FileTime的用法示例。


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

示例1: flush

import java.nio.file.attribute.FileTime; //导入方法依赖的package包/类
public void flush() {
    if (!needsFlush) {
        return;
    }
    needsFlush = false;
    LOGGER.info("flushing bucket {}", bucketNumber);
    try {
        synchronized (this) {
            final FileChannel openChannel = getOpenChannel();
            if (openChannel.isOpen()) {
                openChannel.force(wantsTimestampUpdate);
                if (!wantsTimestampUpdate) {
                    Files.setLastModifiedTime(filePath, lastModifiedTime);
                } else {
                    lastModifiedTime = FileTime.from(Instant.now());
                }
                wantsTimestampUpdate = false;
            }
        }
    } catch (IOException e) {
        LOGGER.warn("unable to flush file of bucket {}", bucketNumber);
    }
}
 
开发者ID:MineboxOS,项目名称:minebox,代码行数:24,代码来源:SingleFileBucket.java

示例2: eq

import java.nio.file.attribute.FileTime; //导入方法依赖的package包/类
static void eq(long v1, TimeUnit u1, long v2, TimeUnit u2) {
    FileTime t1 = FileTime.from(v1, u1);
    FileTime t2 = FileTime.from(v2, u2);
    if (!t1.equals(t2))
        throw new RuntimeException("not equal");
    if (t1.hashCode() != t2.hashCode())
        throw new RuntimeException("hashCodes should be equal");
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:9,代码来源:Basic.java

示例3: testBasicFileAttributesToFileStat

import java.nio.file.attribute.FileTime; //导入方法依赖的package包/类
@Test
public void testBasicFileAttributesToFileStat() {
	Instant instant = Instant.ofEpochSecond(424242l, 42);
	FileTime ftime = FileTime.from(instant);
	BasicFileAttributes attr = Mockito.mock(BasicFileAttributes.class);
	Mockito.when(attr.isDirectory()).thenReturn(true);
	Mockito.when(attr.lastModifiedTime()).thenReturn(ftime);
	Mockito.when(attr.creationTime()).thenReturn(ftime);
	Mockito.when(attr.lastAccessTime()).thenReturn(ftime);
	Mockito.when(attr.size()).thenReturn(42l);

	FileAttributesUtil util = new FileAttributesUtil();
	FileStat stat = util.basicFileAttributesToFileStat(attr);

	Assertions.assertTrue((FileStat.S_IFDIR & stat.st_mode.intValue()) == FileStat.S_IFDIR);
	Assertions.assertEquals(424242l, stat.st_mtim.tv_sec.get());
	Assertions.assertEquals(42, stat.st_mtim.tv_nsec.intValue());
	Assertions.assertEquals(424242l, stat.st_ctim.tv_sec.get());
	Assertions.assertEquals(42, stat.st_ctim.tv_nsec.intValue());
	Assumptions.assumingThat(Platform.IS_MAC || Platform.IS_WINDOWS, () -> {
		Assertions.assertEquals(424242l, stat.st_birthtime.tv_sec.get());
		Assertions.assertEquals(42, stat.st_birthtime.tv_nsec.intValue());
	});
	Assertions.assertEquals(424242l, stat.st_atim.tv_sec.get());
	Assertions.assertEquals(42, stat.st_atim.tv_nsec.intValue());
	Assertions.assertEquals(42l, stat.st_size.longValue());
}
 
开发者ID:cryptomator,项目名称:fuse-nio-adapter,代码行数:28,代码来源:FileAttributesUtilTest.java

示例4: areSourceFilesModified

import java.nio.file.attribute.FileTime; //导入方法依赖的package包/类
/**
 * Checks all cached layers built from the source files to see if the source files have been
 * modified since the newest layer build.
 *
 * @param sourceFiles the source files to check
 * @return true if no cached layer exists that are up-to-date with the source files; false
 *     otherwise.
 */
public boolean areSourceFilesModified(Set<Path> sourceFiles)
    throws IOException, CacheMetadataCorruptedException {
  // Grabs all the layers that have matching source files.
  ImageLayers<CachedLayerWithMetadata> cachedLayersWithSourceFiles =
      cache.getMetadata().filterLayers().bySourceFiles(sourceFiles).filter();
  if (cachedLayersWithSourceFiles.isEmpty()) {
    return true;
  }

  FileTime sourceFilesLastModifiedTime = FileTime.from(Instant.MIN);
  for (Path path : sourceFiles) {
    FileTime lastModifiedTime = getLastModifiedTime(path);
    if (lastModifiedTime.compareTo(sourceFilesLastModifiedTime) > 0) {
      sourceFilesLastModifiedTime = lastModifiedTime;
    }
  }

  // Checks if at least one of the matched layers is up-to-date.
  for (CachedLayerWithMetadata cachedLayer : cachedLayersWithSourceFiles) {
    if (sourceFilesLastModifiedTime.compareTo(cachedLayer.getMetadata().getLastModifiedTime())
        <= 0) {
      // This layer is an up-to-date layer.
      return false;
    }
  }

  return true;
}
 
开发者ID:GoogleCloudPlatform,项目名称:minikube-build-tools-for-java,代码行数:37,代码来源:CacheChecker.java

示例5: ConsistentJarEntry

import java.nio.file.attribute.FileTime; //导入方法依赖的package包/类
public ConsistentJarEntry( String name, long lastModified, boolean consistentDates )
{
    this( name, consistentDates );
    if ( !consistentDates )
    {
        FileTime fileTime = FileTime.from( Instant.ofEpochMilli( lastModified ) );
        this.setLastModifiedTime( fileTime );
    }
}
 
开发者ID:javiersigler,项目名称:apache-maven-shade-plugin,代码行数:10,代码来源:ConsistentJarEntry.java

示例6: maakFileTime

import java.nio.file.attribute.FileTime; //导入方法依赖的package包/类
private FileTime maakFileTime(final String time) throws MojoExecutionException {
    final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMddHHmm");
    try {
        return FileTime.from(LocalDateTime.from(formatter.parse(time)).toInstant(ZoneOffset.UTC));
    } catch (DateTimeParseException e) {
        throw new MojoExecutionException(e.getMessage(), e);
    }
}
 
开发者ID:MinBZK,项目名称:OperatieBRP,代码行数:9,代码来源:TimestampMojo.java

示例7: to

import java.nio.file.attribute.FileTime; //导入方法依赖的package包/类
static void to(long v, TimeUnit unit) {
    FileTime t = FileTime.from(v, unit);
    for (TimeUnit u: TimeUnit.values()) {
        long result = t.to(u);
        long expected = u.convert(v, unit);
        if (result != expected) {
            throw new RuntimeException("unexpected result");
        }
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:11,代码来源:Basic.java

示例8: main

import java.nio.file.attribute.FileTime; //导入方法依赖的package包/类
public static void main(String[] args) throws Throwable{

        File src = new File(System.getProperty("test.src", "."), "TestExtraTime.java");
        if (src.exists()) {
            long time = src.lastModified();
            FileTime mtime = FileTime.from(time, TimeUnit.MILLISECONDS);
            FileTime atime = FileTime.from(time + 300000, TimeUnit.MILLISECONDS);
            FileTime ctime = FileTime.from(time - 300000, TimeUnit.MILLISECONDS);
            TimeZone tz = TimeZone.getTimeZone("Asia/Shanghai");

            for (byte[] extra : new byte[][] { null, new byte[] {1, 2, 3}}) {
                test(mtime, null, null, null, extra);
                // ms-dos 1980 epoch problem
                test(FileTime.from(10, TimeUnit.MILLISECONDS), null, null, null, extra);
                // non-default tz
                test(mtime, null, null, tz, extra);

                test(mtime, atime, null, null, extra);
                test(mtime, null, ctime, null, extra);
                test(mtime, atime, ctime, null, extra);

                test(mtime, atime, null, tz, extra);
                test(mtime, null, ctime, tz, extra);
                test(mtime, atime, ctime, tz, extra);
            }
        }

        testNullHandling();
        testTagOnlyHandling();
        testTimeConversions();
    }
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:32,代码来源:TestExtraTime.java

示例9: neq

import java.nio.file.attribute.FileTime; //导入方法依赖的package包/类
static void neq(Instant ins, long v2, TimeUnit u2) {
    FileTime t1 = FileTime.from(ins);
    FileTime t2 = FileTime.from(v2, u2);
    if (t1.equals(t2))
        throw new RuntimeException("should not be equal");
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:7,代码来源:Basic.java

示例10: winTimeToFileTime

import java.nio.file.attribute.FileTime; //导入方法依赖的package包/类
/**
 * Converts Windows time (in microseconds, UTC/GMT) time to FileTime.
 */
public static final FileTime winTimeToFileTime(long wtime) {
    return FileTime.from(wtime / 10 + WINDOWS_EPOCH_IN_MICROSECONDS,
                         TimeUnit.MICROSECONDS);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:8,代码来源:ZipUtils.java

示例11: lastModifiedTime

import java.nio.file.attribute.FileTime; //导入方法依赖的package包/类
@Override
public FileTime lastModifiedTime() {
    return FileTime.from(this.modified, TimeUnit.MILLISECONDS);
}
 
开发者ID:pontiussoftware,项目名称:smb-nio,代码行数:5,代码来源:SMBFileAttributes.java

示例12: unixTimeToFileTime

import java.nio.file.attribute.FileTime; //导入方法依赖的package包/类
/**
 * Converts "standard Unix time"(in seconds, UTC/GMT) to FileTime
 */
public static final FileTime unixTimeToFileTime(long utime) {
    return FileTime.from(utime, TimeUnit.SECONDS);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:7,代码来源:ZipUtils.java

示例13: getLastModifiedTime

import java.nio.file.attribute.FileTime; //导入方法依赖的package包/类
/**
 * Returns the last modification time of the entry.
 *
 * <p> If the entry is read from a ZIP file or ZIP file formatted
 * input stream, this is the last modification time from the zip
 * file entry's {@code optional extra data} if the extended timestamp
 * fields are present. Otherwise the last modification time is read
 * from the entry's {@code date and time fields}, the {@link
 * java.util.TimeZone#getDefault() default TimeZone} is used to convert
 * the standard MS-DOS formatted date and time to the epoch time.
 *
 * @return The last modification time of the entry, null if not specified
 *
 * @see #setLastModifiedTime(FileTime)
 * @since 1.8
 */
public FileTime getLastModifiedTime() {
    if (mtime != null)
        return mtime;
    long time = getTimeImpl();
    if (time == -1)
        return null;
    return FileTime.from(time, TimeUnit.MILLISECONDS);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:25,代码来源:ZipEntry.java

示例14: getLastModifiedTime

import java.nio.file.attribute.FileTime; //导入方法依赖的package包/类
/**
 * Returns the last modification time of the entry.
 *
 * <p> If the entry is read from a ZIP file or ZIP file formatted
 * input stream, this is the last modification time from the zip
 * file entry's {@code optional extra data} if the extended timestamp
 * fields are present. Otherwise the last modification time is read
 * from the entry's {@code date and time fields}, the {@link
 * java.util.TimeZone#getDefault() default TimeZone} is used to convert
 * the standard MS-DOS formatted date and time to the epoch time.
 *
 * @return The last modification time of the entry, null if not specified
 *
 * @see #setLastModifiedTime(FileTime)
 * @since 1.8
 */
public FileTime getLastModifiedTime() {
    if (mtime != null)
        return mtime;
    if (xdostime == -1)
        return null;
    return FileTime.from(getTime(), TimeUnit.MILLISECONDS);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:24,代码来源:ZipEntry.java


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