Skip to content

Commit

Permalink
Explicit lambda argument types
Browse files Browse the repository at this point in the history
  • Loading branch information
safris committed Oct 9, 2024
1 parent c588915 commit 9b86fc5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/main/java/org/libj/net/Downloads.java
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down
16 changes: 8 additions & 8 deletions src/main/java/org/libj/net/HTTP.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@
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;
import java.net.URLEncoder;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Properties;

/**
* Utility functions pertaining to the {@link HTTP} protocol.
Expand Down Expand Up @@ -77,7 +77,7 @@ public static InputStream getAsStream(final String url, final Map<String,String[
* @throws UnsupportedEncodingException If the provided charset is not supported.
*/
public static InputStream getAsStream(final String url, final Map<String,String[]> 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();
}

/**
Expand All @@ -92,7 +92,7 @@ public static InputStream getAsStream(final String url, final Map<String,String[
* @throws UnsupportedEncodingException If the provided charset is not supported.
*/
public static InputStream getAsStream(final URL url) throws IOException, UnsupportedEncodingException {
return URLConnections.checkFollowRedirect(url.openConnection(), c -> c.setUseCaches(false)).getInputStream();
return URLConnections.checkFollowRedirect(url.openConnection(), (final HttpURLConnection c) -> c.setUseCaches(false)).getInputStream();
}

/**
Expand Down Expand Up @@ -139,7 +139,7 @@ public static InputStream postAsStream(final URL url, final Map<String,String[]>
* @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<String,String[]> 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<String,String[]> parameters, final Map<String,String> properties) throws IOException {
return postAsStream(url, parameters, properties, null);
}

Expand All @@ -156,8 +156,8 @@ public static InputStream postAsStream(final URL url, final Map<String,String[]>
* @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<String,String[]> parameters, final Properties properties, final List<String> 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<String,String[]> parameters, final Map<String,String> properties, final List<String> cookies) throws IOException {
String charset = properties != null ? properties.get("accept-charset") : null;
if (charset == null)
charset = "UTF-8";

Expand All @@ -167,8 +167,8 @@ public static InputStream postAsStream(final URL url, final Map<String,String[]>
urlConnection.setDoOutput(true); // Triggers POST
// urlConnection.setRequestProperty("content-type", "application/x-www-form-urlencoded");
if (properties != null && properties.size() > 0)
for (final Map.Entry<Object,Object> property : properties.entrySet()) // [S]
urlConnection.setRequestProperty((String)property.getKey(), (String)property.getValue());
for (final Map.Entry<String,String> property : properties.entrySet()) // [S]
urlConnection.setRequestProperty(property.getKey(), property.getValue());

if (cookies != null) {
final Map.Entry<String,String> cookie = Cookies.createCookieHeader(cookies);
Expand Down

0 comments on commit 9b86fc5

Please sign in to comment.