The ObjectStream component of the filtering system is used by the Handler to convert the stream of bytes in the Reply content into a stream of Java objects. This conversion process is used to efficiently pass data from one filter to another. Instead of sending the data byte by byte, Java objects are used to store kilobytes of data and allow larger chunks of data to be transferred. An ObjectStream also allows many filters to process a stream of objects in parallel. To accomplish this, the filters need to be configured such that output from the first filter is sent as input to the second filter, and so on for the remaining filters. The result is a chain of filters connected by input and output, with each filter reading and writing objects and processing them if necessary. Filters can also remove objects from the stream, and new objects can be inserted. All objects in an ObjectStream are based on a Java ByteArray object. A ByteArray is a simple Java object which provides an easy interface for storing a large number of bytes in a single object.
ObjectStreams where developed due to performance problems with the standard Java piped streams. Java provides two interfaces for passing data between threads: PipedReader/PipedWriter and PipedInputStream/PipedOutputStream. Initially, the filtering system used PipedReader and PipedWriter for all content filtering. This was found to be very slow since the Java Reader/Writer interface is based on the Java char (2 byte) type which results in having to read and write twice the amount of data. The next step was to try using a PipedInputStream and PipedOutputStream. Performance with these streams was much better since they are built upon Java bytes, but there was still a significant problem. Since each of the HTML content filters was receiving a stream of bytes, each of these filters would have to parse the bytes into HTML tokens. This resulted in very slow performance when more than a few HTML content filters were enabled. ObjectStreams improved performance dramatically. The design goal of ObjectStreams was to come up with way to offload the task of parsing HTML from filters and instead send filters a pre-parsed representation of the HTML document. The result was a system where HTML is parsed once and converted into objects which are then sent in a stream to filters.