Skip to content

Commit

Permalink
Tidy up
Browse files Browse the repository at this point in the history
  • Loading branch information
cstamas committed Oct 17, 2023
1 parent efa07c7 commit 02fc2b5
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import java.net.http.HttpResponse;
import java.nio.file.Files;
import java.nio.file.StandardCopyOption;
import java.nio.file.attribute.FileTime;
import java.security.NoSuchAlgorithmException;
import java.text.SimpleDateFormat;
import java.time.Duration;
Expand All @@ -60,7 +61,9 @@
import org.eclipse.aether.util.FileUtils;

/**
* A transporter for HTTP/HTTPS.
* JDK Transport using {@link java.net.http.HttpClient}.
*
* @since TBD
*/
final class JdkHttpTransporter extends AbstractTransporter {
private static final int MULTIPLE_CHOICES = 300;
Expand All @@ -85,6 +88,8 @@ final class JdkHttpTransporter extends AbstractTransporter {

private static final String USER_AGENT = "User-Agent";

private static final String LAST_MODIFIED = "Last-Modified";

private static final Pattern CONTENT_RANGE_PATTERN =
Pattern.compile("\\s*bytes\\s+([0-9]+)\\s*-\\s*([0-9]+)\\s*/.*");

Expand Down Expand Up @@ -244,6 +249,16 @@ protected void implGet(GetTask task) throws Exception {
task.setDataFile(dataFile);
}
}
if (task.getDataFile() != null) {
String lastModifiedHeader =
response.headers().firstValue(LAST_MODIFIED).orElse(null); // note: Wagon also does first not last
if (lastModifiedHeader != null) {
Date lastModified = createRFC7231().parse(lastModifiedHeader);
if (lastModified != null) {
Files.setLastModifiedTime(task.getDataFile().toPath(), FileTime.fromMillis(lastModified.getTime()));
}
}
}
Map<String, String> checksums = extractXChecksums(response);
if (checksums != null) {
checksums.forEach(task::setChecksum);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import static java.util.Objects.requireNonNull;

/**
* JDK11 Transport factory.
* JDK Transport factory.
*
* @since TBD
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import static java.util.Objects.requireNonNull;

/**
* JDK8 Transport factory: is no-op.
* JDK Transport factory: on Java 8 is no-op.
*
* @since TBD
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
* under the License.
*/
/**
* Support for downloads/uploads via the HTTP and HTTPS protocols. Below Java 11 this implementation
* is no-op.
* Support for downloads/uploads via the HTTP and HTTPS protocols. This implementation is no-op on Java versions
* below 11.
*
* @since TBD
*/
Expand Down

0 comments on commit 02fc2b5

Please sign in to comment.