List of usage examples for java.io File lastModified
public long lastModified()
From source file:com.baomidou.mybatisplus.spring.MybatisMapperRefresh.java
public void run() { final GlobalConfiguration mybatisGlobalCache = GlobalConfiguration.GlobalConfig(configuration); /*//from w ww . j a v a 2 s .c o m * ? XML */ if (enabled) { beforeTime = SystemClock.now(); final MybatisMapperRefresh runnable = this; new Thread(new Runnable() { public void run() { if (fileSet == null) { fileSet = new HashSet<String>(); for (Resource mapperLocation : mapperLocations) { try { if (ResourceUtils.isJarURL(mapperLocation.getURL())) { String key = new UrlResource( ResourceUtils.extractJarFileURL(mapperLocation.getURL())).getFile() .getPath(); fileSet.add(key); if (jarMapper.get(key) != null) { jarMapper.get(key).add(mapperLocation); } else { List<Resource> resourcesList = new ArrayList<Resource>(); resourcesList.add(mapperLocation); jarMapper.put(key, resourcesList); } } else { fileSet.add(mapperLocation.getFile().getPath()); } } catch (IOException ioException) { ioException.printStackTrace(); } } } try { Thread.sleep(delaySeconds * 1000); } catch (InterruptedException interruptedException) { interruptedException.printStackTrace(); } while (true) { try { for (String filePath : fileSet) { File file = new File(filePath); if (file != null && file.isFile() && file.lastModified() > beforeTime) { mybatisGlobalCache.setRefresh(true); List<Resource> removeList = jarMapper.get(filePath); if (removeList != null && !removeList.isEmpty()) {// jarxmljarxml??jar?xml for (Resource resource : removeList) { runnable.refresh(resource); } } else { runnable.refresh(new FileSystemResource(file)); } } } if (mybatisGlobalCache.isRefresh()) { beforeTime = SystemClock.now(); } mybatisGlobalCache.setRefresh(true); } catch (Exception exception) { exception.printStackTrace(); } try { Thread.sleep(sleepSeconds * 1000); } catch (InterruptedException interruptedException) { interruptedException.printStackTrace(); } } } }, "mybatis-plus MapperRefresh").start(); } }
From source file:com.thinkbiganalytics.nifi.provenance.repo.ConfigurationProperties.java
private void load() { String location = null;/*from w w w.j a va2s. c o m*/ try { location = getConfigLocation(); properties.clear(); File file = getConfigFile(getConfigLocation()); properties.load(getConfigFileInputStream(location)); setValues(); if (file.exists()) { lastModified = file.lastModified(); } } catch (Exception e) { log.error("Unable to load properties for location: {} , {} ", location, e.getMessage(), e); } }
From source file:de.undercouch.gradle.tasks.download.OnlyIfNewerTest.java
/** * Tests if the plugin downloads a file and sets the timestamp correctly * @throws Exception if anything goes wrong *///from w w w. j ava 2s . c om @Test public void setFileLastModified() throws Exception { String lm = "Tue, 15 Nov 1994 12:45:26 GMT"; long expectedlmlong = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss z", Locale.ENGLISH).parse(lm) .getTime(); lastModified = lm; Download t = makeProjectAndTask(); t.src(makeSrc(LAST_MODIFIED)); File dst = folder.newFile(); dst.delete(); assertFalse(dst.exists()); t.dest(dst); t.onlyIfNewer(true); t.execute(); assertTrue(dst.exists()); long lmlong = dst.lastModified(); assertEquals(expectedlmlong, lmlong); String dstContents = FileUtils.readFileToString(dst); assertEquals("lm: " + lm, dstContents); }
From source file:com.eryansky.common.web.servlet.StaticContentServlet.java
/** * Content?.//from ww w . j a v a2s . c o m */ private ContentInfo createContentInfo(String contentPath) { ContentInfo contentInfo = new ContentInfo(); String realFilePath = getServletContext().getRealPath(contentPath); File file = new File(realFilePath); contentInfo.contentPath = contentPath; contentInfo.file = file; contentInfo.fileName = file.getName(); contentInfo.length = (int) file.length(); contentInfo.lastModified = file.lastModified(); contentInfo.etag = "W/\"" + contentInfo.lastModified + "\""; String mimeType = getServletContext().getMimeType(realFilePath); if (mimeType == null) { mimeType = "application/octet-stream"; } contentInfo.mimeType = mimeType; if (contentInfo.length >= GZIP_MINI_LENGTH && ArrayUtils.contains(GZIP_MIME_TYPES, contentInfo.mimeType)) { contentInfo.needGzip = true; } else { contentInfo.needGzip = false; } return contentInfo; }
From source file:de.undercouch.gradle.tasks.download.OnlyIfModifiedTest.java
/** * Tests if the plugin downloads a file and sets the timestamp correctly * @throws Exception if anything goes wrong */// www . j a v a 2 s . c o m @Test public void setFileLastModified() throws Exception { String lm = "Tue, 15 Nov 1994 12:45:26 GMT"; long expectedlmlong = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss z", Locale.ENGLISH).parse(lm) .getTime(); lastModified = lm; Download t = makeProjectAndTask(); t.src(makeSrc(LAST_MODIFIED)); File dst = folder.newFile(); dst.delete(); assertFalse(dst.exists()); t.dest(dst); t.onlyIfModified(true); t.execute(); assertTrue(dst.exists()); long lmlong = dst.lastModified(); assertEquals(expectedlmlong, lmlong); String dstContents = FileUtils.readFileToString(dst); assertEquals("lm: " + lm, dstContents); }
From source file:net.maritimecloud.mms.server.security.impl.ApacheConfSecurityHandler.java
/** * Check if the htpasswd file has been updated since last time it was read. * Reads in all users + encrypted password. * * @param htpasswdFile the password file *//* ww w . j ava 2 s . c o m*/ protected synchronized void checkReadHtpasswdFile(File htpasswdFile) throws IOException { if (!htpasswdFile.exists()) { throw new IOException("File does not exist: " + htpasswdFile); } // Only read it, if the file has been updated ... and the first time called. if (htpasswdFile.lastModified() != htpasswdFileLastModified) { userPasswords.clear(); try (Scanner scanner = new Scanner(new FileInputStream(htpasswdFile))) { while (scanner.hasNextLine()) { String line = scanner.nextLine().trim(); if (!line.isEmpty() && !line.startsWith("#")) { Matcher m = HTPASSWD_ENTRY.matcher(line); if (m.matches()) { userPasswords.put(m.group(1), m.group(2)); } } } } // Record time stamp htpasswdFileLastModified = htpasswdFile.lastModified(); } }
From source file:org.montanafoodhub.base.get.BuyerHub.java
protected HashMap<String, Buyer> readFromFile(Context context) { HashMap<String, Buyer> myBuyerMap = new HashMap<String, Buyer>(); try {/* ww w. j a va 2 s . co m*/ // getItem the time the file was last changed here File myFile = new File(context.getFilesDir() + "/" + fileName); SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss"); String lastRefreshTSStr = sdf.format(myFile.lastModified()); Log.w(HubInit.logTag, "Using file (" + fileName + ") last modified on : " + lastRefreshTSStr); lastRefreshTS = sdf.getCalendar(); // create products from the file here InputStream inputStream = context.openFileInput(fileName); if (inputStream != null) { parseCSV(myBuyerMap, inputStream); } inputStream.close(); } catch (FileNotFoundException e) { Log.e(HubInit.logTag, "File (" + fileName + ") not found: " + e.toString()); } catch (IOException e) { Log.e(HubInit.logTag, "Can not read file (" + fileName + ") : " + e.toString()); } Log.w(HubInit.logTag, "Number of buyers loaded: " + myBuyerMap.size()); return myBuyerMap; }
From source file:com.evidon.areweprivateyet.Crawler.java
private String getDriverProfile() { // C:\Users\ADMINI~1\AppData\Local\Temp\2\ /**// ww w .j a va 2 s .com * The temporary profile Selenium/Firefox creates should be * located at java.io.tmpdir. Please check if its the same * on other OSes since I've used winblows. */ File sysTemp = new File(System.getProperty("java.io.tmpdir")); File pd = null; long prevTime = 0; for (File t : sysTemp.listFiles()) { if (!t.isDirectory()) { continue; } if (t.toString().contains("webdriver-profile")) { if (prevTime == 0) { prevTime = System.currentTimeMillis() - t.lastModified(); } if (prevTime >= System.currentTimeMillis() - t.lastModified()) { pd = t; prevTime = System.currentTimeMillis() - t.lastModified(); } } } return pd.toString(); }
From source file:de.undercouch.gradle.tasks.download.OnlyIfNewerTest.java
/** * Tests if the plugin doesn't download a file if the timestamp equals * the last-modified header//from w w w . j av a2s . co m * @throws Exception if anything goes wrong */ @Test public void dontDownloadIfEqual() throws Exception { String lm = "Tue, 15 Nov 1994 12:45:26 GMT"; long expectedlmlong = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss z", Locale.ENGLISH).parse(lm) .getTime(); lastModified = lm; Download t = makeProjectAndTask(); t.src(makeSrc(LAST_MODIFIED)); File dst = folder.newFile(); FileUtils.writeStringToFile(dst, "Hello"); dst.setLastModified(expectedlmlong); t.dest(dst); t.onlyIfNewer(true); t.execute(); long lmlong = dst.lastModified(); assertEquals(expectedlmlong, lmlong); String dstContents = FileUtils.readFileToString(dst); assertEquals("Hello", dstContents); }
From source file:net.pms.dlna.DVDISOTitle.java
public DVDISOTitle(File file, int title) { this.file = file; this.title = title; setLastModified(file.lastModified()); }