@Override public FastBufferOutputStream getResponseOutputStream() { if (stream == null) { stream = new FastBufferOutputStream(); } return stream; }
private static ByteBuffer readContent(InputStream is) throws IOException { if (is == null) { throw new NullPointerException("Resource input stream is null"); } FastBufferOutputStream os = new FastBufferOutputStream(); try { ResourceUtils.copyStreamContent(is, os); } finally { try { is.close(); } catch (IOException e) { if (LOGGER.isDebugEnabled()) { LOGGER.debug(e.getMessage(), e); } } try { os.close(); } catch (IOException e) { if (LOGGER.isDebugEnabled()) { LOGGER.debug(e.getMessage(), e); } } } ByteBuffer buffer = os.getFirstBuffer(); buffer.compact(); return buffer; }
/** * Returns instance of FastBufferOutputStream containing all data written to this writer. * * @return instance of FastBufferOutputStream containing all data written to this writer */ public FastBufferOutputStream convertToOutputStream() { CharBuffer c = firstBuffer; ByteBuffer first = c.toByteBuffer(); ByteBuffer b = first; while (c != null) { c = c.getNext(); if (c == null) { break; } ByteBuffer n = c.toByteBuffer(); b.setNext(n); b = n; } return new FastBufferOutputStream(first); }
public InputStream getInputStream() throws IOException { FastBufferOutputStream fbos = new FastBufferOutputStream(); ImageOutputStream imageOutputStream = ImageIO.createImageOutputStream(fbos); try { paintAndWrite(imageOutputStream); } finally { if (imageOutputStream != null) { try { imageOutputStream.close(); } catch (IOException e) { LOGGER.debug(e.getMessage(), e); } try { fbos.close(); } catch (IOException e) { // Swallow } } } ByteBuffer buffer = fbos.getFirstBuffer(); buffer.compact(); return new FastBufferInputStream(buffer); }
/** * Returns instance of FastBufferOutputStream containing all data written to this writer. * * @param encoding * @return instance of FastBufferOutputStream containing all data written to this writer * @throws UnsupportedEncodingException */ public FastBufferOutputStream convertToOutputStream(String encoding) throws UnsupportedEncodingException { CharBuffer c = firstBuffer; ByteBuffer first = c.toByteBuffer(encoding); ByteBuffer b = first; while (c != null) { c = c.getNext(); if (c == null) { break; } ByteBuffer n = c.toByteBuffer(encoding); b.setNext(n); b = n; } return new FastBufferOutputStream(first); }