Methods Summary |
---|
private java.lang.Object | _invoke(java.lang.reflect.Method m, java.lang.Object[] args)
try {
return java.security.AccessController.doPrivileged
(new java.security.PrivilegedExceptionAction() {
public java.lang.Object run() throws Exception {
return m.invoke(si, args);
}
});
} catch (PrivilegedActionException ex) {
logger.log(Level.FINER, ex.getMessage(), ex);
Throwable tmpEx = ex;
if ( ex.getCause() != null) {
tmpEx = ex.getCause();
}
if (tmpEx instanceof InvocationTargetException) {
Throwable e =
((InvocationTargetException) tmpEx).getTargetException();
if (e != null) {
tmpEx = e;
}
}
logger.log(Level.FINER, tmpEx.getMessage(), tmpEx);
if (tmpEx instanceof SocketException) {
throw (SocketException) tmpEx;
} else if (tmpEx instanceof IOException) {
throw (IOException) tmpEx;
} else {
IOException ie = new IOException(tmpEx.getMessage());
throw (IOException) ie.initCause(tmpEx);
}
} catch (Exception ex) {
logger.log(Level.FINER, ex.getMessage(), ex);
IOException ie = new IOException(ex.getMessage());
throw (IOException) ie.initCause(ex);
}
|
private void | _setupMethods(java.lang.Class siClass)Compare any non-private method. The java.net.socketimpl class
has abtsract protected methods. So, its implementation is
has to have atleast protected methods.
Method[] methods = siClass.getDeclaredMethods();
for (Method m : methods) {
if (Modifier.isPrivate(m.getModifiers())) {
continue;
}
m.setAccessible(true);
if (m.getName().equalsIgnoreCase("CREATE")) {
if (createMethod == null)
createMethod = m;
continue;
}
if (m.getName().equalsIgnoreCase("CONNECT")) {
if (m.getParameterTypes()[0].equals(String.class)) {
if (connectMethod1 == null)
connectMethod1 = m;
} else if (m.getParameterTypes()[0].equals(InetAddress.class)){
if (connectMethod2 == null)
connectMethod2 = m;
} else {
if (connectMethod3 == null)
connectMethod3 = m;
}
continue;
}
if (m.getName().equalsIgnoreCase("BIND")) {
if (bindMethod == null)
bindMethod = m;
continue;
}
if (m.getName().equalsIgnoreCase("LISTEN")) {
if (listenMethod == null)
listenMethod = m;
continue;
}
if (m.getName().equalsIgnoreCase("ACCEPT")) {
if (acceptMethod == null)
acceptMethod = m;
continue;
}
if (m.getName().equalsIgnoreCase("GETINPUTSTREAM")) {
if (getInputStreamMethod == null)
getInputStreamMethod = m;
continue;
}
if (m.getName().equalsIgnoreCase("GETOUTPUTSTREAM")) {
if (getOutputStreamMethod == null)
getOutputStreamMethod = m;
continue;
}
if (m.getName().equalsIgnoreCase("AVAILABLE")) {
if (availableMethod == null)
availableMethod = m;
continue;
}
if (m.getName().equalsIgnoreCase("CLOSE")) {
if (closeMethod == null)
closeMethod = m;
continue;
}
if (m.getName().equalsIgnoreCase("SHUTDOWNINPUT")) {
if (shutdownInputMethod == null)
shutdownInputMethod = m;
continue;
}
if (m.getName().equalsIgnoreCase("SHUTDOWNOUTPUT")) {
if (shutdownOutputMethod == null)
shutdownOutputMethod = m;
continue;
}
if (m.getName().equalsIgnoreCase("SENDURGENTDATA")) {
if (sendUrgentDataMethod == null)
sendUrgentDataMethod = m;
continue;
}
if (m.getName().equalsIgnoreCase("GETOPTION")) {
if (getOptionMethod == null)
getOptionMethod = m;
continue;
}
if (m.getName().equalsIgnoreCase("SETOPTION")) {
if (setOptionMethod == null)
setOptionMethod = m;
continue;
}
if (m.getName().equalsIgnoreCase("GETPORT")) {
if (getPortMethod == null)
getPortMethod = m;
continue;
}
if (m.getName().equalsIgnoreCase("GETINETADDRESS")) {
if (getInetAddressMethod == null)
getInetAddressMethod = m;
continue;
}
if (m.getName().equalsIgnoreCase("GETLOCALPORT")) {
if (getLocalPortMethod == null)
getLocalPortMethod = m;
continue;
}
if (m.getName().equalsIgnoreCase("SUPPORTSURGENTDATA")) {
if (supportsUrgentDataMethod == null)
supportsUrgentDataMethod = m;
continue;
}
}
|
protected void | accept(java.net.SocketImpl s)
_invoke(acceptMethod, new Object[] {s});
|
protected int | available()
return (Integer) _invoke(availableMethod, null);
|
protected void | bind(java.net.InetAddress host, int port)
_invoke(bindMethod, new Object[] {host, new Integer(port)});
|
protected void | close()
_invoke(closeMethod, null);
|
protected void | connect(java.lang.String host, int port)
boolean waitForStartupReqd = ! ASSocketFacadeUtils.getASSocketService().
socketServiceNotified(port);
_invoke(connectMethod1, new Object[] {host, new Integer(port)});
if (ASSocketFacadeUtils.getASSocketService().
isLocalClient(InetAddress.getByName(host)) == false) {
return;
}
if (waitForStartupReqd) {
ASSocketFacadeUtils.getASSocketService().
waitOnClientConnection(getPort());
}
ASSocketFacadeUtils.getASSocketService().clientSocketConnected(
getPort(), getLocalPort());
|
protected void | connect(java.net.InetAddress address, int port)
boolean waitForStartupReqd = ! ASSocketFacadeUtils.getASSocketService().
socketServiceNotified(port);
_invoke(connectMethod2, new Object[] {address, new Integer(port)});
if (ASSocketFacadeUtils.getASSocketService().
isLocalClient(address) == false) {
return;
}
if (waitForStartupReqd) {
ASSocketFacadeUtils.getASSocketService().
waitOnClientConnection(getPort());
}
ASSocketFacadeUtils.getASSocketService().clientSocketConnected(
getPort(), getLocalPort());
|
protected void | connect(java.net.SocketAddress address, int timeout)
InetSocketAddress isa = (InetSocketAddress) address;
boolean waitForStartupReqd = ! ASSocketFacadeUtils.getASSocketService().
socketServiceNotified(isa.getPort());
_invoke(connectMethod3, new Object[] {address, new Integer(timeout)});
if (ASSocketFacadeUtils.getASSocketService().
isLocalClient(isa.getAddress()) == false) {
return;
}
if (waitForStartupReqd) {
ASSocketFacadeUtils.getASSocketService().
waitOnClientConnection(getPort());
}
ASSocketFacadeUtils.getASSocketService().clientSocketConnected(
getPort(), getLocalPort());
|
protected void | create(boolean stream)
_invoke(createMethod, new Object[] {new Boolean(stream)});
|
public java.net.InetAddress | getInetAddress()
try {
return (InetAddress) _invoke(getInetAddressMethod, null);
} catch (IOException ex) {
logger.log(Level.FINER, ex.getMessage(), ex);
throw new RuntimeException(ex);
}
|
protected java.io.InputStream | getInputStream()
return (InputStream) _invoke(getInputStreamMethod, null);
|
public int | getLocalPort()
try {
return (Integer) _invoke(getLocalPortMethod, null);
} catch (IOException ex) {
logger.log(Level.FINER, ex.getMessage(), ex);
throw new RuntimeException(ex);
}
|
public java.lang.Object | getOption(int optID)
try {
return _invoke(getOptionMethod, new Object[] {new Integer(optID)});
} catch (IOException ie) {
SocketException se = new SocketException(ie.getMessage());
throw (SocketException) se.initCause(ie);
}
|
protected java.io.OutputStream | getOutputStream()
return (OutputStream) _invoke(getOutputStreamMethod, null);
|
public int | getPort()
try {
return (Integer) _invoke(getPortMethod, null);
} catch (IOException ex) {
throw new RuntimeException(ex);
}
|
protected void | listen(int backlog)
_invoke(listenMethod, new Object[] {new Integer(backlog)});
|
protected void | sendUrgentData(int data)
_invoke(sendUrgentDataMethod, new Object[] {new Integer(data)});
|
public void | setOption(int optID, java.lang.Object value)
try {
_invoke(setOptionMethod, new Object[] {new Integer(optID), value});
} catch (IOException ie) {
SocketException se = new SocketException(ie.getMessage());
throw (SocketException) se.initCause(ie);
}
|
private void | setup()Introspect all the class and create all the method objects.
The JDK socket impl implementation has all protected methods
and the only way to wrap it is by using setAccessible.
The method can be either in the SocksSocketImpl or in any
of the parent classes.
Object impl = java.security.AccessController.doPrivileged
(new java.security.PrivilegedExceptionAction() {
public java.lang.Object run() throws Exception {
Class tmpClass = Class.forName(SOCKET_IMPL_CLASS);
Constructor cons = tmpClass.getDeclaredConstructor(new Class[] {});
cons.setAccessible(true);
Object obj = cons.newInstance( (Class[])null);
while (tmpClass.getName().
equalsIgnoreCase("JAVA.NET.SOCKETIMPL") == false) {
_setupMethods(tmpClass);
tmpClass = tmpClass.getSuperclass();
}
return obj;
}
});
this.si = (SocketImpl) impl;
|
protected void | shutdownInput()
_invoke(shutdownInputMethod, null);
|
protected void | shutdownOutput()
_invoke(shutdownOutputMethod, null);
|
public boolean | supportsUrgentData()
try {
return (Boolean) _invoke(supportsUrgentDataMethod, null);
} catch (IOException ex) {
throw new RuntimeException(ex);
}
|