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);
}
}
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;
}
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));
}
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()));
}
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());
}
Aggregations