Package org.springframework.core.io

Examples of org.springframework.core.io.ByteArrayResource


  }

  @Test
  public void testLoadArrayOfString() throws Exception {
    YamlPropertiesFactoryBean factory = new YamlPropertiesFactoryBean();
    factory.setResources(new ByteArrayResource("foo:\n- bar\n- baz"
        .getBytes()));
    Properties properties = factory.getObject();
    assertThat(properties.getProperty("foo[0]"), equalTo("bar"));
    assertThat(properties.getProperty("foo[1]"), equalTo("baz"));
  }
View Full Code Here


  }

  @Test
  public void testLoadArrayOfObject() throws Exception {
    YamlPropertiesFactoryBean factory = new YamlPropertiesFactoryBean();
    factory.setResources(new ByteArrayResource(
        "foo:\n- bar:\n    spam: crap\n- baz\n- one: two\n  three: four"
            .getBytes()
    ));
    Properties properties = factory.getObject();
    assertThat(properties.getProperty("foo[0].bar.spam"), equalTo("crap"));
View Full Code Here

    vefb.setResourceLoaderPath("file:/mydir");
    vefb.setResourceLoader(new ResourceLoader() {
      @Override
      public Resource getResource(String location) {
        if (location.equals("file:/mydir") || location.equals("file:/mydir/test")) {
          return new ByteArrayResource("test".getBytes(), "test");
        }
        try {
          return new UrlResource(location);
        }
        catch (MalformedURLException ex) {
View Full Code Here

      @Override
      public Resource getResource(String location) {
        if ("file:/yourdir/test".equals(location)) {
          return new DescriptiveResource("");
        }
        return new ByteArrayResource("test".getBytes(), "test");
      }
      @Override
      public ClassLoader getClassLoader() {
        return getClass().getClassLoader();
      }
View Full Code Here

      @Override
      public Resource getResource(String location) {
        if (!("file:/mydir".equals(location) || "file:/mydir/test".equals(location))) {
          throw new IllegalArgumentException(location);
        }
        return new ByteArrayResource("test".getBytes(), "test");
      }

      @Override
      public ClassLoader getClassLoader() {
        return getClass().getClassLoader();
View Full Code Here

    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@"));
  }
View Full Code Here

  @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()));
  }
View Full Code Here

   
    protected void runSql(final String sql) {
        if (simpleJdbcTemplate == null) {
            simpleJdbcTemplate = new SimpleJdbcTemplate(dataSource);
        }
        SimpleJdbcTestUtils.executeSqlScript(simpleJdbcTemplate, new ByteArrayResource(sql.getBytes()), false);
    }
View Full Code Here

            mimeMailMessage.setText(mailMessage.getBody().getContent());

            if (mailMessage.getBody().hasAttachments()) {
                for (AttachmentPart attachmentPart : mailMessage.getBody().getAttachments()) {
                    mimeMailMessage.getMimeMessageHelper().addAttachment(attachmentPart.getFileName(),
                            new ByteArrayResource(attachmentPart.getContent().getBytes(Charset.forName(attachmentPart.getCharsetName()))),
                            attachmentPart.getContentType());
                }
            }
        } catch (MessagingException e) {
            throw new CitrusRuntimeException("Failed to create mail mime message", e);
View Full Code Here

        TestEnvStatic.init();
    }

    @Before
    public void init() throws Exception {
        source = new ByteArrayResource("<hello></hello>".getBytes());
        illegalSource = new ByteArrayResource("<hello>".getBytes());
        transformer = new Transformer() {
            public void transform(Document document, String systemId) {
                document.getRootElement().addElement("world");
            }
        };
View Full Code Here

TOP

Related Classes of org.springframework.core.io.ByteArrayResource

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.