-
Notifications
You must be signed in to change notification settings - Fork 916
add completed to ResumableFileDownload ser/des #5254
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,8 @@ | |
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.time.Instant; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.Objects; | ||
import java.util.Optional; | ||
import java.util.OptionalLong; | ||
|
@@ -61,6 +63,7 @@ public final class ResumableFileDownload implements ResumableTransfer, | |
private final Instant s3ObjectLastModified; | ||
private final Long totalSizeInBytes; | ||
private final Instant fileLastModified; | ||
private final List<Integer> completedParts; | ||
|
||
private ResumableFileDownload(DefaultBuilder builder) { | ||
this.downloadFileRequest = Validate.paramNotNull(builder.downloadFileRequest, "downloadFileRequest"); | ||
|
@@ -69,6 +72,7 @@ private ResumableFileDownload(DefaultBuilder builder) { | |
this.s3ObjectLastModified = builder.s3ObjectLastModified; | ||
this.totalSizeInBytes = Validate.isPositiveOrNull(builder.totalSizeInBytes, "totalSizeInBytes"); | ||
this.fileLastModified = builder.fileLastModified; | ||
this.completedParts = Validate.getOrDefault(builder.completedParts, Collections::emptyList); | ||
} | ||
|
||
@Override | ||
|
@@ -94,6 +98,9 @@ public boolean equals(Object o) { | |
if (!Objects.equals(fileLastModified, that.fileLastModified)) { | ||
return false; | ||
} | ||
if (!Objects.equals(completedParts, that.completedParts)) { | ||
return false; | ||
} | ||
return Objects.equals(totalSizeInBytes, that.totalSizeInBytes); | ||
} | ||
|
||
|
@@ -104,6 +111,7 @@ public int hashCode() { | |
result = 31 * result + (s3ObjectLastModified != null ? s3ObjectLastModified.hashCode() : 0); | ||
result = 31 * result + (fileLastModified != null ? fileLastModified.hashCode() : 0); | ||
result = 31 * result + (totalSizeInBytes != null ? totalSizeInBytes.hashCode() : 0); | ||
result = 31 * result + (completedParts != null ? completedParts.hashCode() : 0); | ||
return result; | ||
} | ||
|
||
|
@@ -149,6 +157,15 @@ public OptionalLong totalSizeInBytes() { | |
return totalSizeInBytes == null ? OptionalLong.empty() : OptionalLong.of(totalSizeInBytes); | ||
} | ||
|
||
/** | ||
* The lists of parts that were successfully completed and saved to the file. Non-empty only for multipart downloads. | ||
* | ||
* @return part numbers of a multipart download that were completed saved to file. | ||
*/ | ||
public List<Integer> completedParts() { | ||
return Collections.unmodifiableList(completedParts); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we wrap with umodifableList in the ctor instead of the getter? Also, we should probably create a new list. Example: https://github.com/aws/aws-sdk-java-v2/blob/master/core/sdk-core/src/main/java/software/amazon/awssdk/core/client/config/ClientOverrideConfiguration.java#L148 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. will address in full resume PR |
||
} | ||
|
||
@Override | ||
public String toString() { | ||
return ToString.builder("ResumableFileDownload") | ||
|
@@ -157,6 +174,7 @@ public String toString() { | |
.add("s3ObjectLastModified", s3ObjectLastModified) | ||
.add("totalSizeInBytes", totalSizeInBytes) | ||
.add("downloadFileRequest", downloadFileRequest) | ||
.add("completedParts", completedParts) | ||
.build(); | ||
} | ||
|
||
|
@@ -318,6 +336,14 @@ default ResumableFileDownload.Builder downloadFileRequest(Consumer<DownloadFileR | |
* @return a reference to this object so that method calls can be chained together. | ||
*/ | ||
Builder fileLastModified(Instant lastModified); | ||
|
||
/** | ||
* For multipart download, set the lists of parts that were successfully completed and saved to the file. | ||
* | ||
* @param completedParts the list of completed parts saved to file. | ||
* @return a reference to this object so that method calls can be chained together. | ||
*/ | ||
Builder completedParts(List<Integer> completedParts); | ||
} | ||
|
||
private static final class DefaultBuilder implements Builder { | ||
|
@@ -327,6 +353,7 @@ private static final class DefaultBuilder implements Builder { | |
private Instant s3ObjectLastModified; | ||
private Long totalSizeInBytes; | ||
private Instant fileLastModified; | ||
private List<Integer> completedParts; | ||
|
||
private DefaultBuilder() { | ||
} | ||
|
@@ -337,6 +364,7 @@ private DefaultBuilder(ResumableFileDownload persistableFileDownload) { | |
this.totalSizeInBytes = persistableFileDownload.totalSizeInBytes; | ||
this.fileLastModified = persistableFileDownload.fileLastModified; | ||
this.s3ObjectLastModified = persistableFileDownload.s3ObjectLastModified; | ||
this.completedParts = persistableFileDownload.completedParts; | ||
} | ||
|
||
@Override | ||
|
@@ -369,6 +397,12 @@ public Builder fileLastModified(Instant fileLastModified) { | |
return this; | ||
} | ||
|
||
@Override | ||
public Builder completedParts(List<Integer> completedParts) { | ||
this.completedParts = Collections.unmodifiableList(completedParts); | ||
return this; | ||
} | ||
|
||
@Override | ||
public ResumableFileDownload build() { | ||
return new ResumableFileDownload(this); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the reason for List that we may download different parts in parallel in the future?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, trying to prepare for when we will do parallel write to file as well