Search in sources :

Example 56 with ByteArrayResource

use of org.springframework.core.io.ByteArrayResource in project jetty.project by eclipse.

the class SpringConfigurationProcessor method init.

@Override
public void init(URL url, XmlParser.Node config, XmlConfiguration configuration) {
    try {
        _configuration = configuration;
        Resource resource = url != null ? new UrlResource(url) : new ByteArrayResource(("" + "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "<!DOCTYPE beans PUBLIC \"-//SPRING//DTD BEAN//EN\" \"http://www.springframework.org/dtd/spring-beans.dtd\">" + config).getBytes(StandardCharsets.UTF_8));
        _beanFactory = new DefaultListableBeanFactory() {

            @Override
            protected void applyPropertyValues(String beanName, BeanDefinition mbd, BeanWrapper bw, PropertyValues pvs) {
                _configuration.initializeDefaults(bw.getWrappedInstance());
                super.applyPropertyValues(beanName, mbd, bw, pvs);
            }
        };
        new XmlBeanDefinitionReader(_beanFactory).loadBeanDefinitions(resource);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : BeanWrapper(org.springframework.beans.BeanWrapper) PropertyValues(org.springframework.beans.PropertyValues) UrlResource(org.springframework.core.io.UrlResource) XmlBeanDefinitionReader(org.springframework.beans.factory.xml.XmlBeanDefinitionReader) UrlResource(org.springframework.core.io.UrlResource) ByteArrayResource(org.springframework.core.io.ByteArrayResource) Resource(org.springframework.core.io.Resource) DefaultListableBeanFactory(org.springframework.beans.factory.support.DefaultListableBeanFactory) ByteArrayResource(org.springframework.core.io.ByteArrayResource) BeanDefinition(org.springframework.beans.factory.config.BeanDefinition)

Example 57 with ByteArrayResource

use of org.springframework.core.io.ByteArrayResource in project grails-core by grails.

the class GroovyPagesTemplateRenderer method generateScaffoldedTemplate.

private Template generateScaffoldedTemplate(GrailsWebRequest webRequest, String uri) throws IOException {
    Template t = null;
    Collection<String> controllerActions = scaffoldedActionMap.get(webRequest.getControllerName());
    if (controllerActions != null && controllerActions.contains(webRequest.getActionName())) {
        GrailsDomainClass domainClass = controllerToScaffoldedDomainClassMap.get(webRequest.getControllerName());
        if (domainClass != null) {
            int i = uri.lastIndexOf('/');
            String scaffoldedtemplateName = i > -1 ? uri.substring(i) : uri;
            if (scaffoldedtemplateName.toLowerCase().endsWith(".gsp")) {
                scaffoldedtemplateName = scaffoldedtemplateName.substring(0, scaffoldedtemplateName.length() - 4);
            }
            FastStringWriter sw = new FastStringWriter();
            ReflectionUtils.invokeMethod(generateViewMethod, scaffoldingTemplateGenerator, domainClass, scaffoldedtemplateName, sw);
            t = groovyPagesTemplateEngine.createTemplate(new ByteArrayResource(sw.toString().getBytes("UTF-8"), uri), false);
        }
    }
    return t;
}
Also used : FastStringWriter(org.grails.buffer.FastStringWriter) GrailsDomainClass(grails.core.GrailsDomainClass) ByteArrayResource(org.springframework.core.io.ByteArrayResource) Template(groovy.text.Template)

Example 58 with ByteArrayResource

use of org.springframework.core.io.ByteArrayResource in project spring-framework by spring-projects.

the class ResourceRegionHttpMessageWriterTests method setUp.

@Before
public void setUp() throws Exception {
    String content = "Spring Framework test resource content.";
    this.resource = new ByteArrayResource(content.getBytes(StandardCharsets.UTF_8));
}
Also used : ByteArrayResource(org.springframework.core.io.ByteArrayResource) Before(org.junit.Before)

Example 59 with ByteArrayResource

use of org.springframework.core.io.ByteArrayResource in project spring-framework by spring-projects.

the class ResourceHttpMessageConverterTests method writeByteArrayNullMediaType.

// SPR-10848
@Test
public void writeByteArrayNullMediaType() throws IOException {
    MockHttpOutputMessage outputMessage = new MockHttpOutputMessage();
    byte[] byteArray = { 1, 2, 3 };
    Resource body = new ByteArrayResource(byteArray);
    converter.write(body, null, outputMessage);
    assertTrue(Arrays.equals(byteArray, outputMessage.getBodyAsBytes()));
}
Also used : MockHttpOutputMessage(org.springframework.http.MockHttpOutputMessage) ClassPathResource(org.springframework.core.io.ClassPathResource) ByteArrayResource(org.springframework.core.io.ByteArrayResource) InputStreamResource(org.springframework.core.io.InputStreamResource) Resource(org.springframework.core.io.Resource) ByteArrayResource(org.springframework.core.io.ByteArrayResource) Test(org.junit.Test)

Example 60 with ByteArrayResource

use of org.springframework.core.io.ByteArrayResource in project spring-framework by spring-projects.

the class ResourceScriptSourceTests method lastModifiedWorksWithResourceThatDoesNotSupportFileBasedAccessAtAll.

@Test
public void lastModifiedWorksWithResourceThatDoesNotSupportFileBasedAccessAtAll() throws Exception {
    Resource resource = new ByteArrayResource(new byte[0]);
    ResourceScriptSource scriptSource = new ResourceScriptSource(resource);
    assertTrue("ResourceScriptSource must start off in the 'isModified' state (it obviously isn't).", scriptSource.isModified());
    scriptSource.getScriptAsString();
    assertFalse("ResourceScriptSource must not report back as being modified if the underlying File resource is not reporting a changed lastModified time.", scriptSource.isModified());
    // Must now continue to report back as not having been modified 'cos the Resource does not support access as a File (and so the lastModified date cannot be determined).
    assertFalse("ResourceScriptSource must not report back as being modified if the underlying File resource is not reporting a changed lastModified time.", scriptSource.isModified());
}
Also used : ByteArrayResource(org.springframework.core.io.ByteArrayResource) Resource(org.springframework.core.io.Resource) ByteArrayResource(org.springframework.core.io.ByteArrayResource) Test(org.junit.Test)

Aggregations

ByteArrayResource (org.springframework.core.io.ByteArrayResource)95 Test (org.junit.Test)67 Resource (org.springframework.core.io.Resource)32 Properties (java.util.Properties)26 IOException (java.io.IOException)6 InputStream (java.io.InputStream)6 JmsNorthbounderConfig (org.opennms.netmgt.alarmd.northbounder.jms.JmsNorthbounderConfig)6 JmsNorthbounderConfigDao (org.opennms.netmgt.alarmd.northbounder.jms.JmsNorthbounderConfigDao)6 InetAddress (java.net.InetAddress)5 ArrayList (java.util.ArrayList)5 LinkedList (java.util.LinkedList)5 Before (org.junit.Before)5 NorthboundAlarm (org.opennms.netmgt.alarmd.api.NorthboundAlarm)5 JmsDestination (org.opennms.netmgt.alarmd.northbounder.jms.JmsDestination)5 OnmsAlarm (org.opennms.netmgt.model.OnmsAlarm)5 OnmsIpInterface (org.opennms.netmgt.model.OnmsIpInterface)5 OnmsNode (org.opennms.netmgt.model.OnmsNode)5 LinkedHashMap (java.util.LinkedHashMap)4 Map (java.util.Map)4 MutablePropertySources (org.springframework.core.env.MutablePropertySources)4