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

The following examples show how to use java.nio.file.attribute.FileTime#from() . 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: Basic.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
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");
}
 
Example 2
Source File: Basic.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
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");
}
 
Example 3
Source File: TestExtraTime.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
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();
        testTimeConversions();
    }
 
Example 4
Source File: LocalFileFilter.java    From LiquidDonkey with MIT License 5 votes vote down vote up
int testLastModified(Path local, ICloud.MBSFile remote) throws IOException {
    FileTime localTimestamp = Files.getLastModifiedTime(local);
    FileTime remoteTimestamp = FileTime.from(remote.getAttributes().getLastModified(), TimeUnit.SECONDS);
    int comparision = localTimestamp.compareTo(remoteTimestamp);

    logger.debug("-- testLastModified() < comparision: {} local: {} remote: {} file: {}",
            comparision, localTimestamp, remoteTimestamp, remote.getRelativePath());
    return comparision;
}
 
Example 5
Source File: HadoopBasicFileAttributes.java    From jsr203-hadoop with Apache License 2.0 4 votes vote down vote up
@Override
public FileTime creationTime() {
  return FileTime.from(this.fileStatus.getModificationTime(),
      TimeUnit.MILLISECONDS);
}
 
Example 6
Source File: ZipUtils.java    From JDKSourceCode1.8 with MIT License 4 votes vote down vote up
/**
 * 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);
}
 
Example 7
Source File: ZipUtils.java    From j2objc with Apache License 2.0 4 votes vote down vote up
/**
 * Converts "standard Unix time"(in seconds, UTC/GMT) to FileTime
 */
public static final FileTime unixTimeToFileTime(long utime) {
  return FileTime.from(utime, TimeUnit.SECONDS);
}
 
Example 8
Source File: Basic.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
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");
}
 
Example 9
Source File: ZipUtils.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Converts "standard Unix time"(in seconds, UTC/GMT) to FileTime
 */
public static final FileTime unixTimeToFileTime(long utime) {
    return FileTime.from(utime, TimeUnit.SECONDS);
}
 
Example 10
Source File: ZipUtils.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Converts "standard Unix time"(in seconds, UTC/GMT) to FileTime
 */
public static final FileTime unixTimeToFileTime(long utime) {
    return FileTime.from(utime, TimeUnit.SECONDS);
}
 
Example 11
Source File: Item.java    From cloudsync with GNU General Public License v2.0 4 votes vote down vote up
public FileTime getModifyTime()
{

	return FileTime.from(modifytime, TimeUnit.SECONDS);
}
 
Example 12
Source File: ZipUtils.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Converts "standard Unix time"(in seconds, UTC/GMT) to FileTime
 */
public static final FileTime unixTimeToFileTime(long utime) {
    return FileTime.from(utime, TimeUnit.SECONDS);
}
 
Example 13
Source File: Basic.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
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");
}
 
Example 14
Source File: FileTimestamp.java    From InflatableDonkey with MIT License 4 votes vote down vote up
public static boolean set(Path path, long timestamp) throws UncheckedIOException {
    FileTime fileTime = FileTime.from(timestamp, TimeUnit.SECONDS);
    return FileTimestamp.set(path, fileTime);
}
 
Example 15
Source File: ZipEntry.java    From Java8CN with Apache License 2.0 3 votes vote down vote up
/**
 * 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);
}
 
Example 16
Source File: ZipEntry.java    From jdk1.8-source-analysis with Apache License 2.0 3 votes vote down vote up
/**
 * Sets the last modification time of the entry.
 *
 * <p> If the entry is output to a ZIP file or ZIP file formatted
 * output stream the last modification time set by this method will
 * be stored into the {@code date and time fields} of the zip file
 * entry and encoded in standard {@code MS-DOS date and time format}.
 * The {@link java.util.TimeZone#getDefault() default TimeZone} is
 * used to convert the epoch time to the MS-DOS data and time.
 *
 * @param  time
 *         The last modification time of the entry in milliseconds
 *         since the epoch
 *
 * @see #getTime()
 * @see #getLastModifiedTime()
 */
public void setTime(long time) {
    this.xdostime = javaToExtendedDosTime(time);
    // Avoid setting the mtime field if time is in the valid
    // range for a DOS time
    if (xdostime != DOSTIME_BEFORE_1980 && time <= UPPER_DOSTIME_BOUND) {
        this.mtime = null;
    } else {
        this.mtime = FileTime.from(time, TimeUnit.MILLISECONDS);
    }
}
 
Example 17
Source File: ZipEntry.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 3 votes vote down vote up
/**
 * 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);
}
 
Example 18
Source File: ZipEntry.java    From Bytecoder with Apache License 2.0 3 votes vote down vote up
/**
 * Sets the last modification time of the entry.
 *
 * <p> If the entry is output to a ZIP file or ZIP file formatted
 * output stream the last modification time set by this method will
 * be stored into the {@code date and time fields} of the zip file
 * entry and encoded in standard {@code MS-DOS date and time format}.
 * The {@link java.util.TimeZone#getDefault() default TimeZone} is
 * used to convert the epoch time to the MS-DOS data and time.
 *
 * @param  time
 *         The last modification time of the entry in milliseconds
 *         since the epoch
 *
 * @see #getTime()
 * @see #getLastModifiedTime()
 */
public void setTime(long time) {
    this.xdostime = javaToExtendedDosTime(time);
    // Avoid setting the mtime field if time is in the valid
    // range for a DOS time
    if (xdostime != DOSTIME_BEFORE_1980 && time <= UPPER_DOSTIME_BOUND) {
        this.mtime = null;
    } else {
        this.mtime = FileTime.from(time, TimeUnit.MILLISECONDS);
    }
}
 
Example 19
Source File: ZipEntry.java    From jdk8u-jdk with GNU General Public License v2.0 3 votes vote down vote up
/**
 * 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);
}
 
Example 20
Source File: ZipEntry.java    From jdk1.8-source-analysis with Apache License 2.0 3 votes vote down vote up
/**
 * 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);
}