Make HttpConnector a functional interface

This commit is contained in:
Liam Newman
2020-02-25 20:23:40 -08:00
parent fe4f45c2b0
commit 0155d5aa39
5 changed files with 91 additions and 18 deletions

View File

@@ -12,6 +12,7 @@ import java.net.URL;
* <p>
* For example, you can implement this to st custom timeouts.
*/
@FunctionalInterface
public interface HttpConnector {
/**
* Opens a connection to the given URL.
@@ -27,18 +28,12 @@ public interface HttpConnector {
/**
* Default implementation that uses {@link URL#openConnection()}.
*/
HttpConnector DEFAULT = new ImpatientHttpConnector(new HttpConnector() {
public HttpURLConnection connect(URL url) throws IOException {
return (HttpURLConnection) url.openConnection();
}
});
HttpConnector DEFAULT = new ImpatientHttpConnector(url -> (HttpURLConnection) url.openConnection());
/**
* Stub implementation that is always off-line.
*/
HttpConnector OFFLINE = new HttpConnector() {
public HttpURLConnection connect(URL url) throws IOException {
throw new IOException("Offline");
}
HttpConnector OFFLINE = url -> {
throw new IOException("Offline");
};
}