本文整理汇总了Java中java.nio.file.attribute.FileTime.to方法的典型用法代码示例。如果您正苦于以下问题:Java FileTime.to方法的具体用法?Java FileTime.to怎么用?Java FileTime.to使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.nio.file.attribute.FileTime
的用法示例。
在下文中一共展示了FileTime.to方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: check
import java.nio.file.attribute.FileTime; //导入方法依赖的package包/类
static void check(FileTime mtime, FileTime atime, FileTime ctime,
ZipEntry ze, byte[] extra) {
/*
System.out.printf(" mtime [%tc]: [%tc]/[%tc]%n",
mtime.to(TimeUnit.MILLISECONDS),
ze.getTime(),
ze.getLastModifiedTime().to(TimeUnit.MILLISECONDS));
*/
if (mtime.to(TimeUnit.SECONDS) !=
ze.getLastModifiedTime().to(TimeUnit.SECONDS))
throw new RuntimeException("Timestamp: storing mtime failed!");
if (atime != null &&
atime.to(TimeUnit.SECONDS) !=
ze.getLastAccessTime().to(TimeUnit.SECONDS))
throw new RuntimeException("Timestamp: storing atime failed!");
if (ctime != null &&
ctime.to(TimeUnit.SECONDS) !=
ze.getCreationTime().to(TimeUnit.SECONDS))
throw new RuntimeException("Timestamp: storing ctime failed!");
if (extra != null) {
// if extra data exists, the current implementation put it at
// the end of the extra data array (implementation detail)
byte[] extra1 = ze.getExtra();
if (extra1 == null || extra1.length < extra.length ||
!Arrays.equals(Arrays.copyOfRange(extra1,
extra1.length - extra.length,
extra1.length),
extra)) {
throw new RuntimeException("Timestamp: storing extra field failed!");
}
}
}
示例2: 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");
}
}
}
示例3: assetRequested
import java.nio.file.attribute.FileTime; //导入方法依赖的package包/类
@Override
@FromAnyThread
public synchronized void assetRequested(@NotNull final AssetKey key) {
if (key.getCacheType() == null) {
return;
}
final String extension = key.getExtension();
if (StringUtils.isEmpty(extension)) return;
final ObjectDictionary<String, Reference> table = getAssetCacheTable();
final Reference reference = table.get(key.getName());
if (reference == null) return;
final Path assetFile = getRealFile(Paths.get(key.getName()));
if (assetFile == null || !Files.exists(assetFile)) return;
try {
final long timestamp = reference.getLong();
final FileTime lastModifiedTime = Files.getLastModifiedTime(assetFile);
if (lastModifiedTime.to(TimeUnit.MILLISECONDS) <= timestamp) return;
final Editor editor = Editor.getInstance();
final AssetManager assetManager = editor.getAssetManager();
assetManager.deleteFromCache(key);
} catch (final IOException e) {
LOGGER.warning(e);
}
}
示例4: fileTimeToWinTime
import java.nio.file.attribute.FileTime; //导入方法依赖的package包/类
/**
* Converts FileTime to Windows time.
*/
public static final long fileTimeToWinTime(FileTime ftime) {
return (ftime.to(TimeUnit.MICROSECONDS) - WINDOWS_EPOCH_IN_MICROSECONDS) * 10;
}
示例5: fileTimeToUnixTime
import java.nio.file.attribute.FileTime; //导入方法依赖的package包/类
/**
* Converts FileTime to "standard Unix time".
*/
public static final long fileTimeToUnixTime(FileTime ftime) {
return ftime.to(TimeUnit.SECONDS);
}
示例6: setLastModifiedTime
import java.nio.file.attribute.FileTime; //导入方法依赖的package包/类
/**
* Sets the last modification time of the entry.
*
* <p> When output to a ZIP file or ZIP file formatted output stream
* the last modification time set by this method will be stored into
* zip file entry's {@code date and time fields} in {@code standard
* MS-DOS date and time format}), and the extended timestamp fields
* in {@code optional extra data} in UTC time.
*
* @param time
* The last modification time of the entry
* @return This zip entry
*
* @throws NullPointerException if the {@code time} is null
*
* @see #getLastModifiedTime()
* @since 1.8
*/
public ZipEntry setLastModifiedTime(FileTime time) {
Objects.requireNonNull(name, "time");
this.mtime = time;
this.time = time.to(TimeUnit.MILLISECONDS);
return this;
}
示例7: setLastModifiedTime
import java.nio.file.attribute.FileTime; //导入方法依赖的package包/类
/**
* Sets the last modification time of the entry.
*
* <p> When output to a ZIP file or ZIP file formatted output stream
* the last modification time set by this method will be stored into
* zip file entry's {@code date and time fields} in {@code standard
* MS-DOS date and time format}), and the extended timestamp fields
* in {@code optional extra data} in UTC time.
*
* @param time
* The last modification time of the entry
* @return This zip entry
*
* @throws NullPointerException if the {@code time} is null
*
* @see #getLastModifiedTime()
* @since 1.8
*/
public ZipEntry setLastModifiedTime(FileTime time) {
Objects.requireNonNull(name, "time");
this.mtime = time;
this.time = time.to(TimeUnit.MILLISECONDS);
this.dostime = -1;
return this;
}