Example usage for org.springframework.core.io Resource getURI

List of usage examples for org.springframework.core.io Resource getURI

Introduction

In this page you can find the example usage for org.springframework.core.io Resource getURI.

Prototype

URI getURI() throws IOException;

Source Link

Document

Return a URI handle for this resource.

Usage

From source file:org.wallride.support.ExtendedResourceUtils.java

public static void write(Resource resource, File file) throws IOException {
    if (resource instanceof WritableResource) {
        //         IOUtils.copy(new FileInputStream(file), ((WritableResource) resource).getOutputStream());
        try (InputStream input = new FileInputStream(file);
                OutputStream output = ((WritableResource) resource).getOutputStream()) {
            IOUtils.copy(input, output);
        }/*from  w w  w. j a va  2s  .c om*/
        return;
    }
    FileUtils.copyFile(file, getFile(resource.getURI()));
}

From source file:org.paxml.core.ResourceLocator.java

/**
 * Find all resources with a spring path pattern, from the added resources.
 * //from ww w.j a  va 2  s . co  m
 * @param springPattern
 *            the spring path pattern.
 * @param baseFile
 *            the file used to resolve relative path with, can be null if
 *            the pattern is not relative.
 * @return all resource found, never null.
 */
public static Set<PaxmlResource> findResources(String springPattern, Resource baseFile) {

    springPattern = springPattern.trim();

    if (StringUtils.isBlank(springPattern)) {
        throw new PaxmlRuntimeException("Cannot have empty file pattern!");
    }

    Set<PaxmlResource> set = new LinkedHashSet<PaxmlResource>();
    if (!springPattern.startsWith("file:") && !springPattern.startsWith("classpath:")
            && !springPattern.startsWith("classpath*:")) {
        springPattern = getRelativeResource(baseFile, springPattern);
    }
    if (log.isInfoEnabled()) {
        log.info("Searching paxml resource with pattern: " + springPattern);
    }
    try {
        for (Resource res : new PathMatchingResourcePatternResolver().getResources(springPattern)) {

            if (res instanceof ClassPathResource) {
                set.add(new ClasspathResource((ClassPathResource) res));
            } else if (res instanceof UrlResource && res.getURI().toString().startsWith("jar:")) {

                set.add(new ClasspathResource(
                        new ClassPathResource(StringUtils.substringAfterLast(res.getURI().toString(), "!"))));

            } else {
                try {
                    File file = res.getFile();
                    if (file.isFile()) {
                        set.add(new FileSystemResource(file));
                    }
                } catch (IOException e) {
                    throw new PaxmlRuntimeException("Unsupported spring resource: " + res.getURI()
                            + ", of type: " + res.getClass().getName());
                }
            }
        }
    } catch (IOException e) {
        throw new PaxmlRuntimeException("Cannot find resources with spring pattern: " + springPattern, e);
    }
    return set;
}

From source file:org.wallride.support.ExtendedResourceUtils.java

public static void write(Resource resource, MultipartFile file) throws IOException {
    if (resource instanceof WritableResource) {
        //         IOUtils.copy(file.getInputStream(), ((WritableResource) resource).getOutputStream());
        try (InputStream input = file.getInputStream();
                OutputStream output = ((WritableResource) resource).getOutputStream()) {
            IOUtils.copy(input, output);
        }/*from   w  ww . ja v a  2  s.  c  o  m*/
        return;
    }
    FileUtils.copyInputStreamToFile(file.getInputStream(), getFile(resource.getURI()));
}

From source file:hm.binkley.util.XProperties.java

/**
 * Creates a new {@code XProperties} for the given <var>absolutePath</var>
 * found in the classpath./*from  ww w. j av a 2s. c  om*/
 *
 * @param absolutePath the absolute path to search on the classpath, never
 * missing
 *
 * @throws IOException if <var>absolutePath</var> cannot be loaded
 */
@Nonnull
public static XProperties from(@Nonnull @NonNull final String absolutePath) throws IOException {
    final Resource resource = new PathMatchingResourcePatternResolver().getResource(absolutePath);
    try (final InputStream in = resource.getInputStream()) {
        final XProperties xprops = new XProperties();
        xprops.included.add(resource.getURI());
        xprops.load(in);
        return xprops;
    }
}

From source file:org.jahia.modules.external.test.db.WriteableMappedDatabaseProvider.java

private static void extract(JahiaTemplatesPackage p, org.springframework.core.io.Resource r, File f)
        throws Exception {
    if ((r instanceof BundleResource && r.contentLength() == 0)
            || (!(r instanceof BundleResource) && r.getFile().isDirectory())) {
        f.mkdirs();//from   w w  w  .ja v  a2 s  .  com
        String path = r.getURI().getPath();
        for (org.springframework.core.io.Resource resource : p
                .getResources(path.substring(path.indexOf("/toursdb")))) {
            extract(p, resource, new File(f, resource.getFilename()));
        }
    } else {
        FileOutputStream output = null;
        try {
            output = new FileOutputStream(f);
            IOUtils.copy(r.getInputStream(), output);
        } finally {
            IOUtils.closeQuietly(output);
        }
    }
}

From source file:com.griddynamics.jagger.JaggerLauncher.java

private static List<String> discoverResources(URL directory, String[] includePatterns,
        String[] excludePatterns) {
    PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(
            new FileSystemResourceLoader());
    List<String> resourceNames = new ArrayList<String>();
    PathMatcher matcher = new AntPathMatcher();
    try {/*from   w w  w  .  j ava  2  s  . co  m*/
        for (String pattern : includePatterns) {
            Resource[] includeResources = resolver.getResources(directory.toString() + pattern);
            for (Resource resource : includeResources) {
                boolean isValid = true;
                for (String excludePattern : excludePatterns) {
                    if (matcher.match(excludePattern, resource.getFilename())) {
                        isValid = false;
                        break;
                    }
                }
                if (isValid) {
                    resourceNames.add(resource.getURI().toString());
                }
            }
        }
    } catch (IOException e) {
        throw new TechnicalException(e);
    }

    return resourceNames;
}

From source file:com.toyota.carservice.SplashScreen.java

@Override
public void start(Stage stage) throws Exception {
    Parent root = FXMLLoader.load(getClass().getResource("/com/toyota/carservice/view/formSplash.fxml"));
    Scene scene = new Scene(root);
    stage.setTitle("Connection to database...");
    ApplicationContext appContex = config.getInstance().getApplicationContext();
    Resource resource = appContex.getResource("classpath:com/toyota/carservice/img/kallatoyota.png");
    stage.getIcons().add(new Image(resource.getURI().toString()));
    stage.setScene(scene);//  w  ww. j  a  v  a  2  s  . c  o  m
    stage.initStyle(StageStyle.UNDECORATED);
    stage.show();
}

From source file:org.trustedanalytics.servicebroker.gearpump.service.file.ResourceManagerService.java

public String getRealPath(String path) throws IOException {
    Resource resource = getResourceForPath(path);
    try {/*from   ww w.  ja  v a2 s. c  o m*/
        return resource.getURI().getPath();
    } catch (IOException e) {
        LOGGER.error("Cannot get resource URI. ", e);
        throw e;
    }
}

From source file:org.ameba.system.NestedReloadableResourceBundleMessageSource.java

private PropertiesHolder refreshClassPathProperties(String filename, PropertiesHolder propHolder) {
    Properties properties = new Properties();
    long lastModified = -1;
    try {//  www  .  j  a va  2s . 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.jaxio.celerio.template.pack.ClasspathResourceUncryptedPack.java

private boolean isFolder(Resource r) throws IOException {
    return r.getURI().toString().endsWith("/");
}