/** * Calls the {@code #setSoWrite(int)} method of the underlying implementation * of {@link Socket} if exists. * Creates and initializes the single instance of the class when needed * * @param writeTimeoutMilliseconds Write timeout to set, in milliseconds. * @param socket Client socket to connect with the server. */ public static void setSoWriteTimeout(int writeTimeoutMilliseconds, Socket socket) { final Method setSoWriteTimeoutMethod = getMethod(socket); if (setSoWriteTimeoutMethod != null) { try { setSoWriteTimeoutMethod.invoke(socket, writeTimeoutMilliseconds); Log_OC.i( TAG, "Write timeout set in socket, writeTimeoutMilliseconds: " + writeTimeoutMilliseconds ); } catch (IllegalArgumentException e) { Log_OC.e(TAG, "Call to (SocketImpl)#setSoWriteTimeout(int) failed ", e); } catch (IllegalAccessException e) { Log_OC.e(TAG, "Call to (SocketImpl)#setSoWriteTimeout(int) failed ", e); } catch (InvocationTargetException e) { Log_OC.e(TAG, "Call to (SocketImpl)#setSoWriteTimeout(int) failed ", e); } } else { Log_OC.i(TAG, "Write timeout for socket not supported"); } }