/** * Singleton initializer. * * Uses reflection to extract and 'cache' the method to invoke to set a write timouet in a socket. * * @param socketClass Underlying class providing the implementation of {@link Socket}. * @return Method to call to set a write timeout in the socket. */ private static Method initFrom(Class<?> socketClass) { Log_OC.i(TAG, "Socket implementation: " + socketClass.getCanonicalName()); Method setSoWriteTimeoutMethod = null; try { setSoWriteTimeoutMethod = socketClass.getMethod(METHOD_NAME, int.class); } catch (SecurityException e) { Log_OC.e(TAG, "Could not access to (SocketImpl)#setSoWriteTimeout(int) method ", e); } catch (NoSuchMethodException e) { Log_OC.i( TAG, "Could not find (SocketImpl)#setSoWriteTimeout(int) method - write timeout not supported" ); } mSingleInstance.set(new WriteTimeoutEnforcer(socketClass, setSoWriteTimeoutMethod)); return setSoWriteTimeoutMethod; }