List of usage examples for org.springframework.core.io Resource lastModified
long lastModified() throws IOException;
From source file:de.codecentric.boot.admin.web.servlet.resource.ConcatenatingResourceResolver.java
private long getLastModified(List<? extends Resource> resources) throws IOException { long maxLastModified = 0; for (Resource resource : resources) { maxLastModified = Math.max(maxLastModified, resource.lastModified()); }/*from w ww . j a v a2 s .c om*/ return maxLastModified; }
From source file:org.jasig.ssp.util.importer.job.tasklet.PartialUploadGuard.java
@Override public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception { Date lastAllowedModificationTime = getLastAllowedModifiedDate(); if (resources == null || resources.length == 0) { logger.error("Job not started. No resources found"); stopJob();//w w w .jav a2s . co m return RepeatStatus.FINISHED; } for (Resource resource : resources) { Date modified = new Date(resource.lastModified()); if (modified.after(lastAllowedModificationTime)) { logger.info(FILE_SOAK_TIME + resource.getFilename()); stopJob(); return RepeatStatus.FINISHED; } } return RepeatStatus.FINISHED; }
From source file:com.ethlo.geodata.util.ResourceUtil.java
public Date getLastModified(String urlStr) throws IOException { final Resource connection = openConnection(urlStr); final long lastModified = connection.lastModified(); if (lastModified == 0) { throw new IOException("No value for Last-Modified for URL " + urlStr); }/*from w ww . j av a 2s . c o m*/ return new Date(lastModified); }
From source file:com.careerly.common.support.ReloadablePropertySourcesPlaceholderConfigurer.java
@Override public void afterPropertiesSet() throws Exception { Assert.notEmpty(locations, "properties reload, locations not given"); // ??/*from w w w .ja v a 2 s.co m*/ for (Resource resource : locations) { long modified = resource.lastModified(); String modifiedTime = new DateTime(modified).toString("yyyy-MM-dd HH:mm:ss"); logger.info("properties monitor, file: {}, modified: {}", resource.getFile().getPath(), modifiedTime); lastModifiedResources.put(resource, modified); } // ??Constant? for (String beanName : beanFactory.getBeanDefinitionNames()) { if (beanName.endsWith("Constant")) { logger.info("properties monitor, bean: {}", beanName); beanNames.add(beanName); } } // ??10??JDK7?nio2 Watch Service scheduler = Executors.newSingleThreadScheduledExecutor(new NamedThreadFactory("properties-reload")); scheduler.scheduleWithFixedDelay(this, 120L, 10L, TimeUnit.SECONDS); }
From source file:de.codecentric.boot.admin.web.servlet.resource.ConcatenatingResourceResolverTest.java
@Test public void test_concatenation() throws IOException { Resource testResource = new ClassPathResource("/testResource.txt"); List<Resource> resources = asList(testResource, testResource, testResource); Resource resolvedResource = new ConcatenatingResourceResolver(";".getBytes()).resolveResource(null, "/foo.txt", resources, null); assertThat(resolvedResource.getFilename(), is("foo.txt")); assertThat(resolvedResource.lastModified(), is(testResource.lastModified())); assertThat(resolvedResource.getDescription(), is( "Byte array resource [(class path resource [testResource.txt], class path resource [testResource.txt], class path resource [testResource.txt])]")); assertThat(copyToByteArray(resolvedResource.getInputStream()), is("Foobar;Foobar;Foobar".getBytes())); }
From source file:org.jasig.schedassist.impl.relationship.CSVRelationshipDataSourceImpl.java
/** * //from w ww . j a va 2s. c om * @param resource * @return */ protected boolean isResourceUpdated(final Resource resource) { boolean result = true; try { result = (this.resourceLastModified == -1L) || (resource.lastModified() > this.resourceLastModified); } catch (IOException e) { // this exception will occur if the Resource is not representable as a File // in this case - always return true? } return result; }
From source file:com.careerly.common.support.ReloadablePropertySourcesPlaceholderConfigurer.java
@Override public void run() { try {/* w ww. j a v a2 s.co m*/ boolean changed = false; for (Resource resource : lastModifiedResources.keySet()) { long lastModified = lastModifiedResources.get(resource); long modified = resource.lastModified(); if (modified > lastModified) { String modifiedTime = new DateTime(modified).toString("yyyy-MM-dd HH:mm:ss"); logger.info("properties changed, file: {}, modified: {}", resource.getFile().getPath(), modifiedTime); changed = true; lastModifiedResources.put(resource, modified); } } // ????? if (changed) { reload(); } } catch (IOException e) { logger.error("properties reload failure", e); } }
From source file:org.ameba.system.NestedReloadableResourceBundleMessageSource.java
private PropertiesHolder refreshClassPathProperties(String filename, PropertiesHolder propHolder) { Properties properties = new Properties(); long lastModified = -1; try {/*from w ww . jav a 2 s . co m*/ Resource[] resources = resolver.getResources(filename + PROPERTIES_SUFFIX); for (Resource resource : resources) { String sourcePath = resource.getURI().toString().replace(PROPERTIES_SUFFIX, ""); PropertiesHolder holder = super.refreshProperties(sourcePath, propHolder); properties.putAll(holder.getProperties()); if (lastModified < resource.lastModified()) lastModified = resource.lastModified(); } } catch (IOException ignored) { } return new PropertiesHolder(properties, lastModified); }
From source file:com.wavemaker.commons.i18n.MultipleReloadableResourceBundleMessageSource.java
private PropertiesHolder refreshClassPathProperties(String filename, PropertiesHolder propHolder) { Properties properties = new Properties(); long lastModified = -1; try {//from www . jav a2 s .c o m Resource[] resources = null; Resource[] propertiesResources = resolver.getResources(filename + PROPERTIES_SUFFIX); Resource[] xmlResources = resolver.getResources(filename + XML_SUFFIX); resources = getMergedResources(propertiesResources, xmlResources); if (resources != null && resources.length > 0) { String sourcePath = null; PropertiesHolder holder = null; for (Resource resource : resources) { sourcePath = resource.getURI().toString().replace(PROPERTIES_SUFFIX, ""); holder = super.refreshProperties(sourcePath, propHolder); properties.putAll(holder.getProperties()); if (lastModified < resource.lastModified()) lastModified = resource.lastModified(); } } } catch (IOException ex) { if (logger.isDebugEnabled()) { logger.debug(filename + " could not be resolved in the file system", ex); } } return new PropertiesHolder(properties, lastModified); }
From source file:com.iflytek.edu.cloud.frame.support.jdbc.CustomSQL.java
public void init() { reloadSQLFiles = Boolean.valueOf(System.getProperty("reloadSQLFiles")); try {// w w w . j a va 2 s . c o m engine = Engine.getEngine(); Resource[] configs = loadConfigs(); for (Resource _config : configs) { logger.info("Loading " + _config.getURL().getPath()); configMap.put(_config.getURL().getPath(), _config.lastModified()); read(_config.getInputStream()); } } catch (Exception e) { logger.error("", e); } }