Search in sources :

Example 6 with FileTime

use of java.nio.file.attribute.FileTime in project ratpack by ratpack.

the class FileBackedReloadInformant method probe.

private boolean probe() {
    try {
        FileTime nowLastModified = Files.getLastModifiedTime(file);
        FileTime previousLastModified = lastModifiedHolder.getAndSet(nowLastModified);
        return !nowLastModified.equals(previousLastModified);
    } catch (Exception e) {
        throw uncheck(e);
    }
}
Also used : FileTime(java.nio.file.attribute.FileTime)

Example 7 with FileTime

use of java.nio.file.attribute.FileTime in project camel by apache.

the class BOMResolver method canUseCache.

private boolean canUseCache() throws IOException {
    if (CACHE_FILE.exists()) {
        BasicFileAttributes attr = Files.readAttributes(CACHE_FILE.toPath(), BasicFileAttributes.class);
        FileTime fileTime = attr != null ? attr.creationTime() : null;
        Long time = fileTime != null ? fileTime.toMillis() : null;
        // Update the cache every day
        return time != null && time.compareTo(System.currentTimeMillis() - 1000 * 60 * 60 * 24) > 0;
    }
    return false;
}
Also used : FileTime(java.nio.file.attribute.FileTime) BasicFileAttributes(java.nio.file.attribute.BasicFileAttributes)

Example 8 with FileTime

use of java.nio.file.attribute.FileTime in project jimfs by google.

the class BasicAttributeProviderTest method testSetOnCreate.

@Test
public void testSetOnCreate() {
    FileTime time = FileTime.fromMillis(0L);
    assertSetFailsOnCreate("creationTime", time);
    assertSetFailsOnCreate("lastModifiedTime", time);
    assertSetFailsOnCreate("lastAccessTime", time);
}
Also used : FileTime(java.nio.file.attribute.FileTime) Test(org.junit.Test)

Example 9 with FileTime

use of java.nio.file.attribute.FileTime in project jimfs by google.

the class PathURLConnection method connect.

@Override
public void connect() throws IOException {
    if (stream != null) {
        return;
    }
    Path path = Paths.get(toUri(url));
    long length;
    if (Files.isDirectory(path)) {
        // Match File URL behavior for directories by having the stream contain the filenames in
        // the directory separated by newlines.
        StringBuilder builder = new StringBuilder();
        try (DirectoryStream<Path> files = Files.newDirectoryStream(path)) {
            for (Path file : files) {
                builder.append(file.getFileName()).append('\n');
            }
        }
        byte[] bytes = builder.toString().getBytes(UTF_8);
        stream = new ByteArrayInputStream(bytes);
        length = bytes.length;
    } else {
        stream = Files.newInputStream(path);
        length = Files.size(path);
    }
    FileTime lastModified = Files.getLastModifiedTime(path);
    String contentType = MoreObjects.firstNonNull(Files.probeContentType(path), DEFAULT_CONTENT_TYPE);
    ImmutableListMultimap.Builder<String, String> builder = ImmutableListMultimap.builder();
    builder.put("content-length", "" + length);
    builder.put("content-type", contentType);
    if (lastModified != null) {
        DateFormat format = new SimpleDateFormat(HTTP_DATE_FORMAT, Locale.US);
        format.setTimeZone(TimeZone.getTimeZone("GMT"));
        builder.put("last-modified", format.format(new Date(lastModified.toMillis())));
    }
    headers = builder.build();
}
Also used : Path(java.nio.file.Path) FileTime(java.nio.file.attribute.FileTime) Date(java.util.Date) ByteArrayInputStream(java.io.ByteArrayInputStream) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) ImmutableListMultimap(com.google.common.collect.ImmutableListMultimap) SimpleDateFormat(java.text.SimpleDateFormat)

Example 10 with FileTime

use of java.nio.file.attribute.FileTime in project jdk8u_jdk by JetBrains.

the class Basic method eq.

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");
}
Also used : FileTime(java.nio.file.attribute.FileTime)

Aggregations

FileTime (java.nio.file.attribute.FileTime)40 Path (java.nio.file.Path)11 File (java.io.File)7 Test (org.junit.Test)7 Test (org.testng.annotations.Test)7 BasicFileAttributes (java.nio.file.attribute.BasicFileAttributes)6 IOException (java.io.IOException)5 SegmentMetadataImpl (com.linkedin.pinot.core.segment.index.SegmentMetadataImpl)4 BasicFileAttributeView (java.nio.file.attribute.BasicFileAttributeView)3 ProcessResult (com.facebook.buck.testutil.integration.ProjectWorkspace.ProcessResult)2 IndexSegment (com.linkedin.pinot.core.indexsegment.IndexSegment)2 SegmentV1V2ToV3FormatConverter (com.linkedin.pinot.core.segment.index.converter.SegmentV1V2ToV3FormatConverter)2 FileNotFoundException (java.io.FileNotFoundException)2 FileAlreadyExistsException (java.nio.file.FileAlreadyExistsException)2 NoSuchFileException (java.nio.file.NoSuchFileException)2 Date (java.util.Date)2 BuildTarget (com.facebook.buck.model.BuildTarget)1 ProjectWorkspace (com.facebook.buck.testutil.integration.ProjectWorkspace)1 ImmutableListMultimap (com.google.common.collect.ImmutableListMultimap)1 ImmutableMap (com.google.common.collect.ImmutableMap)1