Example usage for org.springframework.util StreamUtils copyToString

List of usage examples for org.springframework.util StreamUtils copyToString

Introduction

In this page you can find the example usage for org.springframework.util StreamUtils copyToString.

Prototype

public static String copyToString(@Nullable InputStream in, Charset charset) throws IOException 

Source Link

Document

Copy the contents of the given InputStream into a String.

Usage

From source file:com.github.ukase.TestHelper.java

private static String getFileContent(String fileName, ClassLoader loader) throws IOException {
    InputStream stream = loader.getResourceAsStream(fileName);
    return StreamUtils.copyToString(stream, Charset.forName("UTF-8"));
}

From source file:hu.petabyte.redflags.engine.RedflagsEngineApp.java

private static void exportConfig(String fn) {
    try {/*w  w  w. j a  v  a2s. c o  m*/
        StreamUtils.copyToString(new ClassPathResource("application.yml").getInputStream(),
                Charset.forName("UTF-8"));
        System.out.println("Internal application.yml copied out to " + fn);
    } catch (IOException e) {
        System.out.println("Operation failed: " + e.getMessage());
    }
}

From source file:org.zalando.github.spring.AbstractTemplateTest.java

public static String resourceToString(Resource resource) throws IOException {
    return StreamUtils.copyToString(resource.getInputStream(), Charset.defaultCharset());
}

From source file:hu.petabyte.redflags.web.cfg.DefaultUsers.java

@Override
public void afterPropertiesSet() throws Exception {
    String sql = StreamUtils.copyToString(sqlFile.getInputStream(), Charset.forName("UTF-8"));
    jdbc.execute(sql);// ww w .jav a 2s  .c  om

    // Why we need it this way: because the original JPA version was working
    // differently on different servers. On the first server it replaced
    // existing records (good), on the other server, it added new ones.
}

From source file:com.github.ukase.toolkit.jar.ZipTemplateSource.java

@Override
public String content() throws IOException {
    return StreamUtils.copyToString(zip.getInputStream(entry), Charset.forName("UTF-8"));
}

From source file:io.spring.initializr.test.generator.SourceCodeAssert.java

public SourceCodeAssert equalsTo(Resource expected) {
    try (InputStream stream = expected.getInputStream()) {
        String expectedContent = StreamUtils.copyToString(stream, Charset.forName("UTF-8"));
        assertThat(this.content).describedAs("Content for %s", this.name)
                .isEqualTo(expectedContent.replaceAll("\r\n", "\n"));
    } catch (IOException e) {
        throw new IllegalStateException("Cannot read file", e);
    }/*ww w  .  j a va 2s. c  o  m*/
    return this;
}

From source file:com.cisco.cta.taxii.adapter.TcpServer.java

@Override
public void run() {
    while (!closed) {
        try (Socket socket = serverSocket.accept(); InputStream in = socket.getInputStream()) {
            message = StreamUtils.copyToString(in, CHARSET);
            connectionCount++;//from  w  w  w .  ja  v  a  2 s .  com
        } catch (SocketException e) {
            // closing server - do nothing
        } catch (Exception e) {
            errorCount++;
            e.printStackTrace();
        }
    }
}

From source file:io.spring.initializr.scs.generator.utils.MavenUtilsTests.java

@Test
public void test() throws IOException, XmlPullParserException {

    final InputStream is = MavenUtilsTests.class.getResourceAsStream("/test-pom.xml");

    final ByteArrayOutputStream bos = new ByteArrayOutputStream();

    MavenUtils.addDockerPlugin(is, bos);

    final String result = new String(bos.toByteArray(), Charset.forName("utf-8"));

    final InputStream comparisonFile = MavenUtilsTests.class
            .getResourceAsStream("/test-pom-with-docker-plugin.xml");
    final String pomWithDockerPlugin = StreamUtils.copyToString(comparisonFile, Charset.forName("utf-8"));
    Assert.assertEquals(pomWithDockerPlugin, result);
}

From source file:com.dickthedeployer.dick.web.service.RepositoryServiceTest.java

@Test
public void shouldCloneRepository() throws IOException {
    InputStream file = service.getFile(
            new Build.Builder().withProject(new Project.Builder().withName("dick-the-deployer/dick").build())
                    .withRepository("https://github.com/dick-the-deployer/dick.git").withRef("master")
                    .withSha("74ab161c6b4df731ded57dd434c8df120d140832").build(),
            ".dick.yml");

    String content = StreamUtils.copyToString(file, Charsets.UTF_8);
    assertThat(content).isNotNull().contains("foo: bar");
}

From source file:hu.petabyte.redflags.web.ctrl.IndexCtrl.java

@RequestMapping("/robots.txt")
@ResponseBody/*  w  w w . j a v  a 2 s  .  c o  m*/
public String robots() {
    try {
        return StreamUtils.copyToString(robotsTxt.getInputStream(), Charset.forName("UTF-8"));
    } catch (IOException e) {
        return "";
    }
}