public void writeContentTo (final OutputStream aOS) throws IOException { if (!m_aDelegate.isCommitted () && m_aOS.m_aBAOS.isNotEmpty ()) m_aOS.m_aBAOS.writeTo (aOS); }
public final void doNotCompress (final String sDebugInfo) throws IOException { if (m_aCompressedOS != null) throw new IllegalStateException ("Compressed output stream is already assigned."); if (m_aOS == null || m_aBAOS != null) { m_bDoNotCompress = true; _debugLog (false, sDebugInfo); m_aOS = m_aHttpResponse.getOutputStream (); setContentLength (m_nContentLength); if (m_aBAOS != null) { // Copy all cached content m_aBAOS.writeTo (m_aOS); m_aBAOS = null; } } }
/** * Switches the underlying output stream from a memory based stream to one * that is backed by disk. This is the point at which we realise that too much * data is being written to keep in memory, so we elect to switch to * disk-based storage. * * @exception IOException * if an error occurs. */ @Override protected void onThresholdReached () throws IOException { FileOutputStream aFOS = null; try { aFOS = new FileOutputStream (m_aOutputFile); m_aMemoryOS.writeTo (aFOS); m_aCurrentOS = aFOS; // Explicitly close the stream (even though this is a no-op) StreamHelper.close (m_aMemoryOS); m_aMemoryOS = null; } catch (final IOException ex) { StreamHelper.close (aFOS); throw ex; } }
public final void doCompress (@Nullable final String sDebugInfo) throws IOException { if (m_aCompressedOS == null) { if (m_aHttpResponse.isCommitted ()) throw new IllegalStateException ("Response already committed"); m_aHttpResponse.setHeader (CHttpHeader.CONTENT_ENCODING, m_sContentEncoding); // Check if header was really set (may e.g. not be the case when something // is included like a JSP) if (m_aHttpResponse.containsHeader (CHttpHeader.CONTENT_ENCODING)) { _debugLog (true, sDebugInfo); m_aCompressedOS = createDeflaterOutputStream (m_aHttpResponse.getOutputStream ()); m_aOS = m_aCompressedOS; if (m_aBAOS != null) { // Copy cached content to new OS m_aBAOS.writeTo (m_aOS); m_aBAOS = null; } } else doNotCompress ("from compress: included request"); } else { if (CompressFilterSettings.isDebugModeEnabled ()) LOGGER.info ("doCompress on already compressed stream"); } }
/** * Writes the data from this output stream to the specified output stream, * after it has been closed. * * @param aOS * output stream to write to. * @exception IOException * if this stream is not yet closed or an error occurs. */ public void writeTo (@Nonnull @WillNotClose final OutputStream aOS) throws IOException { // we may only need to check if this is closed if we are working with a file // but we should force the habit of closing whether we are working with // a file or memory. if (!m_bClosed) throw new IOException ("This stream is not closed"); if (isInMemory ()) { m_aMemoryOS.writeTo (aOS); } else { final InputStream aIS = FileHelper.getInputStream (m_aOutputFile); StreamHelper.copyInputStreamToOutputStream (aIS, aOS); } } }
private void writeObject (@Nonnull final ObjectOutputStream aOOS) throws IOException { // write text aOOS.writeObject (m_sText); // write the mime body final NonBlockingByteArrayOutputStream aBAOS = new NonBlockingByteArrayOutputStream (); try { if (m_aData != null) { aBAOS.write (1); m_aData.writeTo (aBAOS); } else { aBAOS.write (0); } aBAOS.writeTo (aOOS); } catch (final MessagingException ex) { throw new IOException ("Messaging exception", ex); } finally { StreamHelper.close (aBAOS); } } }