List of usage examples for java.io File lastModified
public long lastModified()
From source file:com.meltmedia.cadmium.maven.ArtifactResolverTest.java
@Test public void testResolveArtifact() throws Exception { File localRepo = new File("./target/.m2"); if (localRepo.exists()) { FileUtils.cleanDirectory(localRepo); }/*w ww . j a va2 s .c o m*/ FileUtils.forceMkdir(localRepo); ArtifactResolver resolver = new ArtifactResolver(null, localRepo.getAbsolutePath()); File artifact = resolver.resolveMavenArtifact("org.apache.maven:maven-artifact:3.0.4"); System.err.println("Artifact is downloaded to: " + artifact.getAbsolutePath()); assertTrue("Artifact not downloaded.", artifact.exists()); assertTrue("Artifact cannot be read.", artifact.canRead()); assertTrue("Artifact points to empty file.", artifact.lastModified() > 0l); }
From source file:com.yoncabt.abys.core.util.EBRConf.java
private void reloadIfRequired() { File confFile = getConfFile(); if (confFile.exists() && confFile.isFile() && confFile.canRead() && confFile.lastModified() > lastModified) { reload();//from w w w . j ava 2 s . com } }
From source file:at.ac.tuwien.infosys.jcloudscale.classLoader.caching.fileCollectors.FileCollectorAbstract.java
/** * Returns a {@link ClassLoaderOffer} containing the requested file in the classpath, if possible.<br/> * If the resource cannot be located, {@code null} is returned instead. * //from ww w. ja v a 2 s . c o m * @param fileName the name of the resource * @return the offer (can be {@code null}) */ protected ClassLoaderOffer collectFile(String fileName) { try { ClassPathResource resource = new ClassPathResource(fileName); if (resource.exists()) { File file = resource.getFile(); ClassLoaderFile classLoaderFile = new ClassLoaderFile(fileName, file.lastModified(), ContentType.ROFILE, Files.toByteArray(file)); return new ClassLoaderOffer(null, 0, new ClassLoaderFile[] { classLoaderFile }); } } catch (IOException e) { // ignore } return null; }
From source file:com.ksc.auth.profile.ProfilesConfigFile.java
/** * Loads the AWS credential profiles from the file. The reference to the * file is specified as a parameter to the constructor. *///from w w w. ja v a 2 s. co m public ProfilesConfigFile(File file, ProfileCredentialsService credentialsService) throws KscClientException { profileFile = file; profileCredentialsService = credentialsService; profileFileLastModified = file.lastModified(); profilesByName = loadProfiles(profileFile, profileCredentialsService); }
From source file:org.montanafoodhub.base.get.CertificationHub.java
protected HashMap<String, Certification> readFromFile(Context context) { HashMap<String, Certification> myCertificationMap = new HashMap<String, Certification>(); try {//from w ww. jav a 2s.c om // 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(myCertificationMap, 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 certifications loaded: " + myCertificationMap.size()); return myCertificationMap; }
From source file:com.krawler.esp.servlets.importICSServlet.java
public static Calendar setUpICal(String url, String ID, int interval) throws ServiceException { Calendar calByUrl = null;/*from w w w . j av a 2 s . c om*/ try { setSystemProperties(); boolean fileCreated = false; File file = new File( StorageHandler.GetDocStorePath() + StorageHandler.GetFileSeparator() + ID + ".ics"); if (file.exists()) { // if this calendar file exists in the store? java.util.Calendar cal = java.util.Calendar.getInstance(); cal.setTime(new Date()); cal.add(java.util.Calendar.MINUTE, interval); if (new Date(file.lastModified()).before(cal.getTime()) || new Date(file.lastModified()).equals(cal.getTime())) { // if its older than given time? fileCreated = getICalFileFromURL(file, url, true); if (fileCreated) { interval = interval * -1; Tree.updateInternetCalendar(ID, interval, true); file.setLastModified(new Date().getTime()); } } else { fileCreated = true; } } else { // file does not exists. it has to be created. fileCreated = getICalFileFromURL(file, url, false); if (fileCreated) file.setLastModified(new Date().getTime()); } if (fileCreated) { FileInputStream fip = new FileInputStream(file); CalendarBuilder cb = new CalendarBuilder(new CalendarParserImpl()); calByUrl = cb.build(fip); fip.close(); file.setReadOnly(); if (!calByUrl.toString().contains(Organizer.ORGANIZER)) { Property p = new Organizer("MAILTO:calendar@deskera.com"); calByUrl.getProperties().add(p); } calByUrl.validate(); } } catch (FileNotFoundException e) { throw ServiceException.FAILURE(KWLErrorMsgs.calFileEx, e); } catch (ValidationException e) { throw ServiceException.FAILURE(KWLErrorMsgs.calValidationEx, e); } catch (ParserException e) { throw ServiceException.FAILURE(KWLErrorMsgs.calParseEx, e); } catch (ConfigurationException e) { throw ServiceException.FAILURE(KWLErrorMsgs.calFileEx, e); } catch (URISyntaxException e) { throw ServiceException.FAILURE(KWLErrorMsgs.calURLEx, e); } catch (IOException e) { throw ServiceException.FAILURE(KWLErrorMsgs.calIOEx, e); } catch (Exception e) { throw ServiceException.FAILURE(KWLErrorMsgs.calIOEx, e); } return calByUrl; }
From source file:io.stallion.dataAccess.file.FilePersisterBase.java
public boolean reloadIfNewer(T obj) { String path = fullFilePathForObj(obj); File file = new File(path.toString()); Long currentTs = file.lastModified(); Long fileLastModified = or(obj.getLastModifiedMillis(), 0L); if (currentTs >= fileLastModified) { getStash().loadForId(obj.getId()); fileToTimestampMap.put(path.toString(), currentTs); return true; }/*from w w w. j ava2 s . com*/ return false; }
From source file:com.izforge.izpack.installer.unpacker.AbstractFileUnpackerTest.java
/** * Verifies the target matches the source. * * @param source the source// w ww. jav a2s . c o m * @param target the target * @throws IOException for any I/O error */ protected void checkTarget(File source, File target) throws IOException { assertTrue(target.exists()); assertEquals(source.length(), target.length()); assertEquals(source.lastModified(), target.lastModified()); byte[] sourceBytes = getContent(source); byte[] targetBytes = getContent(target); assertArrayEquals(sourceBytes, targetBytes); }
From source file:hudson.ClassicPluginStrategy.java
/** * Repackage classes directory into a jar file to make it remoting friendly. * The remoting layer can cache jar files but not class files. *//*from w w w .ja v a 2s .c o m*/ private static void createClassJarFromWebInfClasses(File archive, File destDir, Project prj) throws IOException { File classesJar = new File(destDir, "WEB-INF/lib/classes.jar"); ZipFileSet zfs = new ZipFileSet(); zfs.setProject(prj); zfs.setSrc(archive); zfs.setIncludes("WEB-INF/classes/"); MappedResourceCollection mapper = new MappedResourceCollection(); mapper.add(zfs); GlobPatternMapper gm = new GlobPatternMapper(); gm.setFrom("WEB-INF/classes/*"); gm.setTo("*"); mapper.add(gm); final long dirTime = archive.lastModified(); // this ZipOutputStream is reused and not created for each directory final ZipOutputStream wrappedZOut = new ZipOutputStream(new NullOutputStream()) { @Override public void putNextEntry(ZipEntry ze) throws IOException { ze.setTime(dirTime + 1999); // roundup super.putNextEntry(ze); } }; try { Zip z = new Zip() { /** * Forces the fixed timestamp for directories to make sure * classes.jar always get a consistent checksum. */ protected void zipDir(Resource dir, ZipOutputStream zOut, String vPath, int mode, ZipExtraField[] extra) throws IOException { // use wrappedZOut instead of zOut super.zipDir(dir, wrappedZOut, vPath, mode, extra); } }; z.setProject(prj); z.setTaskType("zip"); classesJar.getParentFile().mkdirs(); z.setDestFile(classesJar); z.add(mapper); z.execute(); } finally { wrappedZOut.close(); } }
From source file:com.liferay.blade.cli.SamplesCommand.java
private boolean downloadBladeRepoIfNeeded() throws Exception { File bladeRepoArchive = new File(_blade.getCacheDir(), _BLADE_REPO_ARCHIVE_NAME); Date now = new Date(); long diff = now.getTime() - bladeRepoArchive.lastModified(); if (!bladeRepoArchive.exists() || (diff > _FILE_EXPIRATION_TIME)) { FileUtils.copyURLToFile(new URL(_BLADE_REPO_URL), bladeRepoArchive); return true; }/*from www.ja va 2 s . c o m*/ return false; }