We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see ourdocumentation.
There was an error while loading.Please reload this page.
1 parentb84b483 commit06fe5cbCopy full SHA for 06fe5cb
src/main/java/generateimages/ImageDownloader.java
@@ -10,6 +10,7 @@
10
importjava.nio.file.Path;
11
importjava.nio.file.Paths;
12
importjava.nio.file.StandardCopyOption;
13
+importjava.time.Duration;
14
15
publicclassImageDownloader {
16
@@ -18,8 +19,11 @@ public static void downloadImage(String imageUrl, String destinationFile)
18
19
// Create an HttpClient
20
HttpClientclient =HttpClient.newHttpClient();
21
-// Create an HttpRequest for the image URL
22
-HttpRequestrequest =HttpRequest.newBuilder().uri(URI.create(imageUrl)).build();
+// Create an HttpRequest for the image URL with a timeout of 20 seconds
23
+HttpRequestrequest =HttpRequest.newBuilder()
24
+ .uri(URI.create(imageUrl))
25
+ .timeout(Duration.ofSeconds(20))// Set timeout duration
26
+ .build();
27
28
// Send the request and receive the response
29
HttpResponse<InputStream>response =