org.springframework.util.FileCopyUtils.copyToString()

Here are the examples of the java api org.springframework.util.FileCopyUtils.copyToString() taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

89 Examples 7

19 Source : FileUtil.java
with BSD 3-Clause "New" or "Revised" License
from zzt93

public static String readAll(InputStream inputStream) throws IOException {
    return FileCopyUtils.copyToString(new InputStreamReader(inputStream));
}

19 Source : FileUtil.java
with BSD 3-Clause "New" or "Revised" License
from zzt93

public static String readAll(String resourceName) throws IOException {
    return FileCopyUtils.copyToString(new InputStreamReader(getResource(resourceName).getInputStream()));
}

19 Source : AbstractApplicationLauncher.java
with Apache License 2.0
from yuanmabiji

private int awaitServerPort(Process process, File serverPortFile) throws Exception {
    long end = System.currentTimeMillis() + 30000;
    while (serverPortFile.length() == 0) {
        if (System.currentTimeMillis() > end) {
            throw new IllegalStateException("server.port file was not written within 30 seconds");
        }
        if (!process.isAlive()) {
            throw new IllegalStateException("Application failed to launch");
        }
        Thread.sleep(100);
    }
    return Integer.parseInt(FileCopyUtils.copyToString(new FileReader(serverPortFile)));
}

19 Source : TestProject.java
with Apache License 2.0
from yuanmabiji

/**
 * Add source code at the end of file, just before last '}'
 * @param target the target
 * @param snippetStream the snippet stream
 * @throws Exception if the source cannot be added
 */
public void addSourceCode(Clreplaced<?> target, InputStream snippetStream) throws Exception {
    File targetFile = getSourceFile(target);
    String contents = getContents(targetFile);
    int insertAt = contents.lastIndexOf('}');
    String additionalSource = FileCopyUtils.copyToString(new InputStreamReader(snippetStream));
    contents = contents.substring(0, insertAt) + additionalSource + contents.substring(insertAt);
    putContents(targetFile, contents);
}

19 Source : TestProject.java
with Apache License 2.0
from yuanmabiji

private static String getContents(File file) throws Exception {
    return FileCopyUtils.copyToString(new FileReader(file));
}

19 Source : JsonLoader.java
with Apache License 2.0
from yuanmabiji

String getJson(InputStream source) {
    try {
        return FileCopyUtils.copyToString(new InputStreamReader(source, this.charset));
    } catch (IOException ex) {
        throw new IllegalStateException("Unable to load JSON from InputStream", ex);
    }
}

19 Source : LogbackLoggingSystemTests.java
with Apache License 2.0
from yuanmabiji

@Test
public void exceptionsIncludeClreplacedPackaging() throws Exception {
    this.loggingSystem.beforeInitialize();
    this.loggingSystem.initialize(this.initializationContext, null, getLogFile(null, tmpDir()));
    Matcher<String> expectedOutput = containsString("[junit-");
    this.output.expect(expectedOutput);
    this.logger.warn("Expected exception", new RuntimeException("Expected"));
    String fileContents = FileCopyUtils.copyToString(new FileReader(new File(tmpDir() + "/spring.log")));
    replacedertThat(fileContents).is(Matched.by(expectedOutput));
}

19 Source : LogbackLoggingSystemTests.java
with Apache License 2.0
from yuanmabiji

private String getLineWithText(File file, String outputSearch) throws Exception {
    return getLineWithText(FileCopyUtils.copyToString(new FileReader(file)), outputSearch);
}

19 Source : ScriptTemplateView.java
with MIT License
from Vip-Augus

protected String getTemplate(String path) throws IOException {
    Resource resource = getResource(path);
    if (resource == null) {
        throw new IllegalStateException("Template resource [" + path + "] not found");
    }
    InputStreamReader reader = (this.charset != null ? new InputStreamReader(resource.getInputStream(), this.charset) : new InputStreamReader(resource.getInputStream()));
    return FileCopyUtils.copyToString(reader);
}

19 Source : ScriptTemplateView.java
with MIT License
from Vip-Augus

protected String getTemplate(String path) throws IOException {
    Resource resource = getResource(path);
    if (resource == null) {
        throw new IllegalStateException("Template resource [" + path + "] not found");
    }
    InputStreamReader reader = new InputStreamReader(resource.getInputStream(), getDefaultCharset());
    return FileCopyUtils.copyToString(reader);
}

19 Source : SpringDocTestApp.java
with Apache License 2.0
from springdoc

public static String replacedtring(Resource resource) {
    try (Reader reader = new InputStreamReader(resource.getInputStream())) {
        return FileCopyUtils.copyToString(reader);
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}

19 Source : JsonClientCacheDataImporterExporterIntegrationTests.java
with Apache License 2.0
from spring-projects

private static String loadJson(String resourcePath) throws IOException {
    return FileCopyUtils.copyToString(new InputStreamReader(new ClreplacedPathResource(resourcePath).getInputStream()));
}

19 Source : ChangelogGeneratorTests.java
with Apache License 2.0
from spring-io

private String from(String path) throws IOException {
    return FileCopyUtils.copyToString(new InputStreamReader(getClreplaced().getResourcereplacedtream(path)));
}

19 Source : HttpArtifactoryBuildRunsTests.java
with Apache License 2.0
from spring-io

private RequestMatcher jsonContent(Resource expected) {
    return (request) -> {
        String actualJson = ((MockClientHttpRequest) request).getBodyreplacedtring();
        String expectedJson = FileCopyUtils.copyToString(new InputStreamReader(expected.getInputStream(), Charset.forName("UTF-8")));
        replacedertJson(actualJson, expectedJson);
    };
}

19 Source : SystemInput.java
with Apache License 2.0
from spring-io

public <T> T read(Clreplaced<T> type) throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(this.systemStreams.in()));
    long startTime = System.currentTimeMillis();
    while (!in.ready()) {
        replacedert.state(System.currentTimeMillis() - startTime < this.timeout, "Timeout waiting for input");
    }
    String content = FileCopyUtils.copyToString(in);
    String resolved = this.environment.resolvePlaceholders(content);
    return this.objectMapper.readValue(new StringReader(resolved), type);
}

19 Source : ScriptTemplateView.java
with Apache License 2.0
from langtianya

protected String getTemplate(String path) throws IOException {
    Resource resource = this.resourceLoader.getResource(path);
    InputStreamReader reader = new InputStreamReader(resource.getInputStream(), this.charset);
    return FileCopyUtils.copyToString(reader);
}

19 Source : LocksApplication.java
with Apache License 2.0
from joshlong

String read() throws Exception {
    try (var r = new BufferedReader(new FileReader(this.file))) {
        return FileCopyUtils.copyToString(r);
    }
}

19 Source : DataBuffers.java
with MIT License
from jbrixhe

public static String readToString(DataBuffer dataBuffer) {
    try {
        return FileCopyUtils.copyToString(new InputStreamReader(dataBuffer.asInputStream()));
    } catch (IOException e) {
        return e.getMessage();
    }
}

19 Source : RF2ToOWLService.java
with Apache License 2.0
from IHTSDO

protected String getCopyrightNotice() throws IOException {
    return FileCopyUtils.copyToString(new InputStreamReader(getClreplaced().getResourcereplacedtream("/owl-file-copyright-notice.txt")));
}

19 Source : SymphonyNotificator.java
with Apache License 2.0
from finos

public static String replacedtring(Resource resource) {
    try (Reader reader = new InputStreamReader(resource.getInputStream(), Charsets.UTF_8)) {
        return FileCopyUtils.copyToString(reader);
    } catch (IOException e) {
        log.error("Couldn't load clreplacedpath template: ", e);
        throw new UncheckedIOException(e);
    }
}

19 Source : ResourceReader.java
with MIT License
from FAIRDataTeam

public static String loadResource(Resource resource) {
    try (Reader reader = new InputStreamReader(resource.getInputStream(), UTF_8)) {
        return FileCopyUtils.copyToString(reader);
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}

19 Source : PaymentTOMapperTest.java
with Apache License 2.0
from adorsys

private String readPayment(String file) throws IOException {
    ResourceLoader loader = new DefaultResourceLoader();
    Resource resource = loader.getResource(file);
    try (Reader reader = new InputStreamReader(resource.getInputStream(), UTF_8)) {
        return FileCopyUtils.copyToString(reader);
    } catch (IOException e) {
        log.error("Cant read file");
        throw e;
    }
}

18 Source : PomCondition.java
with Apache License 2.0
from yuanmabiji

@Override
public boolean matches(File pom) {
    try {
        String contents = FileCopyUtils.copyToString(new FileReader(pom));
        for (String expected : this.expectedContents) {
            if (!contents.contains(expected)) {
                return false;
            }
        }
        for (String notExpected : this.notExpectedContents) {
            if (contents.contains(notExpected)) {
                return false;
            }
        }
    } catch (IOException ex) {
        throw new RuntimeException(ex);
    }
    return true;
}

18 Source : PackagingDocumentationTests.java
with Apache License 2.0
from yuanmabiji

@Test
public void bootJarIncludeLaunchScript() throws IOException {
    this.gradleBuild.script("src/main/gradle/packaging/boot-jar-include-launch-script").build("bootJar");
    File file = new File(this.gradleBuild.getProjectDir(), "build/libs/" + this.gradleBuild.getProjectDir().getName() + ".jar");
    replacedertThat(file).isFile();
    replacedertThat(FileCopyUtils.copyToString(new FileReader(file))).startsWith("#!/bin/bash");
}

18 Source : PackagingDocumentationTests.java
with Apache License 2.0
from yuanmabiji

@Test
public void bootJarLaunchScriptProperties() throws IOException {
    this.gradleBuild.script("src/main/gradle/packaging/boot-jar-launch-script-properties").build("bootJar");
    File file = new File(this.gradleBuild.getProjectDir(), "build/libs/" + this.gradleBuild.getProjectDir().getName() + ".jar");
    replacedertThat(file).isFile();
    replacedertThat(FileCopyUtils.copyToString(new FileReader(file))).contains("example-app.log");
}

18 Source : ContentContainingCondition.java
with Apache License 2.0
from yuanmabiji

@Override
public boolean matches(File value) {
    try (Reader reader = new FileReader(value)) {
        String content = FileCopyUtils.copyToString(reader);
        return content.contains(this.toContain);
    } catch (IOException ex) {
        throw new IllegalStateException(ex);
    }
}

18 Source : WebServerPortFileWriterTest.java
with Apache License 2.0
from yuanmabiji

@Test
public void overridePortFileWithDefault() throws Exception {
    System.setProperty("PORTFILE", this.temporaryFolder.newFile().getAbsolutePath());
    WebServerPortFileWriter listener = new WebServerPortFileWriter();
    listener.onApplicationEvent(mockEvent("", 8080));
    FileReader reader = new FileReader(System.getProperty("PORTFILE"));
    replacedertThat(FileCopyUtils.copyToString(reader)).isEqualTo("8080");
}

18 Source : ApplicationPidTests.java
with Apache License 2.0
from yuanmabiji

@Test
public void writeNewPid() throws Exception {
    // gh-10784
    ApplicationPid pid = new ApplicationPid("123");
    File file = this.temporaryFolder.newFile();
    file.delete();
    pid.write(file);
    String actual = FileCopyUtils.copyToString(new FileReader(file));
    replacedertThat(actual).isEqualTo("123");
}

18 Source : ApplicationPidTests.java
with Apache License 2.0
from yuanmabiji

@Test
public void writePid() throws Exception {
    ApplicationPid pid = new ApplicationPid("123");
    File file = this.temporaryFolder.newFile();
    pid.write(file);
    String actual = FileCopyUtils.copyToString(new FileReader(file));
    replacedertThat(actual).isEqualTo("123");
}

18 Source : LogbackLoggingSystemTests.java
with Apache License 2.0
from yuanmabiji

@Test
public void customExceptionConversionWord() throws Exception {
    System.setProperty(LoggingSystemProperties.EXCEPTION_CONVERSION_WORD, "%ex");
    try {
        this.loggingSystem.beforeInitialize();
        this.logger.info("Hidden");
        this.loggingSystem.initialize(this.initializationContext, null, getLogFile(null, tmpDir()));
        Matcher<String> expectedOutput = Matchers.allOf(containsString("java.lang.RuntimeException: Expected"), not(containsString("Wrapped by:")));
        this.output.expect(expectedOutput);
        this.logger.warn("Expected exception", new RuntimeException("Expected", new RuntimeException("Cause")));
        String fileContents = FileCopyUtils.copyToString(new FileReader(new File(tmpDir() + "/spring.log")));
        replacedertThat(fileContents).is(Matched.by(expectedOutput));
    } finally {
        System.clearProperty(LoggingSystemProperties.EXCEPTION_CONVERSION_WORD);
    }
}

18 Source : MockHttpServletRequestTests.java
with MIT License
from Vip-Augus

@Test
public void setContentAndGetReader() throws IOException {
    byte[] bytes = "body".getBytes(Charset.defaultCharset());
    request.setContent(bytes);
    replacedertEquals(bytes.length, request.getContentLength());
    replacedertEquals("body", FileCopyUtils.copyToString(request.getReader()));
    request.setContent(bytes);
    replacedertEquals(bytes.length, request.getContentLength());
    replacedertEquals("body", FileCopyUtils.copyToString(request.getReader()));
}

18 Source : PassThroughClob.java
with MIT License
from Vip-Augus

@Override
public InputStream getAsciiStream() throws SQLException {
    try {
        if (this.content != null) {
            return new ByteArrayInputStream(this.content.getBytes(StandardCharsets.US_ASCII));
        } else if (this.characterStream != null) {
            String tempContent = FileCopyUtils.copyToString(this.characterStream);
            return new ByteArrayInputStream(tempContent.getBytes(StandardCharsets.US_ASCII));
        } else {
            return (this.asciiStream != null ? this.asciiStream : StreamUtils.emptyInput());
        }
    } catch (IOException ex) {
        throw new SQLException("Failed to read stream content: " + ex);
    }
}

18 Source : ResourceTests.java
with MIT License
from Vip-Augus

@Test
public void testInputStreamResource() throws IOException {
    InputStream is = new ByteArrayInputStream("testString".getBytes());
    Resource resource = new InputStreamResource(is);
    replacedertTrue(resource.exists());
    replacedertTrue(resource.isOpen());
    String content = FileCopyUtils.copyToString(new InputStreamReader(resource.getInputStream()));
    replacedertEquals("testString", content);
    replacedertEquals(resource, new InputStreamResource(is));
}

18 Source : ResourceTests.java
with MIT License
from Vip-Augus

@Test
public void testInputStreamResourceWithDescription() throws IOException {
    InputStream is = new ByteArrayInputStream("testString".getBytes());
    Resource resource = new InputStreamResource(is, "my description");
    replacedertTrue(resource.exists());
    replacedertTrue(resource.isOpen());
    String content = FileCopyUtils.copyToString(new InputStreamReader(resource.getInputStream()));
    replacedertEquals("testString", content);
    replacedertTrue(resource.getDescription().contains("my description"));
    replacedertEquals(resource, new InputStreamResource(is));
}

18 Source : ResourceTests.java
with MIT License
from Vip-Augus

@Test
public void testByteArrayResourceWithDescription() throws IOException {
    Resource resource = new ByteArrayResource("testString".getBytes(), "my description");
    replacedertTrue(resource.exists());
    replacedertFalse(resource.isOpen());
    String content = FileCopyUtils.copyToString(new InputStreamReader(resource.getInputStream()));
    replacedertEquals("testString", content);
    replacedertTrue(resource.getDescription().contains("my description"));
    replacedertEquals(resource, new ByteArrayResource("testString".getBytes()));
}

18 Source : ResourceTests.java
with MIT License
from Vip-Augus

@Test
public void testByteArrayResource() throws IOException {
    Resource resource = new ByteArrayResource("testString".getBytes());
    replacedertTrue(resource.exists());
    replacedertFalse(resource.isOpen());
    String content = FileCopyUtils.copyToString(new InputStreamReader(resource.getInputStream()));
    replacedertEquals("testString", content);
    replacedertEquals(resource, new ByteArrayResource("testString".getBytes()));
}

18 Source : ClassPathXmlApplicationContextTests.java
with MIT License
from Vip-Augus

private void checkExceptionFromInvalidValueType(Throwable ex) throws IOException {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ex.printStackTrace(new PrintStream(baos));
    String dump = FileCopyUtils.copyToString(new InputStreamReader(new ByteArrayInputStream(baos.toByteArray())));
    replacedertTrue(dump.contains("someMessageSource"));
    replacedertTrue(dump.contains("useCodeAsDefaultMessage"));
}

18 Source : ResourceScriptSource.java
with MIT License
from Vip-Augus

@Override
public String getScriptreplacedtring() throws IOException {
    synchronized (this.lastModifiedMonitor) {
        this.lastModified = retrieveLastModifiedTime();
    }
    Reader reader = this.resource.getReader();
    return FileCopyUtils.copyToString(reader);
}

18 Source : RawR2dbcApplication.java
with Apache License 2.0
from spring-tips

private static String readFileToString(Resource resource) throws IOException {
    try (Reader reader = new InputStreamReader(resource.getInputStream())) {
        return FileCopyUtils.copyToString(reader);
    }
}

18 Source : AbstractLambdaCompilingProxy.java
with Apache License 2.0
from spring-cloud

@Override
public void afterPropertiesSet() throws Exception {
    String lambda = FileCopyUtils.copyToString(new InputStreamReader(this.resource.getInputStream()));
    this.factory = this.compiler.compile(this.beanName, lambda, this.typeParameterizations);
}

18 Source : ResourceTests.java
with Apache License 2.0
from SourceHot

@Test
void inputStreamResourceWithDescription() throws IOException {
    InputStream is = new ByteArrayInputStream("testString".getBytes());
    Resource resource = new InputStreamResource(is, "my description");
    replacedertThat(resource.exists()).isTrue();
    replacedertThat(resource.isOpen()).isTrue();
    String content = FileCopyUtils.copyToString(new InputStreamReader(resource.getInputStream()));
    replacedertThat(content).isEqualTo("testString");
    replacedertThat(resource.getDescription().contains("my description")).isTrue();
    replacedertThat(new InputStreamResource(is)).isEqualTo(resource);
}

18 Source : ResourceTests.java
with Apache License 2.0
from SourceHot

@Test
void inputStreamResource() throws IOException {
    InputStream is = new ByteArrayInputStream("testString".getBytes());
    Resource resource = new InputStreamResource(is);
    replacedertThat(resource.exists()).isTrue();
    replacedertThat(resource.isOpen()).isTrue();
    String content = FileCopyUtils.copyToString(new InputStreamReader(resource.getInputStream()));
    replacedertThat(content).isEqualTo("testString");
    replacedertThat(new InputStreamResource(is)).isEqualTo(resource);
}

18 Source : ResourceTests.java
with Apache License 2.0
from SourceHot

@Test
void byteArrayResourceWithDescription() throws IOException {
    Resource resource = new ByteArrayResource("testString".getBytes(), "my description");
    replacedertThat(resource.exists()).isTrue();
    replacedertThat(resource.isOpen()).isFalse();
    String content = FileCopyUtils.copyToString(new InputStreamReader(resource.getInputStream()));
    replacedertThat(content).isEqualTo("testString");
    replacedertThat(resource.getDescription().contains("my description")).isTrue();
    replacedertThat(new ByteArrayResource("testString".getBytes())).isEqualTo(resource);
}

18 Source : ResourceTests.java
with Apache License 2.0
from SourceHot

@Test
void byteArrayResource() throws IOException {
    Resource resource = new ByteArrayResource("testString".getBytes());
    replacedertThat(resource.exists()).isTrue();
    replacedertThat(resource.isOpen()).isFalse();
    String content = FileCopyUtils.copyToString(new InputStreamReader(resource.getInputStream()));
    replacedertThat(content).isEqualTo("testString");
    replacedertThat(new ByteArrayResource("testString".getBytes())).isEqualTo(resource);
}

18 Source : ClassPathXmlApplicationContextTests.java
with Apache License 2.0
from SourceHot

private void checkExceptionFromInvalidValueType(Throwable ex) {
    try {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        ex.printStackTrace(new PrintStream(baos));
        String dump = FileCopyUtils.copyToString(new InputStreamReader(new ByteArrayInputStream(baos.toByteArray())));
        replacedertThat(dump.contains("someMessageSource")).isTrue();
        replacedertThat(dump.contains("useCodeAsDefaultMessage")).isTrue();
    } catch (IOException ioex) {
        throw new IllegalStateException(ioex);
    }
}

18 Source : PassThroughClob.java
with Apache License 2.0
from langtianya

@Override
public InputStream getAsciiStream() throws SQLException {
    try {
        if (this.content != null) {
            return new ByteArrayInputStream(this.content.getBytes("US-ASCII"));
        } else if (this.characterStream != null) {
            String tempContent = FileCopyUtils.copyToString(this.characterStream);
            return new ByteArrayInputStream(tempContent.getBytes("US-ASCII"));
        } else {
            return this.asciiStream;
        }
    } catch (UnsupportedEncodingException ex) {
        throw new SQLException("US-ASCII encoding not supported: " + ex);
    } catch (IOException ex) {
        throw new SQLException("Failed to read stream content: " + ex);
    }
}

18 Source : ResourceLoaderAwsTest.java
with Apache License 2.0
from awspring

@Test
void testUploadAndDownloadOfSmallFileWithInjectedResourceLoader() throws Exception {
    String bucketName = this.stackResourceRegistry.lookupPhysicalResourceId("EmptyBucket");
    uploadFileTestFile(bucketName, "testUploadAndDownloadOfSmallFileWithInjectedResourceLoader", "hello world");
    Resource resource = this.resourceLoader.getResource(S3_PREFIX + bucketName + "/testUploadAndDownloadOfSmallFileWithInjectedResourceLoader");
    replacedertThat(resource.exists()).isTrue();
    InputStream inputStream = resource.getInputStream();
    replacedertThat(inputStream).isNotNull();
    replacedertThat(FileCopyUtils.copyToString(new InputStreamReader(inputStream, "UTF-8"))).isEqualTo("hello world");
    replacedertThat(resource.contentLength()).isEqualTo("hello world".length());
}

17 Source : SampleAntApplicationIT.java
with Apache License 2.0
from yuanmabiji

@Test
public void runJar() throws Exception {
    File target = new File("target");
    File[] jarFiles = target.listFiles(new FileFilter() {

        @Override
        public boolean accept(File file) {
            return file.getName().endsWith(".jar");
        }
    });
    replacedertThat(jarFiles).hreplacedize(1);
    Process process = new JavaExecutable().processBuilder("-jar", jarFiles[0].getName()).directory(target).start();
    process.waitFor(5, TimeUnit.MINUTES);
    replacedertThat(process.exitValue()).isEqualTo(0);
    String output = FileCopyUtils.copyToString(new InputStreamReader(process.getInputStream()));
    replacedertThat(output).contains("Spring Boot Ant Example");
}

17 Source : PackagingDocumentationTests.java
with Apache License 2.0
from yuanmabiji

@Test
public void bootJarCustomLaunchScript() throws IOException {
    File customScriptFile = new File(this.gradleBuild.getProjectDir(), "src/custom.script");
    customScriptFile.getParentFile().mkdirs();
    FileCopyUtils.copy("custom", new FileWriter(customScriptFile));
    this.gradleBuild.script("src/main/gradle/packaging/boot-jar-custom-launch-script").build("bootJar");
    File file = new File(this.gradleBuild.getProjectDir(), "build/libs/" + this.gradleBuild.getProjectDir().getName() + ".jar");
    replacedertThat(file).isFile();
    replacedertThat(FileCopyUtils.copyToString(new FileReader(file))).startsWith("custom");
}

17 Source : WebServerPortFileWriterTest.java
with Apache License 2.0
from yuanmabiji

@Test
public void overridePortFileWithExplicitFile() throws Exception {
    File file = this.temporaryFolder.newFile();
    System.setProperty("PORTFILE", this.temporaryFolder.newFile().getAbsolutePath());
    WebServerPortFileWriter listener = new WebServerPortFileWriter(file);
    listener.onApplicationEvent(mockEvent("", 8080));
    FileReader reader = new FileReader(System.getProperty("PORTFILE"));
    replacedertThat(FileCopyUtils.copyToString(reader)).isEqualTo("8080");
}

See More Examples