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.trustedanalytics.servicebroker.gearpump.service.file.ResourceManagerService.java

public InputStream getResourceInputStream(String path) throws IOException {
    Resource resource = getResourceForPath(path);
    LOGGER.info("Got the resource: {}", resource.getURI());

    return resource.getInputStream();
}

From source file:com.github.mybatis.repository.autoconfig.SpringBootVFS.java

@Override
protected List<String> list(URL url, String path) throws IOException {
    Resource[] resources = resourceResolver.getResources("classpath*:" + path + "/**/*.class");
    List<String> resourcePaths = new ArrayList<String>();
    for (Resource resource : resources) {
        resourcePaths.add(preserveSubpackageName(resource.getURI(), path));
    }//from   w  ww .j  av  a  2s .c  om
    return resourcePaths;
}

From source file:com.czy.core.orm.config.mybatis.SpringBootVFS.java

@Override
protected List<String> list(URL url, String path) throws IOException {
    ClassLoader cl = this.getClass().getClassLoader();
    ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(cl);
    Resource[] resources = resolver.getResources("classpath*:" + path + "/**/*.class");
    List<Resource> resources1 = Arrays.asList(resources);
    List<String> resourcePaths = new ArrayList<String>();
    for (Resource resource : resources1) {
        resourcePaths.add(preserveSubpackageName(resource.getURI(), path));
    }/*from   w ww  . j  ava 2s .c  o m*/
    return resourcePaths;
}

From source file:com.yahoo.bard.webservice.config.ConfigResourceLoader.java

/**
 * A simple predicate that is true if a resource is not from a jar.
 *
 * @param resource  the Resource under test
 *
 * @return true if the resource is not from a jar
 *///from   ww w .  jav a  2 s .  c  o  m
public boolean isResourceNotAJar(Resource resource) {
    try {
        return !resource.getURI().getScheme().equals("jar");
    } catch (IOException e) {
        // If the resource doesn't parse cleanly as a URI, it's not a jar
        return true;
    }
}

From source file:nl.flotsam.calendar.core.memory.InMemoryComoundCalendarTest.java

@Test
public void shouldParseNingCalendarCorrectly() throws IOException, ValidationException {
    Resource resource = new ClassPathResource("/ning.ical");
    assertTrue(resource.exists());//  ww  w  .j  av a 2s  .  co m
    URI uri = resource.getURI();

    InMemoryCompoundCalendarRepository repository = new InMemoryCompoundCalendarRepository(urlFetchService);
    Calendar calendar = repository.putCalendar("test", Arrays.asList(uri));
    calendar = repository.getCalendar("test");
    assertThat(calendar, is(not(nullValue())));
}

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 w  w  w . j a  v a  2 s.com
        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.edmunds.autotest.ClassResolver.java

private String getURI(Resource resource) {
    try {/*w ww . j av a 2 s  .c om*/
        final URI uri = resource.getURI();
        if (uri != null) {
            return uri.toString();
        }

    } catch (IOException e) {
        log.info(e);
    }
    return null;
}

From source file:nl.flotsam.hamcrest.schema.relaxng.ResourceValidator.java

public boolean validate(Verifier verifier, Resource verifiable) throws SAXException, IOException {
    InputSource source = new InputSource(verifiable.getInputStream());
    source.setSystemId(verifiable.getURI().toASCIIString());
    return new InputSourceValidator().validate(verifier, source);
}

From source file:org.bitsofinfo.util.address.usps.ais.processor.DataProcessorRecordHandlerTest.java

@Test
public void testLoad805WithDataProcessorRecordHandler() {
    try {//from   w  ww.  j a v  a  2s .  c o m

        Resource file = applicationContext.getResource("classpath:805.txt");
        FileHandle handle = new FileHandle(file.getURI());

        recordLoader.loadRecords(handle, recordHandler, 2, 500000,
                USPSProductType.ZIP_PLUS_4.getRecordLength());

        // should be 60971

        //   dataStore.purgeEntireStore();

    } catch (Exception e) {
        e.printStackTrace();
        int v = 1;
    }
}

From source file:org.bitsofinfo.util.address.usps.ais.loader.USPSRecordHandlerTest.java

@Test
public void testLoad805WithUSPSRecordHandler() {
    try {// w w  w.  j av a 2  s .c  o m
        Resource file = applicationContext.getResource("classpath:805.txt");
        FileHandle handle = new FileHandle(file.getURI());

        MapBackedRecordHandler handler = new MapBackedRecordHandler(uspsUtils, parser, idGenerator);

        recordLoader.loadRecords(handle, handler, 1, 500000, USPSProductType.ZIP_PLUS_4.getRecordLength());

        Map<Long, USPSRecord> results = handler.getResults();
        for (Long recordNum : results.keySet()) {
            ZipPlus4Detail rec = (ZipPlus4Detail) results.get(recordNum);
            if (rec.getStreetName().indexOf("BOG") != -1) {
                int v = 1;
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
        int v = 1;
    }
}