in maven-resolver-transport-jetty/src/main/java/org/eclipse/aether/transport/jetty/JettyTransporter.java [246:344]
protected void implGet(GetTask task) throws Exception {
boolean resume = task.getResumeOffset() > 0L && task.getDataPath() != null;
Response response;
InputStreamResponseListener listener;
while (true) {
Request request = client.newRequest(resolve(task)).method("GET");
request.headers(m -> headers.forEach(m::add));
if (preemptiveAuth) {
mayApplyPreemptiveAuth(request);
}
if (resume) {
long resumeOffset = task.getResumeOffset();
long lastModified =
Files.getLastModifiedTime(task.getDataPath()).toMillis();
request.headers(h -> {
h.add(RANGE, "bytes=" + resumeOffset + '-');
h.addDateField(IF_UNMODIFIED_SINCE, lastModified - MODIFICATION_THRESHOLD);
h.remove(HttpHeader.ACCEPT_ENCODING);
h.add(ACCEPT_ENCODING, "identity");
});
}
listener = new InputStreamResponseListener();
request.send(listener);
try {
response = listener.get(requestTimeout, TimeUnit.MILLISECONDS);
} catch (ExecutionException e) {
Throwable t = e.getCause();
if (t instanceof Exception) {
throw (Exception) t;
} else {
throw new RuntimeException(t);
}
}
if (response.getStatus() >= MULTIPLE_CHOICES) {
if (resume && response.getStatus() == PRECONDITION_FAILED) {
resume = false;
continue;
}
JettyRFC9457Reporter.INSTANCE.generateException(listener, (statusCode, reasonPhrase) -> {
throw new HttpTransporterException(statusCode);
});
}
break;
}
long offset = 0L, length = response.getHeaders().getLongField(CONTENT_LENGTH);
if (resume) {
String range = response.getHeaders().get(CONTENT_RANGE);
if (range != null) {
Matcher m = CONTENT_RANGE_PATTERN.matcher(range);
if (!m.matches()) {
throw new IOException("Invalid Content-Range header for partial download: " + range);
}
offset = Long.parseLong(m.group(1));
length = Long.parseLong(m.group(2)) + 1L;
if (offset < 0L || offset >= length || (offset > 0L && offset != task.getResumeOffset())) {
throw new IOException("Invalid Content-Range header for partial download from offset "
+ task.getResumeOffset() + ": " + range);
}
}
}
final boolean downloadResumed = offset > 0L;
final Path dataFile = task.getDataPath();
if (dataFile == null) {
try (InputStream is = listener.getInputStream()) {
utilGet(task, is, true, length, downloadResumed);
}
} else {
try (FileUtils.CollocatedTempFile tempFile = FileUtils.newTempFile(dataFile)) {
task.setDataPath(tempFile.getPath(), downloadResumed);
if (downloadResumed && Files.isRegularFile(dataFile)) {
try (InputStream inputStream = Files.newInputStream(dataFile)) {
Files.copy(inputStream, tempFile.getPath(), StandardCopyOption.REPLACE_EXISTING);
}
}
try (InputStream is = listener.getInputStream()) {
utilGet(task, is, true, length, downloadResumed);
}
tempFile.move();
} finally {
task.setDataPath(dataFile);
}
}
if (task.getDataPath() != null && response.getHeaders().getDateField(LAST_MODIFIED) != -1) {
long lastModified =
response.getHeaders().getDateField(LAST_MODIFIED); // note: Wagon also does first not last
if (lastModified != -1) {
pathProcessor.setLastModified(task.getDataPath(), lastModified);
}
}
Map<String, String> checksums = checksumExtractor.extractChecksums(headerGetter(response));
if (checksums != null && !checksums.isEmpty()) {
checksums.forEach(task::setChecksum);
}
}