Java Code Examples for java.nio.file.attribute.FileTime#to()

The following examples show how to use java.nio.file.attribute.FileTime#to() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Item.java    From cloudsync with GNU General Public License v2.0 6 votes vote down vote up
public static Item fromLocalData(String name, ItemType type, Long filesize, FileTime creationtime, FileTime modifytime, FileTime accesstime,
		Map<String, String[]> map)
{
	Item item = new Item();
	item.name = name;
	item.type = type;
	item.filesize = filesize;
	item.creationtime = creationtime.to(TimeUnit.SECONDS);
	item.modifytime = modifytime.to(TimeUnit.SECONDS);
	item.accesstime = accesstime.to(TimeUnit.SECONDS);
	item.attributes = convertToAttributes(map);
	if (item.type.equals(ItemType.FOLDER))
	{
		item.children = new HashMap<>();
	}
	return item;
}
 
Example 2
Source File: Basic.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
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");
        }
    }
}
 
Example 3
Source File: Basic.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
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");
        }
    }
}
 
Example 4
Source File: TestExtraTime.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
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!");
        }
    }
}
 
Example 5
Source File: TestExtraTime.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
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!");
        }
    }
}
 
Example 6
Source File: Basic.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
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");
        }
    }
}
 
Example 7
Source File: Basic.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
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");
        }
    }
}
 
Example 8
Source File: TestExtraTime.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
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!");
        }
    }
}
 
Example 9
Source File: ResourceManager.java    From jmonkeybuilder with Apache License 2.0 5 votes vote down vote up
@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 realFile = getRealFile(Paths.get(key.getName()));
    if (realFile == null || !Files.exists(realFile)) {
        return;
    }

    try {

        final long timestamp = reference.getLong();

        final FileTime lastModifiedTime = Files.getLastModifiedTime(realFile);
        if (lastModifiedTime.to(TimeUnit.MILLISECONDS) <= timestamp) {
            return;
        }

        final AssetManager assetManager = EditorUtil.getAssetManager();
        assetManager.deleteFromCache(key);

    } catch (final IOException e) {
        LOGGER.warning(e);
    }
}
 
Example 10
Source File: ZipUtils.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Converts FileTime to "standard Unix time".
 */
public static final long fileTimeToUnixTime(FileTime ftime) {
    return ftime.to(TimeUnit.SECONDS);
}
 
Example 11
Source File: ZipUtils.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Converts FileTime to "standard Unix time".
 */
public static final long fileTimeToUnixTime(FileTime ftime) {
    return ftime.to(TimeUnit.SECONDS);
}
 
Example 12
Source File: ZipUtils.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Converts FileTime to Windows time.
 */
public static final long fileTimeToWinTime(FileTime ftime) {
    return (ftime.to(TimeUnit.MICROSECONDS) - WINDOWS_EPOCH_IN_MICROSECONDS) * 10;
}
 
Example 13
Source File: ZipUtils.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Converts FileTime to "standard Unix time".
 */
public static final long fileTimeToUnixTime(FileTime ftime) {
    return ftime.to(TimeUnit.SECONDS);
}
 
Example 14
Source File: ZipUtils.java    From Bytecoder with Apache License 2.0 4 votes vote down vote up
/**
 * Converts FileTime to "standard Unix time".
 */
public static final long fileTimeToUnixTime(FileTime ftime) {
    return ftime.to(TimeUnit.SECONDS);
}
 
Example 15
Source File: ZipUtils.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Converts FileTime to "standard Unix time".
 */
public static final long fileTimeToUnixTime(FileTime ftime) {
    return ftime.to(TimeUnit.SECONDS);
}
 
Example 16
Source File: ZipUtils.java    From j2objc with Apache License 2.0 4 votes vote down vote up
/**
 * Converts FileTime to Windows time.
 */
public static final long fileTimeToWinTime(FileTime ftime) {
  return (ftime.to(TimeUnit.MICROSECONDS) - WINDOWS_EPOCH_IN_MICROSECONDS) * 10;
}
 
Example 17
Source File: ZipUtils.java    From jdk1.8-source-analysis with Apache License 2.0 4 votes vote down vote up
/**
 * Converts FileTime to "standard Unix time".
 */
public static final long fileTimeToUnixTime(FileTime ftime) {
    return ftime.to(TimeUnit.SECONDS);
}
 
Example 18
Source File: ZipUtils.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Converts FileTime to "standard Unix time".
 */
public static final long fileTimeToUnixTime(FileTime ftime) {
    return ftime.to(TimeUnit.SECONDS);
}
 
Example 19
Source File: ZipUtils.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Converts FileTime to "standard Unix time".
 */
public static final long fileTimeToUnixTime(FileTime ftime) {
    return ftime.to(TimeUnit.SECONDS);
}
 
Example 20
Source File: ZipEntry.java    From openjdk-8-source with GNU General Public License v2.0 3 votes vote down vote up
/**
 * 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;
}