Example usage for org.springframework.core.io AbstractResource AbstractResource

List of usage examples for org.springframework.core.io AbstractResource AbstractResource

Introduction

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

Prototype

AbstractResource

Source Link

Usage

From source file:ar.com.zauber.commons.spring.configurers.SystemPropertyPlaceholderConfigurer.java

/** constructor */
public SystemPropertyPlaceholderConfigurer() {
    setLocation(new AbstractResource() {
        public String getDescription() {
            return "system properties";
        }//from   www . j a  v  a 2  s  . c om

        public InputStream getInputStream() throws IOException {
            final ByteArrayOutputStream os = new ByteArrayOutputStream();
            System.getProperties().store(os, null);
            return new ByteArrayInputStream(os.toByteArray());
        }

        /** @see AbstractResource#getFilename() */
        @Override
        public String getFilename() throws IllegalStateException {
            return "system.properties";
        }
    });
}

From source file:org.cloudfoundry.identity.uaa.config.YamlMapFactoryBeanTests.java

@Test
public void testFirstFound() throws Exception {
    factory.setResolutionMethod(ResolutionMethod.FIRST_FOUND);
    factory.setResources(new Resource[] { new AbstractResource() {
        @Override/*from  www. j  a  va  2 s  . co m*/
        public String getDescription() {
            return "non-existent";
        }

        @Override
        public InputStream getInputStream() throws IOException {
            throw new IOException("planned");
        }
    }, new ByteArrayResource("foo:\n  spam: bar".getBytes()) });
    assertEquals(1, factory.getObject().size());
}

From source file:com.opengamma.component.ComponentManager.java

/**
 * Intelligently sets the property to the merged set of properties.
 * <p>//w ww  .  java  2s  . c om
 * The key "MANAGER.PROPERTIES" can be used in a properties file to refer to
 * the entire set of merged properties. This is normally what you want to pass
 * into other systems (such as Spring) that need a set of properties.
 * 
 * @param bean  the bean, not null
 * @param mp  the property, not null
 * @throws Exception allowing throwing of a checked exception
 */
protected void setPropertyMergedProperties(Bean bean, MetaProperty<?> mp) throws Exception {
    final String desc = MANAGER_PROPERTIES + " for " + mp;
    final ByteArrayOutputStream out = new ByteArrayOutputStream(1024);
    Properties props = new Properties();
    props.putAll(getProperties());
    props.store(out, desc);
    out.close();
    Resource resource = new AbstractResource() {
        @Override
        public String getDescription() {
            return MANAGER_PROPERTIES;
        }

        @Override
        public String getFilename() throws IllegalStateException {
            return MANAGER_PROPERTIES + ".properties";
        }

        @Override
        public InputStream getInputStream() throws IOException {
            return new ByteArrayInputStream(out.toByteArray());
        }

        @Override
        public String toString() {
            return desc;
        }
    };
    mp.set(bean, resource);
}

From source file:de.codesourcery.spring.contextrewrite.XMLRewrite.java

/**
 * Transforms XML according to a given <code>RewriteConfig</code>.
 *  //www.jav a 2  s .  c o m
 * @param resource
 * @param config
 * @return Resource that provides the transformed XML.
 * @throws Exception
 */
public Resource filterResource(Resource resource, RewriteConfig config) throws Exception {
    Validate.notNull(resource, "resource must not be NULL");
    Validate.notNull(config, "config must not be NULL");

    final boolean dumpRewrittenXML = config.isDumpXML();
    this.debugEnabled = config.isDebug();

    final List<Rule> rules = config.getRules();

    // parse XML
    final Document doc = parseXML(resource, rules);

    // rewrite XML
    rewriteXML(doc, rules, true, true);

    // write XML to byte[] array
    final byte[] data = toByteArray(doc, false);

    if (dumpRewrittenXML) {
        final String[] lines = new String(data).split("\n");
        int no = 1;
        for (String line : lines) {
            System.out.println(no + ":   " + line);
            no++;
        }
    }
    return new AbstractResource() {
        @Override
        public String getDescription() {
            return "Spring XML filtered from " + resource;
        }

        @Override
        public InputStream getInputStream() throws IOException {
            return new ByteArrayInputStream(data);
        }
    };
}

From source file:org.craftercms.engine.controller.StaticAssetsRequestHandler.java

protected Resource toResource(Content content, String path) {
    return new AbstractResource() {

        @Override//from  w ww  . j ava 2s  .c o  m
        public String getFilename() {
            return FilenameUtils.getName(path);
        }

        @Override
        public long lastModified() throws IOException {
            return content.getLastModified();
        }

        @Override
        public long contentLength() throws IOException {
            return content.getLength();
        }

        @Override
        public String getDescription() {
            return null;
        }

        @Override
        public InputStream getInputStream() throws IOException {
            return content.getInputStream();
        }

    };
}