/** * Initializes the current responses output stream * and the corresponding print writer.<p> * * @throws IOException in case something goes wrong while initializing */ private void initStream() throws IOException { if (m_out == null) { if (!m_writeOnlyToBuffer) { // we can use the parents output stream if (m_cachingRequired || (m_controller.getResponseStackSize() > 1)) { // we are allowed to cache our results (probably to construct a new cache entry) m_out = new CmsFlexResponse.CmsServletOutputStream(m_res.getOutputStream()); } else { // we are not allowed to cache so we just use the parents output stream m_out = (CmsFlexResponse.CmsServletOutputStream)m_res.getOutputStream(); } } else { // construct a "buffer only" output stream m_out = new CmsFlexResponse.CmsServletOutputStream(); } } if (m_writer == null) { // create a PrintWriter that uses the encoding required for the request context m_writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(m_out, m_encoding)), false); } }
/** * Returns the bytes that have been written on the current writers output stream.<p> * * @return the bytes that have been written on the current writers output stream */ public byte[] getWriterBytes() { if (isSuspended()) { // No output whatsoever if the response is suspended return new byte[0]; } if (m_cacheBytes != null) { // Optimization for cached "leaf" nodes, here I re-use the array from the cache return m_cacheBytes; } if (m_out == null) { // No output was written so far, just return an empty array return new byte[0]; } if (m_writer != null) { // Flush the writer in case something was written on it m_writer.flush(); } return m_out.getBytes(); }
m_out.write(bytes);
m_out.clear(); } catch (Exception e) { if (LOG.isDebugEnabled()) {
m_out.clear(); } catch (Exception e) { if (LOG.isDebugEnabled()) {
/** * Initializes the current responses output stream * and the corresponding print writer.<p> * * @throws IOException in case something goes wrong while initializing */ private void initStream() throws IOException { if (m_out == null) { if (!m_writeOnlyToBuffer) { // we can use the parents output stream if (m_cachingRequired || (m_controller.getResponseStackSize() > 1)) { // we are allowed to cache our results (probably to construct a new cache entry) m_out = new CmsFlexResponse.CmsServletOutputStream(m_res.getOutputStream()); } else { // we are not allowed to cache so we just use the parents output stream m_out = (CmsFlexResponse.CmsServletOutputStream)m_res.getOutputStream(); } } else { // construct a "buffer only" output stream m_out = new CmsFlexResponse.CmsServletOutputStream(); } } if (m_writer == null) { // create a PrintWriter that uses the encoding required for the request context m_writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(m_out, m_encoding)), false); } }
m_out.write(bytes);
/** * Returns the bytes that have been written on the current writers output stream.<p> * * @return the bytes that have been written on the current writers output stream */ public byte[] getWriterBytes() { if (isSuspended()) { // No output whatsoever if the response is suspended return new byte[0]; } if (m_cacheBytes != null) { // Optimization for cached "leaf" nodes, here I re-use the array from the cache return m_cacheBytes; } if (m_out == null) { // No output was written so far, just return an empty array return new byte[0]; } if (m_writer != null) { // Flush the writer in case something was written on it m_writer.flush(); } return m_out.getBytes(); }
/** * Constructor that must be used if the stream should write * to a buffer and to another stream at the same time.<p> * * @param servletStream The stream to write to */ public CmsServletOutputStream(ServletOutputStream servletStream) { m_servletStream = servletStream; clear(); }
/** * Constructor that must be used if the stream should write * only to a buffer.<p> */ public CmsServletOutputStream() { m_servletStream = null; clear(); }
/** * Constructor that must be used if the stream should write * to a buffer and to another stream at the same time.<p> * * @param servletStream The stream to write to */ public CmsServletOutputStream(ServletOutputStream servletStream) { m_servletStream = servletStream; clear(); }
/** * Constructor that must be used if the stream should write * only to a buffer.<p> */ public CmsServletOutputStream() { m_servletStream = null; clear(); }