List of usage examples for java.io File lastModified
public long lastModified()
From source file:com.thalesgroup.hudson.plugins.copyarchiver.FilePathArchiver.java
/** * * @param baseDir the base directory//from w ww . j av a 2 s.com * @param fileMask the mask file * @param excludes the excludes pattern * @param out the output stream * @return the number of files * @throws IOException the IOException */ private Integer writeToTar(File baseDir, String fileMask, String excludes, OutputStream out) throws IOException { FileSet fs = Util.createFileSet(baseDir, fileMask, excludes); byte[] buf = new byte[8192]; TarOutputStream tar = new TarOutputStream(new BufferedOutputStream(out)); tar.setLongFileMode(TarOutputStream.LONGFILE_GNU); String[] files; if (baseDir.exists()) { DirectoryScanner ds = fs.getDirectoryScanner(new org.apache.tools.ant.Project()); files = ds.getIncludedFiles(); } else { files = new String[0]; } for (String f : files) { if (Functions.isWindows()) f = f.replace('\\', '/'); File file = new File(baseDir, f); TarEntry te = new TarEntry(f); te.setModTime(file.lastModified()); if (!file.isDirectory()) te.setSize(file.length()); tar.putNextEntry(te); if (!file.isDirectory()) { FileInputStream in = new FileInputStream(file); int len; while ((len = in.read(buf)) >= 0) tar.write(buf, 0, len); in.close(); } tar.closeEntry(); } tar.close(); return files.length; }
From source file:com.xpn.xwiki.plugin.charts.ChartingPlugin.java
public void outputFile(String filename, XWikiContext context) throws IOException { File ofile = getTempFile(filename); byte[] bytes = readFile(ofile); XWikiResponse response = context.getResponse(); context.setFinished(true);/*from w w w . j a v a2 s.c om*/ response.setDateHeader("Last-Modified", ofile.lastModified()); response.setContentLength(bytes.length); response.setContentType(context.getEngineContext().getMimeType(filename)); OutputStream os = response.getOutputStream(); os.write(bytes); }
From source file:com.hypersocket.server.handlers.impl.ClasspathContentHandler.java
@Override public long getLastModified(String path) { try {//from w w w . ja va 2 s . co m URL url = getClass().getResource(classpathPrefix + "/" + path); if (log.isDebugEnabled()) { log.debug("Processing resource URL " + url.toURI().toString()); } int idx; File jarFile; if ((idx = url.toURI().toString().indexOf("!")) > -1) { jarFile = new File(url.toURI().toString().substring(9, idx)); } else { jarFile = new File(url.toURI()); } if (log.isInfoEnabled()) { Date modified = new Date(jarFile.lastModified()); if (log.isDebugEnabled()) { log.debug("Jar file " + jarFile.getAbsolutePath() + " last modified " + HypersocketUtils.formatDateTime(modified)); } } return jarFile.lastModified(); } catch (URISyntaxException e) { } return System.currentTimeMillis(); }
From source file:net.orpiske.ssps.common.resource.FileResourceExchange.java
@Override public Resource<InputStream> get(URI uri) throws ResourceExchangeException { File file = new File(uri); Resource<InputStream> ret = new Resource<InputStream>(); try {/*from w w w. ja v a2 s .c om*/ inputStream = FileUtils.openInputStream(file); ret.setPayload(inputStream); ResourceInfo info = new ResourceInfo(); info.setSize(FileUtils.sizeOf(file)); info.setLastModified(file.lastModified()); ret.setResourceInfo(info); } catch (IOException e) { throw new ResourceExchangeException("I/O error: " + e.getMessage(), e); } return ret; }
From source file:edu.washington.iam.registry.rp.XMLMetadata.java
private void loadMetadata() throws RelyingPartyException { log.info("load relyingParties for " + id + " from " + uri); relyingParties = new Vector(); Document doc;/*www . j a va2 s .c om*/ try { DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance(); builderFactory.setNamespaceAware(true); DocumentBuilder builder = builderFactory.newDocumentBuilder(); doc = builder.parse(uri); } catch (Exception e) { log.error("parse issue: " + e); throw new RelyingPartyException("bad xml"); } // update the timestamp File f = new File(sourceName); modifyTime = f.lastModified(); log.debug("rp load " + f.getName() + ": time = " + modifyTime); List<Element> list = XMLHelper.getElementsByName(doc.getDocumentElement(), "EntityDescriptor"); log.info("found " + list.size()); for (int i = 0; i < list.size(); i++) { Element rpe = list.get(i); if (XMLHelper.getElementByName(rpe, "SPSSODescriptor") == null) continue; try { RelyingParty rp = new RelyingParty(rpe, id, editable); relyingParties.add(rp); } catch (RelyingPartyException e) { log.error("load of element failed: " + e); } } }
From source file:org.jboss.maven.plugins.qstools.config.ConfigurationProvider.java
private InputStream getCachedRepoStream(final boolean force) throws FileNotFoundException { final String logmessage = "Local file %1s %2s used! Reason: Force:[%3b] - LastModification: %4d/%5d"; File localCacheFile = getLocalCacheFile(); if (localCacheFile.exists()) { long cachedvalidity = 1000 * Constants.CACHE_EXPIRES_SECONDS; long lastModified = localCacheFile.lastModified(); long timeSinceLastModification = System.currentTimeMillis() - lastModified; // if online, consider the cache valid until it expires if (force || timeSinceLastModification <= cachedvalidity) { log.debug(String.format(logmessage, localCacheFile, "was", force, timeSinceLastModification, cachedvalidity));//from ww w. ja v a 2 s . co m return new FileInputStream(localCacheFile); } log.debug(String.format(logmessage, localCacheFile, "was not", force, timeSinceLastModification, cachedvalidity)); } return null; }
From source file:cn.dreampie.common.plugin.coffeescript.compiler.CoffeeCompiler.java
/** * Compiles the input <code>CoffeeSource</code> to CSS and writes it to the specified output <code>File</code>. * * @param input The input <code>CoffeeSource</code> to compile. * @param output The output <code>File</code> to write the CSS to. * @param force 'false' to only compile the input <code>CoffeeSource</code> in case the COFFEE source has been modified (including imports) or the output file does not exists. * @throws IOException If the COFFEE file cannot be read or the output file cannot be written. *//*from w ww . j a va 2s .c o m*/ public void compile(CoffeeSource input, File output, boolean force) throws IOException, CoffeeException { if (force || (!output.exists() && output.createNewFile()) || output.lastModified() < input.getLastModifiedIncludingImports()) { String data = compile(input); FileUtils.writeStringToFile(output, data, encoding); } }
From source file:de.undercouch.gradle.tasks.download.FunctionalDownloadTest.java
/** * Create destination file locally, then run download. * @throws Exception if anything went wrong *///from w w w . j a v a 2 s . com @Test public void downloadOnlyIfNewerReDownloadIfFileExists() throws Exception { File testFile = new File(folder.getRoot(), TEST_FILE_NAME); FileUtils.writeByteArrayToFile(destFile, contents); assertTrue(destFile.setLastModified(testFile.lastModified())); assertTaskSuccess(download(new Parameters(singleSrc, dest, true, false))); }
From source file:com.wavemaker.common.util.IOUtilsTest.java
public void testTouchDir() throws Exception { File f = null; try {//from ww w .j av a 2 s . c om f = IOUtils.createTempDirectory(); long lastModified = f.lastModified(); // UNIX counts in seconds Thread.sleep(3000); IOUtils.touch(f); assertTrue(lastModified < f.lastModified()); } finally { if (f != null) { IOUtils.deleteRecursive(f); } } }
From source file:info.fetter.logstashforwarder.FileState.java
public FileState(File file) throws IOException { this.file = file; directory = file.getCanonicalFile().getParent(); fileName = file.getName();/*from w w w . ja v a2 s. c o m*/ randomAccessFile = new RandomAccessFile(file.getPath(), "r"); lastModified = file.lastModified(); size = file.length(); }