Package org.springframework.core.io

Examples of org.springframework.core.io.Resource.lastModified()


    if (resource.exists()) {
      long fileTimestamp = -1;
      if (this.cacheMillis >= 0) {
        // Last-modified timestamp of file will just be read if caching with timeout.
        try {
          fileTimestamp = resource.lastModified();
          if (propHolder != null && propHolder.getFileTimestamp() == fileTimestamp) {
            if (logger.isDebugEnabled()) {
              logger.debug("Re-caching properties for filename [" + filename + "] - file hasn't been modified");
            }
            propHolder.setRefreshTimestamp(refreshTimestamp);
View Full Code Here


*/
public class ResourceScriptSourceTests extends TestCase {

  public void testDoesNotPropagateFatalExceptionOnResourceThatCannotBeResolvedToAFile() throws Exception {
    Resource resource = mock(Resource.class);
    given(resource.lastModified()).willThrow(new IOException());

    ResourceScriptSource scriptSource = new ResourceScriptSource(resource);
    long lastModified = scriptSource.retrieveLastModifiedTime();
    assertEquals(0, lastModified);
  }
View Full Code Here

  public void testLastModifiedWorksWithResourceThatDoesNotSupportFileBasedReading() throws Exception {
    Resource resource = mock(Resource.class);
    // underlying File is asked for so that the last modified time can be checked...
    // And then mock the file changing; i.e. the File says it has been modified
    given(resource.lastModified()).willReturn(100L, 100L, 200L);
    // does not support File-based reading; delegates to InputStream-style reading...
    //resource.getFile();
    //mock.setThrowable(new FileNotFoundException());
    given(resource.getInputStream()).willReturn(new ByteArrayInputStream(new byte[0]));
View Full Code Here

    if (resource.exists()) {
      long fileTimestamp = -1;
      if (this.cacheMillis >= 0) {
        // Last-modified timestamp of file will just be read if caching with timeout.
        try {
          fileTimestamp = resource.lastModified();
          if (propHolder != null && propHolder.getFileTimestamp() == fileTimestamp) {
            if (logger.isDebugEnabled()) {
              logger.debug("Re-caching properties for filename [" + filename + "] - file hasn't been modified");
            }
            propHolder.setRefreshTimestamp(refreshTimestamp);
View Full Code Here

        protected Resource resolveResource(String href, String base) throws TransformerException {
            final Resource resource = super.resolveResource(href, base);

            long lastModified = 0;
            try {
                lastModified = resource.lastModified();
            }
            catch (IOException e) {
                //Ignore, not all resources can have a valid lastModified returned
            }
            resolvedResources.put(resource, lastModified);
View Full Code Here

      return;
    }

    // header phase
    setHeaders(response, resource, mediaType);
    if (new ServletWebRequest(request, response).checkNotModified(resource.lastModified())) {
      logger.debug("Resource not modified - returning 304");
      return;
    }

    // content phase
View Full Code Here

    protected ResourceLoader resourceLoader = new FileSystemResourceLoader();

    @Override
    public long checkResource(Object... coordinates) throws IOException {
        Resource resource = resourceLoader.getResource(getResourceLocation(coordinates));
        return resource.exists() ? resource.lastModified() : 0;
    }

    @Override
    public InputStream loadResource(Object... coordinates) throws IOException {
        Resource resource = resourceLoader.getResource(getResourceLocation(coordinates));
View Full Code Here

        Resource resource = resourceLoader.getResource(getResourceLocation(coordinates));
        if(!resource.exists()) {
            createResource(resource);
        }
        FileCopyUtils.copy(inputStream, new FileOutputStream(resource.getFile()));
        return resource.lastModified();
    }

    @Override
    public void removeResource(Object... coordinates) throws IOException {
        Resource resource = resourceLoader.getResource(getResourceLocation(coordinates));
View Full Code Here

    }

    @Override
    public long checkSizedResource(Object size, Object... coordinates) throws IOException {
        Resource sizedResource = resourceLoader.getResource(getSizedResourceLocation(size, coordinates));
        return sizedResource.exists()?sizedResource.lastModified() : 0;
    }

    private void createResource(Resource resource) throws IOException {
        resource.getFile().getParentFile().mkdirs();
        resource.getFile().createNewFile();
View Full Code Here

        }

        long lastModified;

        try {
            lastModified = resource.lastModified();
        } catch (IOException e) {
            lastModified = 0;
        }

        // 2. 假如资源找到了,但是不支持lastModified功能,则认为modified==false,模板不会重新装载。
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.