Java Code Examples for org.springframework.util.StreamUtils#BUFFER_SIZE
The following examples show how to use
org.springframework.util.StreamUtils#BUFFER_SIZE .
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: ResourceHttpRequestHandler.java From spring4-understanding with Apache License 2.0 | 6 votes |
private void copyRange(InputStream in, OutputStream out, long start, long end) throws IOException { long skipped = in.skip(start); if (skipped < start) { throw new IOException("Skipped only " + skipped + " bytes out of " + start + " required."); } long bytesToCopy = end - start + 1; byte buffer[] = new byte[StreamUtils.BUFFER_SIZE]; while (bytesToCopy > 0) { int bytesRead = in.read(buffer); if (bytesRead <= bytesToCopy) { out.write(buffer, 0, bytesRead); bytesToCopy -= bytesRead; } else { out.write(buffer, 0, (int) bytesToCopy); bytesToCopy = 0; } if (bytesRead == -1) { break; } } }
Example 2
Source File: ByteArrayHttpMessageConverter.java From spring-analysis-note with MIT License | 5 votes |
@Override public byte[] readInternal(Class<? extends byte[]> clazz, HttpInputMessage inputMessage) throws IOException { long contentLength = inputMessage.getHeaders().getContentLength(); ByteArrayOutputStream bos = new ByteArrayOutputStream(contentLength >= 0 ? (int) contentLength : StreamUtils.BUFFER_SIZE); StreamUtils.copy(inputMessage.getBody(), bos); return bos.toByteArray(); }
Example 3
Source File: ByteArrayHttpMessageConverter.java From java-technology-stack with MIT License | 5 votes |
@Override public byte[] readInternal(Class<? extends byte[]> clazz, HttpInputMessage inputMessage) throws IOException { long contentLength = inputMessage.getHeaders().getContentLength(); ByteArrayOutputStream bos = new ByteArrayOutputStream(contentLength >= 0 ? (int) contentLength : StreamUtils.BUFFER_SIZE); StreamUtils.copy(inputMessage.getBody(), bos); return bos.toByteArray(); }
Example 4
Source File: ByteArrayHttpMessageConverter.java From lams with GNU General Public License v2.0 | 5 votes |
@Override public byte[] readInternal(Class<? extends byte[]> clazz, HttpInputMessage inputMessage) throws IOException { long contentLength = inputMessage.getHeaders().getContentLength(); ByteArrayOutputStream bos = new ByteArrayOutputStream(contentLength >= 0 ? (int) contentLength : StreamUtils.BUFFER_SIZE); StreamUtils.copy(inputMessage.getBody(), bos); return bos.toByteArray(); }
Example 5
Source File: ByteArrayHttpMessageConverter.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Override public byte[] readInternal(Class<? extends byte[]> clazz, HttpInputMessage inputMessage) throws IOException { long contentLength = inputMessage.getHeaders().getContentLength(); ByteArrayOutputStream bos = new ByteArrayOutputStream(contentLength >= 0 ? (int) contentLength : StreamUtils.BUFFER_SIZE); StreamUtils.copy(inputMessage.getBody(), bos); return bos.toByteArray(); }
Example 6
Source File: RawContentTag.java From lognavigator with Apache License 2.0 | 5 votes |
@Override public int doEndTag() throws JspException { // Get input and ouput variables Reader rawContent = (Reader) pageContext.getAttribute(Constants.RAW_CONTENT_KEY, PageContext.REQUEST_SCOPE); JspWriter out = pageContext.getOut(); try { // Copy input (rawContent) to output (out) char[] buffer = new char[StreamUtils.BUFFER_SIZE]; int bytesRead = -1; while ((bytesRead = rawContent.read(buffer)) != -1) { String stringToWrite = new String(buffer, 0, bytesRead); stringToWrite = HtmlUtils.htmlEscape(stringToWrite); out.write(stringToWrite); } out.flush(); return EVAL_PAGE; } catch (IOException e) { throw new JspException(e); } finally { IOUtils.closeQuietly(rawContent); } }