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);
}
}
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;
}
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);
}
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();
}
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");
}
Aggregations