I'm trying to create a BufferedServerSocketImpl
which would return a BufferedInputStream
in getInputStream
instead of the non-buffered one of the wrapped object (markSupported()
=false), but otherwise simply forward all other calls to the wrapped SocketImpl object.
The issue I'm having is with accept
and other protected abstract methods not being visible. Here's an excerpt:
public class BufferedServerSocketImpl extends SocketImpl {
private SocketImpl internalSocketImpl;
BufferedServerSocketImpl(SocketImpl nested) {
this.internalSocketImpl = nested;
}
@Override
protected void accept(SocketImpl s) throws IOException {
internalSocketImpl.accept(s);
}
//...
}
In the above example internalSocketImpl.accept(s);
is an error because the method accept(SocketImpl)
from the type SocketImpl
is not visible.
I know that the object I'll wrap will be a java.net.PlainServerSocketImpl
or a java.net.SocksSocketImpl
, but I can't extend those as they are not visible either.
Any ideas on why this is so and how I could work around it?
I considered using dynamic proxies for Socket
or SocketImpl
, but since they do not have interfaces I would have to either use an external library or do bytecode manipulations, neither of which are feasible for the project. Also, I'm running in an OSGi framework, so classloader shenanigans are also not feasible.