InputStream with "events" in Java
<p>I have a situation in Java where I have a method that returns an InputStream, and I want to make it so that whenever the person calls the close function on that InputStream, some other place in the code gets notified (like a callback). </p>

<p>However, the actual InputStream I'm returning is a sub-class of InputStream returned by a library call, so I don't have direct control over it.</p>

<p>My current solution is to create a subclass of InputStream, which has an InputStream member variable which is instantiated by the library call in the constructor, and I just override the methods of InputStream and just have them use the variable's methods, with the addition that the close() function does something extra.</p>

<p>This works, but I would like to reduce the overhead of having to create a whole new class, override all the necessary methods, just so that I can do a single event when close() is called.</p>
