use of java.nio.file.attribute.FileTime in project jdk8u_jdk by JetBrains.
the class Basic method neq.
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");
}
use of java.nio.file.attribute.FileTime in project jdk8u_jdk by JetBrains.
the class TestExtraTime method main.
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();
testTagOnlyHandling();
testTimeConversions();
}
use of java.nio.file.attribute.FileTime in project graylog2-server by Graylog2.
the class WebInterfaceAssetsResource method getResponse.
private Response getResponse(Request request, String filename, URL resourceUrl, boolean fromPlugin) throws IOException, URISyntaxException {
final Date lastModified;
final InputStream stream;
final HashCode hashCode;
switch(resourceUrl.getProtocol()) {
case "file":
final File file = new File(resourceUrl.toURI());
lastModified = new Date(file.lastModified());
stream = new FileInputStream(file);
hashCode = Files.hash(file, Hashing.sha256());
break;
case "jar":
final URI uri = resourceUrl.toURI();
final FileSystem fileSystem = fileSystemCache.getUnchecked(uri);
final java.nio.file.Path path = fileSystem.getPath(pluginPrefixFilename(fromPlugin, filename));
final FileTime lastModifiedTime = java.nio.file.Files.getLastModifiedTime(path);
lastModified = new Date(lastModifiedTime.toMillis());
stream = resourceUrl.openStream();
hashCode = Resources.asByteSource(resourceUrl).hash(Hashing.sha256());
break;
default:
throw new IllegalArgumentException("Not a JAR or local file: " + resourceUrl);
}
final EntityTag entityTag = new EntityTag(hashCode.toString());
final Response.ResponseBuilder response = request.evaluatePreconditions(lastModified, entityTag);
if (response != null) {
return response.build();
}
final String contentType = firstNonNull(mimeTypes.getContentType(filename), MediaType.APPLICATION_OCTET_STREAM);
final CacheControl cacheControl = new CacheControl();
cacheControl.setMaxAge((int) TimeUnit.DAYS.toSeconds(365));
cacheControl.setNoCache(false);
cacheControl.setPrivate(false);
return Response.ok(stream).header(HttpHeaders.CONTENT_TYPE, contentType).tag(entityTag).cacheControl(cacheControl).lastModified(lastModified).build();
}
use of java.nio.file.attribute.FileTime in project lucene-solr by apache.
the class SimpleFSLockFactory method obtainFSLock.
@Override
protected Lock obtainFSLock(FSDirectory dir, String lockName) throws IOException {
Path lockDir = dir.getDirectory();
// Ensure that lockDir exists and is a directory.
// note: this will fail if lockDir is a symlink
Files.createDirectories(lockDir);
Path lockFile = lockDir.resolve(lockName);
// create the file: this will fail if it already exists
try {
Files.createFile(lockFile);
} catch (FileAlreadyExistsException | AccessDeniedException e) {
// convert optional specific exception to our optional specific exception
throw new LockObtainFailedException("Lock held elsewhere: " + lockFile, e);
}
// used as a best-effort check, to see if the underlying file has changed
final FileTime creationTime = Files.readAttributes(lockFile, BasicFileAttributes.class).creationTime();
return new SimpleFSLock(lockFile, creationTime);
}
use of java.nio.file.attribute.FileTime in project sakuli by ConSol.
the class LogCleanUpResultServiceImplTest method testTriggerAction.
@Test
public void testTriggerAction() throws Exception {
Files.createDirectories(tempLog);
Path folder1 = Files.createDirectories(tempLog.resolve("folder1"));
Path today = Files.createFile(folder1.resolve("today.log"));
FileTime todayMinus15 = FileTime.from(Instant.now().minus(15, ChronoUnit.DAYS));
Path toOld1 = createFileWithDate(folder1.resolve("today-15.log"), todayMinus15);
Path toOld2 = createFileWithDate(tempLog.resolve("root-today-15.log"), todayMinus15);
FileTime todayMinus13 = FileTime.from(Instant.now().minus(13, ChronoUnit.DAYS));
Path notToOld = createFileWithDate(folder1.resolve("today-13.log"), todayMinus13);
Path notToOld2 = createFileWithDate(tempLog.resolve("today-13.log"), todayMinus13);
when(sakuliProperties.getLogFolder()).thenReturn(tempLog);
testling.triggerAction();
verify(testling, times(2)).cleanUpDirectory(any());
assertTrue(Files.exists(folder1));
assertTrue(Files.exists(today));
assertTrue(Files.exists(notToOld));
assertTrue(Files.exists(notToOld2));
assertFalse(Files.exists(toOld1));
assertFalse(Files.exists(toOld2));
}
Aggregations