mirror of
https://github.com/square/okhttp.git
synced 2026-01-25 16:01:38 +03:00
Fix unresolved function call on JVM < 1.7
This notably allows the mockwebserver project to be run on Android. ServerSocket only implements Closeable since Java 1.7 and thus calling of closeQuietly(Closeable) with a ServerSocket argument fails when running on Java 1.5 or 1.6 JVMs. This is the same as is already done for closeQuietly(Socket).
This commit is contained in:
@@ -26,6 +26,7 @@ import java.io.Reader;
|
||||
import java.io.StringWriter;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.Socket;
|
||||
import java.net.ServerSocket;
|
||||
import java.net.URI;
|
||||
import java.net.URL;
|
||||
import java.nio.ByteOrder;
|
||||
@@ -136,6 +137,21 @@ public final class Util {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Closes {@code serverSocket}, ignoring any checked exceptions. Does nothing if
|
||||
* {@code serverSocket} is null.
|
||||
*/
|
||||
public static void closeQuietly(ServerSocket serverSocket) {
|
||||
if (serverSocket != null) {
|
||||
try {
|
||||
serverSocket.close();
|
||||
} catch (RuntimeException rethrown) {
|
||||
throw rethrown;
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Closes {@code a} and {@code b}. If either close fails, this completes
|
||||
* the other close and rethrows the first encountered exception.
|
||||
|
||||
Reference in New Issue
Block a user