Package com.twelvemonkeys.servlet
Class OutputStreamAdapter
- java.lang.Object
-
- java.io.OutputStream
-
- javax.servlet.ServletOutputStream
-
- com.twelvemonkeys.servlet.OutputStreamAdapter
-
- All Implemented Interfaces:
java.io.Closeable
,java.io.Flushable
,java.lang.AutoCloseable
public class OutputStreamAdapter extends javax.servlet.ServletOutputStream
AServletOutputStream
implementation backed by aOutputStream
. For filters that need to buffer the response and do post filtering, it may be used like this:ByteArrayOutputStream buffer = new ByteArraOutputStream(); ServletOutputStream adapter = new OutputStreamAdapter(buffer);
As a
ServletOutputStream
is itself anOutputStream
, this class may also be used as a superclass for wrappers of otherServletOutputStream
s, like this:class FilterServletOutputStream extends OutputStreamAdapter { public FilterServletOutputStream(ServletOutputStream out) { super(out); } public void write(int abyte) { // do filtering... super.write(...); } } ... ServletOutputStream original = response.getOutputStream(); ServletOutputStream wrapper = new FilterServletOutputStream(original);
- Version:
- $Id: OutputStreamAdapter.java#1 $
- Author:
- Harald Kuhr, $Author: haku $
-
-
Field Summary
Fields Modifier and Type Field Description protected java.io.OutputStream
out
The wrappedOutputStream
.
-
Constructor Summary
Constructors Constructor Description OutputStreamAdapter(java.io.OutputStream pOut)
Creates anOutputStreamAdapter
.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.io.OutputStream
getOutputStream()
Returns the wrappedOutputStream
.boolean
isReady()
void
setWriteListener(javax.servlet.WriteListener writeListener)
java.lang.String
toString()
void
write(byte[] pBytes)
void
write(byte[] pBytes, int pOff, int pLen)
void
write(int pByte)
Writes a byte to the underlying stream.
-
-
-
Method Detail
-
getOutputStream
public java.io.OutputStream getOutputStream()
Returns the wrappedOutputStream
.- Returns:
- the wrapped
OutputStream
.
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
write
public void write(int pByte) throws java.io.IOException
Writes a byte to the underlying stream.- Specified by:
write
in classjava.io.OutputStream
- Parameters:
pByte
- the byte to write.- Throws:
java.io.IOException
- if an error occurs during writing
-
write
public void write(byte[] pBytes) throws java.io.IOException
- Overrides:
write
in classjava.io.OutputStream
- Throws:
java.io.IOException
-
write
public void write(byte[] pBytes, int pOff, int pLen) throws java.io.IOException
- Overrides:
write
in classjava.io.OutputStream
- Throws:
java.io.IOException
-
setWriteListener
public void setWriteListener(javax.servlet.WriteListener writeListener)
- Specified by:
setWriteListener
in classjavax.servlet.ServletOutputStream
-
isReady
public boolean isReady()
- Specified by:
isReady
in classjavax.servlet.ServletOutputStream
-
-