diff --git a/src/main/java/org/libj/net/Downloads.java b/src/main/java/org/libj/net/Downloads.java index 5173eaa..6f7af2e 100644 --- a/src/main/java/org/libj/net/Downloads.java +++ b/src/main/java/org/libj/net/Downloads.java @@ -141,7 +141,7 @@ public static HttpURLConnection downloadFile(final URL fromUrl, final File toFil * @throws IllegalArgumentException If the {@code connectTimeout} or {@code readTimeout} parameter is negative. */ public static HttpURLConnection downloadFile(final URL fromUrl, final File toFile, final int connectTimeout, final int readTimeout, final boolean followRedirects, CopyOption ... options) throws IOException { - final HttpURLConnection connection = (HttpURLConnection)(followRedirects ? URLConnections.checkFollowRedirect(fromUrl.openConnection(), c -> beforeDownloadFile(c, connectTimeout, readTimeout, toFile)) : fromUrl.openConnection()); + final HttpURLConnection connection = (HttpURLConnection)(followRedirects ? URLConnections.checkFollowRedirect(fromUrl.openConnection(), (final HttpURLConnection c) -> beforeDownloadFile(c, connectTimeout, readTimeout, toFile)) : fromUrl.openConnection()); try { if (connection.getResponseCode() == HttpURLConnection.HTTP_OK) { try (final InputStream in = connection.getInputStream()) { diff --git a/src/main/java/org/libj/net/HTTP.java b/src/main/java/org/libj/net/HTTP.java index d2ba3b0..31b3109 100644 --- a/src/main/java/org/libj/net/HTTP.java +++ b/src/main/java/org/libj/net/HTTP.java @@ -20,6 +20,7 @@ import java.io.InputStream; import java.io.OutputStreamWriter; import java.io.UnsupportedEncodingException; +import java.net.HttpURLConnection; import java.net.MalformedURLException; import java.net.URL; import java.net.URLConnection; @@ -27,7 +28,6 @@ import java.util.Iterator; import java.util.List; import java.util.Map; -import java.util.Properties; /** * Utility functions pertaining to the {@link HTTP} protocol. @@ -77,7 +77,7 @@ public static InputStream getAsStream(final String url, final Map parameters, final String charset) throws IOException, UnsupportedEncodingException { - return URLConnections.checkFollowRedirect(get(url, parameters, charset).openConnection(), c -> c.setUseCaches(false)).getInputStream(); + return URLConnections.checkFollowRedirect(get(url, parameters, charset).openConnection(), (final HttpURLConnection c) -> c.setUseCaches(false)).getInputStream(); } /** @@ -92,7 +92,7 @@ public static InputStream getAsStream(final String url, final Map c.setUseCaches(false)).getInputStream(); + return URLConnections.checkFollowRedirect(url.openConnection(), (final HttpURLConnection c) -> c.setUseCaches(false)).getInputStream(); } /** @@ -139,7 +139,7 @@ public static InputStream postAsStream(final URL url, final Map * @throws IOException If an I/O error has occurred. * @throws NullPointerException If {@code url} is null. */ - public static InputStream postAsStream(final URL url, final Map parameters, final Properties properties) throws IOException { // FIXME: Should switch Properties to HashMap, and also need to make it case-insensitive? + public static InputStream postAsStream(final URL url, final Map parameters, final Map properties) throws IOException { return postAsStream(url, parameters, properties, null); } @@ -156,8 +156,8 @@ public static InputStream postAsStream(final URL url, final Map * @throws IOException If an I/O error has occurred. * @throws NullPointerException If {@code url} is null. */ - public static InputStream postAsStream(final URL url, final Map parameters, final Properties properties, final List cookies) throws IOException { // FIXME: Should switch Properties to HashMap, and also need to make it case-insensitive? - String charset = properties != null ? properties.getProperty("accept-charset") : null; + public static InputStream postAsStream(final URL url, final Map parameters, final Map properties, final List cookies) throws IOException { + String charset = properties != null ? properties.get("accept-charset") : null; if (charset == null) charset = "UTF-8"; @@ -167,8 +167,8 @@ public static InputStream postAsStream(final URL url, final Map urlConnection.setDoOutput(true); // Triggers POST // urlConnection.setRequestProperty("content-type", "application/x-www-form-urlencoded"); if (properties != null && properties.size() > 0) - for (final Map.Entry property : properties.entrySet()) // [S] - urlConnection.setRequestProperty((String)property.getKey(), (String)property.getValue()); + for (final Map.Entry property : properties.entrySet()) // [S] + urlConnection.setRequestProperty(property.getKey(), property.getValue()); if (cookies != null) { final Map.Entry cookie = Cookies.createCookieHeader(cookies);