Spring Framework ByteArrayResource - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Spring Framework ByteArrayResource class.

This code example shows how to use the following methods:
		// Must now report back as having been modified 
		assertTrue("ResourceScriptSource must report back as being modified if the underlying File resource is reporting a changed lastModified time.", scriptSource.isModified());
	} 
 
	public void testLastModifiedWorksWithResourceThatDoesNotSupportFileBasedAccessAtAll() 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());
	} 
 
} 
7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:
		assertThat(ps.getName(), is("ps1"));
	} 
 
	@Test
	public void withResourceHavingNoDescriptionAndGeneratedName() throws IOException {
		PropertySource<?> ps = new ResourcePropertySource(new ByteArrayResource("foo=bar".getBytes(), ""));
		assertEquals(ps.getProperty("foo"), "bar");
		assertTrue(ps.getName().startsWith("ByteArrayResource@"));
	} 
 
} 
6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:
 
	@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()));
	} 
 
} 
7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:
 
	@Test
	public void testCreate() throws Exception {
		DefaultBufferedReaderFactory factory = new DefaultBufferedReaderFactory();
		@SuppressWarnings("resource") 
		BufferedReader reader = factory.create(new ByteArrayResource("a\nb\nc".getBytes()), "UTF-8");
		assertEquals("a", reader.readLine());
	} 
 
} 
6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:
 */ 
public class XmlValidatingMessageSelectorTests { 
 
	@Test
	public void validateCreationWithSchemaAndDefaultSchemaType() throws Exception{
		Resource resource = new ByteArrayResource("<xsd:schema xmlns:xsd='http://www.w3.org/2001/XMLSchema'/>".getBytes());
		new XmlValidatingMessageSelector(resource, (SchemaType) null);
	} 
 
	@Test
	public void validateCreationWithSchemaAndProvidedSchemaType() throws Exception{
		Resource resource = new ByteArrayResource("<xsd:schema xmlns:xsd='http://www.w3.org/2001/XMLSchema'/>".getBytes());
		new XmlValidatingMessageSelector(resource, SchemaType.XML_SCHEMA);
	} 
 
	@Test
	public void validateFailureInvalidSchemaLanguage() throws Exception{
		ConfigurableApplicationContext context = null;
		try { 
			context = new ClassPathXmlApplicationContext("XmlValidatingMessageSelectorTests-context.xml", this.getClass());
6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:
	@Override 
	protected Resource readInternal(Class<? extends Resource> clazz, HttpInputMessage inputMessage)
			throws IOException, HttpMessageNotReadableException {
 
		byte[] body = StreamUtils.copyToByteArray(inputMessage.getBody());
		return new ByteArrayResource(body);
	} 
 
	@Override 
	protected MediaType getDefaultContentType(Resource resource) {
		if (jafPresent) {
			return ActivationMediaTypeFactory.getMediaType(resource);
		} 
		else { 
			return MediaType.APPLICATION_OCTET_STREAM;
		} 
	} 
 
	@Override 
	protected Long getContentLength(Resource resource, MediaType contentType) throws IOException {
6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:
 
	@Test
	public void testCreate() throws Exception {
		SimpleBinaryBufferedReaderFactory factory = new SimpleBinaryBufferedReaderFactory();
		@SuppressWarnings("resource") 
		BufferedReader reader = factory.create(new ByteArrayResource("a\nb".getBytes()), "UTF-8");
		assertEquals("a", reader.readLine());
		assertEquals("b", reader.readLine());
		assertEquals(null, reader.readLine());
	} 
 
	@Test
	public void testCreateWithLineEnding() throws Exception {
		SimpleBinaryBufferedReaderFactory factory = new SimpleBinaryBufferedReaderFactory();
		factory.setLineEnding("||");
		@SuppressWarnings("resource") 
		BufferedReader reader = factory.create(new ByteArrayResource("a||b".getBytes()), "UTF-8");
		assertEquals("a", reader.readLine());
		assertEquals("b", reader.readLine());
		assertEquals(null, reader.readLine());
6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:
		loadContext("type='password' username='admin' access-token-uri='http://somewhere.com'"); 
	} 
 
	private void loadContext(String attributes) {
		String config = HEADER + String.format(TEMPLATE, attributes) + FOOTER;
		context = new GenericXmlApplicationContext(new ByteArrayResource(config .getBytes()));
	} 
 
	private static String HEADER = "<?xml version='1.0' encoding='UTF-8'?><beans xmlns='http://www.springframework.org/schema/beans' xmlns:oauth='http://www.springframework.org/schema/security/oauth2' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'	xsi:schemaLocation='http://www.springframework.org/schema/security/oauth2 http://www.springframework.org/schema/security/spring-security-oauth2-1.0.xsd	http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd'>";
	private static String FOOTER = "</beans>";
	private static String TEMPLATE = "<oauth:resource id='resource' client-id='client' %s/>";
} 
5
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:
 
	private ResourcesItemReader reader = new ResourcesItemReader();
 
	@Before 
	public void init() { 
		reader.setResources(new Resource[] { new ByteArrayResource("foo".getBytes()),
				new ByteArrayResource("bar".getBytes()) });
	} 
 
	@Test
	public void testRead() throws Exception {
		assertNotNull(reader.read());
	} 
 
	@Test
	public void testExhaustRead() throws Exception {
		for (int i = 0; i < 2; i++) {
			assertNotNull(reader.read());
		} 
		assertNull(reader.read());
5
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:
		 
	} 
 
	@Test
	public void testLoadNoUeis() { 
		Resource resource = new ByteArrayResource(xmlNoUeis.getBytes());
		 
		SyslogNorthbounderConfigDao dao = new SyslogNorthbounderConfigDao();
		dao.setConfigResource(resource);
		 
		dao.afterPropertiesSet();
		 
		SyslogNorthbounderConfig config = dao.getConfig();
		 
		assertNotNull(config);
		assertEquals(null, config.getUeis());
		assertTrue(config.getDestinations().get(0).isFirstOccurrenceOnly());
		 
	} 
	 
5
CodeRank
Connect your IDE to all the code out there  Get Codota for Java