444 CHAPTER 11 ADVANCED FILTERING TECHNIQUES extends (Affordable web hosting)
444 CHAPTER 11 ADVANCED FILTERING TECHNIQUES extends ServletOutputStream { byte[] result; private ByteArrayOutputStream baStream; private boolean closed = false; public ReplaceContentOutputStream() { baStream = new ByteArrayOutputStream(); } public void write(int i) throws java.io.IOException { baStream.write(i); } public void close() throws java.io.IOException { if (!closed) { processStream(); closed = true; } } public abstract byte[] replaceContent(byte[] inBytes) throws java.io.IOException; public void processStream() throws java.io.IOException { result = replaceContent(baStream.toByteArray()); } public byte[] getResult() { return result; } } This abstract class extends another abstract class, called ServletOutputStream, which is the base class of the OutputStreamreturned by getOutputStream()on a response. ServletOutputStream requires the write(int) method to be implemented by its subclass. It implements all the other write() variants based on this method. The ReplaceContentOutputStreamrequires the replaceContent() method to be implemented by all its subclasses. Note the use of the flag variable closed: Initially false, this variable is used to ensure that the wrapped stream is closed only once, regardless of how many times the close() method may be called. The constructor creates the memory-based ByteArrayOutputStream for the downstream processors. Next, the class implements the required write(int)method, which writes to the in- memory byte array stream called baStream. This ensures that all writes on this stream write to baStream (essentially a buffer).
You need excellent and relaible webhost company to host your web applications? Then pay a visit to Inexpensive Web Hosting services.