Example usage for org.springframework.util ResourceUtils getFile

List of usage examples for org.springframework.util ResourceUtils getFile

Introduction

In this page you can find the example usage for org.springframework.util ResourceUtils getFile.

Prototype

public static File getFile(URI resourceUri, String description) throws FileNotFoundException 

Source Link

Document

Resolve the given resource URI to a java.io.File , i.e.

Usage

From source file:spring.osgi.io.OsgiBundleResource.java

/**
 * Returns a <code>File</code> handle for this resource. This method does
 * a best-effort attempt to locate the bundle resource on the file system.
 * It is strongly recommended to use {@link #getInputStream()} method
 * instead which works no matter if the bundles are saved (in exploded form
 * or not) on the file system./*from www .  ja va2 s  .  co m*/
 *
 * @return File handle to this resource
 * @throws java.io.IOException if the resource cannot be resolved as absolute file
 *                             path, i.e. if the resource is not available in a file system
 */
public File getFile() throws IOException {
    // locate the file inside the bundle only known prefixes
    if (searchType != OsgiResourceUtils.PREFIX_TYPE_UNKNOWN) {
        String bundleLocation = bundle.getLocation();
        int prefixIndex = bundleLocation.indexOf(ResourceUtils.FILE_URL_PREFIX);
        if (prefixIndex > -1) {
            bundleLocation = bundleLocation.substring(prefixIndex + ResourceUtils.FILE_URL_PREFIX.length());
        }
        File file = new File(bundleLocation, path);
        if (file.exists()) {
            return file;
        }
        // fall back to the URL discovery (just in case)
    }

    try {
        return ResourceUtils.getFile(getURI(), getDescription());
    } catch (IOException ioe) {
        throw (IOException) new FileNotFoundException(
                getDescription() + " cannot be resolved to absolute file path").initCause(ioe);
    }
}

From source file:org.springframework.boot.devtools.restart.server.RestartServer.java

private void updateTimeStamp(URL url) {
    try {//from  w ww  . jav a  2  s .c o  m
        URL actualUrl = ResourceUtils.extractJarFileURL(url);
        File file = ResourceUtils.getFile(actualUrl, "Jar URL");
        file.setLastModified(System.currentTimeMillis());
    } catch (Exception ex) {
        // Ignore
    }
}

From source file:org.springframework.core.io.ClassPathResource.java

/**
 * This implementation returns a File reference for the underlying class path
 * resource, provided that it refers to a file in the file system.
 *
 * @see org.springframework.util.ResourceUtils#getFile(java.net.URL, String)
 *///from   w  ww.  java 2 s.  co m
public File getFile() throws IOException {
    return ResourceUtils.getFile(getURL(), getDescription());
}