replacing text in a printstream

Create create a subclass of FilterOutputStream, say RegexOutputStream. This class should buffer all data written to it (from the different write(...) methods). In the flush() method, it should apply the regex and then write the result to the underlying OutputStream.

Next, instantiate the PrintWriter to write to the RegexOutputStream. This way you don't need to alter the behaviour of the PrintWriter class. In case you don't want the filtering anymore, you can just take the RegexOutStream out of the chain, and everything will work again.

Note that, depending on how you use the PrintWriter, this might cause the RegexOutputStreams buffer to get quite big. If you create the PrintWriter to autoflush, it will flush after every line and after every byte array. See its JavaDoc for details.

Answer:1

I wrote the following StringTemplate template lines: <instance.attributes: { attr | <attr.value>}> <instance.attributes: { attr | <if(attr.value)>skip<else>don't skip<...

I get error: incompatible types: org.eclipse.jetty.servlet.ServletHandler cannot be converted to org.mortbay.jetty.Handler While trying to run my below code. I'm new to Java and not sure why this is ...

The default behavior is that the absolute file path is used to uniquely identify files - I would like customize this to use the md5 checksum of the file. Is it possible to simply implement a custom ...

How can I create implementations of an interface dynamically at runtime in java? I have a factory that will read the annotations on class Foo and create an instance of class Bar. For this factory to ...