Java Code Examples for org.springframework.util.FileCopyUtils#copyToString()
The following examples show how to use
org.springframework.util.FileCopyUtils#copyToString() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RequestLoggingFilterTests.java From spring-analysis-note with MIT License | 6 votes |
@Test public void payloadReader() throws Exception { filter.setIncludePayload(true); final MockHttpServletRequest request = new MockHttpServletRequest("POST", "/hotels"); MockHttpServletResponse response = new MockHttpServletResponse(); final String requestBody = "Hello World"; request.setContent(requestBody.getBytes(StandardCharsets.UTF_8)); FilterChain filterChain = (filterRequest, filterResponse) -> { ((HttpServletResponse) filterResponse).setStatus(HttpServletResponse.SC_OK); String buf = FileCopyUtils.copyToString(filterRequest.getReader()); assertEquals(requestBody, buf); }; filter.doFilter(request, response, filterChain); assertNotNull(filter.afterRequestMessage); assertTrue(filter.afterRequestMessage.contains(requestBody)); }
Example 2
Source File: PassThroughClob.java From spring-analysis-note with MIT License | 6 votes |
@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); } }
Example 3
Source File: FreeMarkerMacroTests.java From java-technology-stack with MIT License | 5 votes |
private String fetchMacro(String name) throws Exception { ClassPathResource resource = new ClassPathResource("test.ftl", getClass()); assertTrue(resource.exists()); String all = FileCopyUtils.copyToString(new InputStreamReader(resource.getInputStream())); all = all.replace("\r\n", "\n"); String[] macros = StringUtils.delimitedListToStringArray(all, "\n\n"); for (String macro : macros) { if (macro.startsWith(name)) { return macro.substring(macro.indexOf("\n")).trim(); } } return null; }
Example 4
Source File: ResourceScriptSource.java From spring-analysis-note with MIT License | 5 votes |
@Override public String getScriptAsString() throws IOException { synchronized (this.lastModifiedMonitor) { this.lastModified = retrieveLastModifiedTime(); } Reader reader = this.resource.getReader(); return FileCopyUtils.copyToString(reader); }
Example 5
Source File: ScriptTemplateView.java From java-technology-stack with MIT License | 5 votes |
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); }
Example 6
Source File: ClassPathXmlApplicationContextTests.java From java-technology-stack with MIT License | 5 votes |
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()))); assertTrue(dump.contains("someMessageSource")); assertTrue(dump.contains("useCodeAsDefaultMessage")); }
Example 7
Source File: ResourceScriptSource.java From java-technology-stack with MIT License | 5 votes |
@Override public String getScriptAsString() throws IOException { synchronized (this.lastModifiedMonitor) { this.lastModified = retrieveLastModifiedTime(); } Reader reader = this.resource.getReader(); return FileCopyUtils.copyToString(reader); }
Example 8
Source File: ScriptTemplateView.java From java-technology-stack with MIT License | 5 votes |
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); }
Example 9
Source File: SourceHttpMessageConverterTests.java From spring-analysis-note with MIT License | 5 votes |
@Test public void readStreamSource() throws Exception { MockHttpInputMessage inputMessage = new MockHttpInputMessage(BODY.getBytes("UTF-8")); inputMessage.getHeaders().setContentType(new MediaType("application", "xml")); StreamSource result = (StreamSource) converter.read(StreamSource.class, inputMessage); String s = FileCopyUtils.copyToString(new InputStreamReader(result.getInputStream())); assertThat("Invalid result", s, isSimilarTo(BODY)); }
Example 10
Source File: ResourceTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void testByteArrayResourceWithDescription() throws IOException { Resource resource = new ByteArrayResource("testString".getBytes(), "my description"); assertTrue(resource.exists()); assertFalse(resource.isOpen()); String content = FileCopyUtils.copyToString(new InputStreamReader(resource.getInputStream())); assertEquals("testString", content); assertTrue(resource.getDescription().contains("my description")); assertEquals(resource, new ByteArrayResource("testString".getBytes())); }
Example 11
Source File: FreeMarkerMacroTests.java From spring-analysis-note with MIT License | 5 votes |
private String fetchMacro(String name) throws Exception { ClassPathResource resource = new ClassPathResource("test.ftl", getClass()); assertTrue(resource.exists()); String all = FileCopyUtils.copyToString(new InputStreamReader(resource.getInputStream())); all = all.replace("\r\n", "\n"); String[] macros = StringUtils.delimitedListToStringArray(all, "\n\n"); for (String macro : macros) { if (macro.startsWith(name)) { return macro.substring(macro.indexOf("\n")).trim(); } } return null; }
Example 12
Source File: ResourceTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void testInputStreamResourceWithDescription() throws IOException { InputStream is = new ByteArrayInputStream("testString".getBytes()); Resource resource = new InputStreamResource(is, "my description"); assertTrue(resource.exists()); assertTrue(resource.isOpen()); String content = FileCopyUtils.copyToString(new InputStreamReader(resource.getInputStream())); assertEquals("testString", content); assertTrue(resource.getDescription().contains("my description")); assertEquals(resource, new InputStreamResource(is)); }
Example 13
Source File: ResourceTests.java From spring-analysis-note with MIT License | 5 votes |
@Test public void testInputStreamResourceWithDescription() throws IOException { InputStream is = new ByteArrayInputStream("testString".getBytes()); Resource resource = new InputStreamResource(is, "my description"); assertTrue(resource.exists()); assertTrue(resource.isOpen()); String content = FileCopyUtils.copyToString(new InputStreamReader(resource.getInputStream())); assertEquals("testString", content); assertTrue(resource.getDescription().contains("my description")); assertEquals(resource, new InputStreamResource(is)); }
Example 14
Source File: ResourceTests.java From spring-analysis-note with MIT License | 5 votes |
@Test public void testInputStreamResource() throws IOException { InputStream is = new ByteArrayInputStream("testString".getBytes()); Resource resource = new InputStreamResource(is); assertTrue(resource.exists()); assertTrue(resource.isOpen()); String content = FileCopyUtils.copyToString(new InputStreamReader(resource.getInputStream())); assertEquals("testString", content); assertEquals(resource, new InputStreamResource(is)); }
Example 15
Source File: ResourceTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void testInputStreamResource() throws IOException { InputStream is = new ByteArrayInputStream("testString".getBytes()); Resource resource = new InputStreamResource(is); assertTrue(resource.exists()); assertTrue(resource.isOpen()); String content = FileCopyUtils.copyToString(new InputStreamReader(resource.getInputStream())); assertEquals("testString", content); assertEquals(resource, new InputStreamResource(is)); }
Example 16
Source File: SourceHttpMessageConverterTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void readSAXSource() throws Exception { MockHttpInputMessage inputMessage = new MockHttpInputMessage(BODY.getBytes("UTF-8")); inputMessage.getHeaders().setContentType(new MediaType("application", "xml")); SAXSource result = (SAXSource) converter.read(SAXSource.class, inputMessage); InputSource inputSource = result.getInputSource(); String s = FileCopyUtils.copyToString(new InputStreamReader(inputSource.getByteStream())); assertThat("Invalid result", s, isSimilarTo(BODY)); }
Example 17
Source File: SourceHttpMessageConverterTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void readStreamSource() throws Exception { MockHttpInputMessage inputMessage = new MockHttpInputMessage(BODY.getBytes("UTF-8")); inputMessage.getHeaders().setContentType(new MediaType("application", "xml")); StreamSource result = (StreamSource) converter.read(StreamSource.class, inputMessage); String s = FileCopyUtils.copyToString(new InputStreamReader(result.getInputStream())); assertThat("Invalid result", s, isSimilarTo(BODY)); }
Example 18
Source File: ClassPathXmlApplicationContextTests.java From spring-analysis-note with MIT License | 5 votes |
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()))); assertTrue(dump.contains("someMessageSource")); assertTrue(dump.contains("useCodeAsDefaultMessage")); }
Example 19
Source File: HttpCharsetConvert.java From anyline with Apache License 2.0 | 4 votes |
@SuppressWarnings("rawtypes") @Override protected String readInternal(Class clazz, HttpInputMessage inputMessage) throws IOException { Charset charset = getContentTypeCharset(inputMessage.getHeaders().getContentType()); return FileCopyUtils.copyToString(new InputStreamReader(inputMessage.getBody(), charset)); }
Example 20
Source File: HttpCharsetConvert.java From anyline with Apache License 2.0 | 4 votes |
@SuppressWarnings("rawtypes") @Override protected String readInternal(Class clazz, HttpInputMessage inputMessage) throws IOException { Charset charset = getContentTypeCharset(inputMessage.getHeaders().getContentType()); return FileCopyUtils.copyToString(new InputStreamReader(inputMessage.getBody(), charset)); }