List of usage examples for org.springframework.core.io Resource getDescription
String getDescription();
From source file:com.bluexml.side.framework.alfresco.commons.configurations.AbstractConfigurationFile.java
public Map<K, V> getDictionary() { if (dictionary == null) { dictionary = new HashMap<K, V>(); try {//from w ww. j a v a 2 s. c o m for (Resource r : getResources()) { logger.info("Loading resource " + r.getDescription()); loadResource(r); } } catch (Exception e) { logger.error("error when traying to reload configuration", e); } } return Collections.unmodifiableMap(dictionary); }
From source file:at.porscheinformatik.common.spring.web.extended.template.chunk.ChunkTemplateTest.java
@Test(dataProvider = "renderTemplateData") public void renderTemplate(Resource resource, String templateName, ResourceType type, String expected) throws Exception { Template t = factory.createTemplate(resource, templateName, resource.getDescription(), type, false); String actual = t.render();/* ww w . j a v a 2 s. com*/ Assert.assertThat(actual, CoreMatchers.equalTo(expected)); }
From source file:at.porscheinformatik.common.spring.web.extended.template.chunk.ChunkTemplateTest.java
@Test(dataProvider = "renderTemplateData") public void performanceTest(Resource resource, String templateName, ResourceType type, String expected) throws Exception { Template t = factory.createTemplate(resource, templateName, resource.getDescription(), type, false); for (int i = 0; i < 1000; i++) { Assert.assertThat(t.render(), CoreMatchers.equalTo(expected)); }//from w w w .j a v a 2s . c o m }
From source file:com.bluexml.side.Integration.alfresco.sql.synchronization.dictionary.PropertyFileDatabaseDictionary.java
public void setResourcePattern(String resourcePattern) { try {/*from w w w . j a v a 2 s .co m*/ Resource[] resources = _resolver.getResources(resourcePattern); for (Resource r : resources) { if (logger.isDebugEnabled()) logger.debug("Loading resource " + r.getDescription()); _loadResource(r); } } catch (IOException e) { logger.error(e); } }
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.craftercms.commons.properties.OverrideProperties.java
/** * Checks and starts the reading of the given Resources. *//*from w w w . j a v a 2s .co m*/ public void init() { for (Resource resource : resources) { if (resource.exists()) { try (InputStream in = resource.getInputStream()) { readPropertyFile(in); } catch (IOException ex) { log.debug("Unable to load queries from " + resource.getDescription(), ex); } } else { log.info("Query file at {} not found. Ignoring it...", resource.getDescription()); } } }
From source file:ws.antonov.config.provider.ResourceConfigProvider.java
public Message.Builder retrieveConfigData(Class<? extends Message> configClass, ConfigParamsBuilder.ConfigParamsMap configParams) throws IOException { Resource resource = computeResourceDestinationFromParams(configParams); try {/*from www. jav a 2 s. co m*/ return convertMessage(configClass, determineContentType(resource), resource.getInputStream()); } catch (Exception e) { throw new IOException("Unable to load requested config from " + resource.getDescription(), e); } finally { resource.getInputStream().close(); } }
From source file:org.obiba.onyx.spring.context.OnyxMessageSourceFactoryBean.java
protected void findBasenames(Set<String> basenames, String pathPrefix, String suffix) throws IOException { ResourcePatternResolver resolver = (ResourcePatternResolver) this.resourceLoader; // Find all files that match "pathPrefix/**/MESSAGES_BASENAME*suffix" // For example, this will find "WEB-INF/config/myModule/messages_en.properties" String resourcePattern = pathPrefix + "**/" + MESSAGES_BUNDLENAME + "*" + suffix; String resourcePatternParent = onyxConfigPath + MESSAGES_BUNDLENAME + "*" + suffix; log.debug("Finding resources that match pattern {}", resourcePattern); List<Resource> messageResources = new ArrayList<Resource>(); messageResources.addAll(Arrays.asList(resolver.getResources(resourcePattern))); messageResources.addAll(Arrays.asList(resolver.getResources(resourcePatternParent))); for (Resource resource : messageResources) { String basename = resolveBasename(pathPrefix, resource); log.debug("Basename for bundle resource {} resolved as {}", resource.getDescription(), basename); if (basename != null) { basenames.add(basename);/* w w w . jav a2s.c o m*/ } } }
From source file:de.langmi.spring.batch.examples.readers.file.gzip.GZipBufferedReaderFactory.java
/** * Creates Bufferedreader for gzip Resource, handles normal resources * too./* ww w .jav a 2s .co m*/ * * @param resource * @param encoding * @return * @throws UnsupportedEncodingException * @throws IOException */ @Override public BufferedReader create(Resource resource, String encoding) throws UnsupportedEncodingException, IOException { for (String suffix : gzipSuffixes) { // test for filename and description, description is used when // handling itemStreamResources if (resource.getFilename().endsWith(suffix) || resource.getDescription().endsWith(suffix)) { return new BufferedReader( new InputStreamReader(new GZIPInputStream(resource.getInputStream()), encoding)); } } return new BufferedReader(new InputStreamReader(resource.getInputStream(), encoding)); }
From source file:org.obiba.onyx.spring.context.OnyxMessageSourceFactoryBean.java
protected MessageSource loadJarBundles() throws IOException { ResourcePatternResolver resolver = (ResourcePatternResolver) this.resourceLoader; String bundlePattern = ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX + "META-INF/" + MESSAGES_BUNDLENAME + "*" + MESSAGES_PROPERTIES_SUFFIX; Resource[] messageResources = resolver.getResources(bundlePattern); StaticMessageSource sms = new StaticMessageSource(); for (int i = 0; i < messageResources.length; i++) { Resource resource = messageResources[i]; Locale locale = extractLocale(resource, MESSAGES_PROPERTIES_SUFFIX); log.debug("Found module bundle resource {} with locale {}", resource.getDescription(), locale); Properties props = new Properties(); props.load(resource.getInputStream()); sms.addMessages(Maps.fromProperties(props), locale); }/* ww w. ja va2 s. c o m*/ return sms; }