Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit06fe5cb

Browse files
authored
Update ImageDownloader.java
1 parentb84b483 commit06fe5cb

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

‎src/main/java/generateimages/ImageDownloader.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
importjava.nio.file.Path;
1111
importjava.nio.file.Paths;
1212
importjava.nio.file.StandardCopyOption;
13+
importjava.time.Duration;
1314

1415
publicclassImageDownloader {
1516

@@ -18,8 +19,11 @@ public static void downloadImage(String imageUrl, String destinationFile)
1819
// Create an HttpClient
1920
HttpClientclient =HttpClient.newHttpClient();
2021

21-
// Create an HttpRequest for the image URL
22-
HttpRequestrequest =HttpRequest.newBuilder().uri(URI.create(imageUrl)).build();
22+
// 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();
2327

2428
// Send the request and receive the response
2529
HttpResponse<InputStream>response =

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp