List of usage examples for java.io File lastModified
public long lastModified()
From source file:com.netxforge.oss2.config.LinkdConfigFactory.java
/** * <p>reload</p>//from ww w.jav a 2s . c om * * @throws java.io.IOException if any. * @throws org.exolab.castor.xml.MarshalException if any. * @throws org.exolab.castor.xml.ValidationException if any. */ public void reload() throws IOException, MarshalException, ValidationException { getWriteLock().lock(); try { final File cfgFile = ConfigFileConstants.getFile(ConfigFileConstants.LINKD_CONFIG_FILE_NAME); if (cfgFile.lastModified() > m_currentVersion) { m_currentVersion = cfgFile.lastModified(); LogUtils.debugf(this, "init: config file path: %s", cfgFile.getPath()); InputStream stream = null; try { stream = new FileInputStream(cfgFile); reloadXML(stream); } finally { if (stream != null) { IOUtils.closeQuietly(stream); } } LogUtils.debugf(this, "init: finished loading config file: %s", cfgFile.getPath()); } } finally { getWriteLock().unlock(); } }
From source file:SecuritySupport.java
long getLastModified(final File f) { return ((Long) AccessController.doPrivileged(new PrivilegedAction() { public Object run() { return new Long(f.lastModified()); }/*from w w w . j a v a 2s. co m*/ })).longValue(); }
From source file:com.github.luluvise.droid_utils.cache.ModelDiskCache.java
/** * Gets an item from the disk cache only if it is not expired. * //from w w w. j a v a2s . c om * <b>Note on expiration:</b> This method uses the * {@link File#lastModified()} method to check if the cache item is expired. * Sometimes in Android this value is rounded to the second, so using very * small expiration times can result in a cache miss even if the item would * be valid. * * @param key * The cache item key (must be not null) * @param expiration * The validity of the item from its modification in * milliseconds, or {@link Long#MAX_VALUE} for no expiration * @return The cached item, null if not present, expired or an error * occurred */ @CheckForNull public V get(@Nonnull String key, long expiration) { File jsonFile = new File(mCacheLocation, key); if (!jsonFile.exists()) { return null; } final boolean noExpire = expiration == Long.MAX_VALUE; if (noExpire || (jsonFile.lastModified() + expiration) > System.currentTimeMillis()) { try { // the item is still valid, try parsing it return mObjectMapper.readValue(jsonFile, mModelClass); } catch (IOException e) { // something wrong happened LogUtils.logException(TAG, "Exception when reading " + key, e); jsonFile.delete(); // try to delete damaged file return null; } } return null; }
From source file:edu.washington.iam.registry.rp.XMLMetadata.java
private void refreshMetadataIfNeeded() { log.debug("reloader checking..."); File f = new File(sourceName); if (f.lastModified() > modifyTime) { // reload the metadata log.debug("reloading metadata for " + id + " from " + uri); locker.writeLock().lock();//ww w . j a va 2 s .c o m try { loadMetadata(); } catch (Exception e) { log.error("reload errro: " + e); } locker.writeLock().unlock(); log.debug("reload completed, time now " + modifyTime); } }
From source file:com.alibaba.otter.node.etl.extract.extractor.FileExtractor.java
private void doFileDetectCollector(Pipeline pipeline, List<FileData> fileDatas) { ExecutorTemplate executorTemplate = executorTemplateGetter.get(); try {//from www . j av a 2 s .c o m executorTemplate.start(); // ?poolSize executorTemplate.adjustPoolSize(pipeline.getParameters().getFileLoadPoolSize()); for (final FileData fileData : fileDatas) { // ??? executorTemplate.submit(new Runnable() { public void run() { boolean isAranda = StringUtils.isNotEmpty(fileData.getNameSpace()); int count = 0; Throwable exception = null; while (count++ < retry) { try { if (isAranda) { // remote file throw new RuntimeException(fileData + " is not support!"); } else { // ? File file = new File(fileData.getPath()); fileData.setLastModifiedTime(file.lastModified()); fileData.setSize(file.length()); } return;// } catch (Exception e) { fileData.setLastModifiedTime(Long.MIN_VALUE); fileData.setSize(Long.MIN_VALUE); exception = e; } } if (count >= retry) { logger.warn(String.format("FileDetectCollector is error! collect failed[%s]", fileData.getNameSpace() + "/" + fileData.getPath()), exception); } } }); } long start = System.currentTimeMillis(); logger.info("start pipelinep[{}] waitFor FileData Size : {} ", pipeline.getId(), fileDatas.size()); // ?? executorTemplate.waitForResult(); logger.info("end pipelinep[{}] waitFor FileData cost : {} ms ", pipeline.getId(), (System.currentTimeMillis() - start)); } finally { if (executorTemplate != null) { executorTemplateGetter.release(executorTemplate); } } }
From source file:com.ibm.jaggr.core.util.ZipUtilTest.java
@Before public void setUp() throws Exception { tmpdir = Files.createTempDir(); sourceDir = new File(tmpdir, "source"); targetDir = new File(tmpdir, "target"); sourceDir.mkdir();/* w w w.j a va 2s . c om*/ targetDir.mkdir(); targetDir.setLastModified(sourceDir.lastModified()); Files.write(ROOT_FILE_CONTENTS, new File(sourceDir, "rootFile.txt"), Charsets.UTF_8); File rootDir = new File(sourceDir, "rootDir"); File subDir = new File(rootDir, "subDir"); rootDir.mkdir(); subDir.mkdir(); File file1 = new File(rootDir, "file1"); File file2 = new File(subDir, "file2"); Files.write(FILE1_CONTENTS, file1, Charsets.UTF_8); Files.write(FILE2_CONTENTS, file2, Charsets.UTF_8); file1.setLastModified(file1.lastModified() - 10000); subDir.setLastModified(subDir.lastModified() + 120000); }
From source file:com.github.ukase.service.BulkRenderer.java
private void registerPdf(File pdf) { String fileName = pdf.getName(); if (pdf.isFile() && fileName.endsWith(PDF_EXT)) { String id = fileName.substring(0, fileName.length() - 4); renderedPDFs.put(id, pdf.lastModified()); }/*from w ww . j av a 2 s. co m*/ }
From source file:org.montanafoodhub.base.get.OrderHub.java
protected List<Order> readFromFile(Context context) { List<Order> myOrderArr = new ArrayList<Order>(); try {/* w w w .j a v a2s . c o 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(myOrderArr, 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()); } catch (ParseException pe) { Log.e(HubInit.logTag, "Can't parse Order date (" + fileName + ") : " + pe.toString()); } Log.w(HubInit.logTag, "Number of orders loaded: " + myOrderArr.size()); return myOrderArr; }
From source file:io.github.eternalbits.compactvd.CompactVD.java
private void copy(File from, int options, File to, String type) throws IOException { long mtime = to.lastModified(); task = DiskImageProgress.COPY;//from w w w . j a v a 2 s . c o m File copy = null; try (RandomAccessFile check = new RandomAccessFile(from, "r")) { // is file? // If writable, source is open in write mode for an exclusive file lock String mode = from.canWrite() ? "rw" : "r"; try (DiskImage image = DiskImages.open(from, mode)) { if (type == null) type = image.getType(); try (DiskImage clone = DiskImages.create(type, to, image.getDiskSize())) { copy = to; // copy open by DiskImage FileLock source = null; if (mode.equals("rw")) source = image.tryLock(); verboseProgress(SEARCHING_SPACE); image.addObserver(this, false); image.optimize(options); image.removeObserver(this); if (!isCancelled()) { verboseProgress("Copying " + from.getName() + " to " + to.getName()); FileLock fileLock = clone.tryLock(); clone.addObserver(this, false); clone.copy(image); clone.removeObserver(this); fileLock.release(); } if (source != null) source.release(); if (!isCancelled()) { copy = null; } } } } finally { if (copy != null && copy.isFile()) copy.delete(); System.out.println(mtime != to.lastModified() ? String.format(IMAGE_CREATED, to.getName(), to.getAbsoluteFile().getParent()) : IMAGE_NOT_CREATED); } }
From source file:com.github.marcosalis.kraken.cache.ModelDiskCache.java
/** * Gets an item from the disk cache only if it is not expired. * //w w w .ja v a 2 s . c o m * <b>Note on expiration:</b> This method uses the * {@link File#lastModified()} method to check if the cache item is expired. * Sometimes in Android this value is rounded to the second, so using very * small expiration times can result in a cache miss even if the item would * be valid. * * @param key * The cache item key (must be not null) * @param expiration * The validity of the item from its modification in * milliseconds, or {@link Long#MAX_VALUE} for no expiration * @return The cached item, null if not present, expired or an error * occurred */ @CheckForNull @SuppressFBWarnings(value = "RV_RETURN_VALUE_IGNORED_BAD_PRACTICE") public V get(@Nonnull String key, long expiration) { File jsonFile = new File(mCacheLocation, key); if (!jsonFile.exists()) { return null; } final boolean noExpire = expiration == Long.MAX_VALUE; if (noExpire || (jsonFile.lastModified() + expiration) > System.currentTimeMillis()) { try { // the item is still valid, try parsing it return mObjectMapper.readValue(jsonFile, mModelClass); } catch (IOException e) { // something wrong happened LogUtils.logException(TAG, "Exception when reading " + key, e); jsonFile.delete(); // try to delete damaged file return null; } } return null; }