Skip to content

Commit

Permalink
Fix find bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
ivandika3 committed Oct 6, 2024
1 parent db67bc0 commit 41d14d6
Showing 1 changed file with 26 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -779,31 +779,32 @@ private List<PartETag> uploadParts(String bucketName, String key, String uploadI
// Upload the file parts.
long filePosition = 0;
long fileLength = file.length();
FileInputStream fileInputStream = new FileInputStream(file);
for (int i = 1; filePosition < fileLength; i++) {
// Because the last part could be less than 5 MB, adjust the part size as
// needed.
partSize = Math.min(partSize, (fileLength - filePosition));

// Create the request to upload a part.
UploadPartRequest uploadRequest = new UploadPartRequest()
.withBucketName(bucketName)
.withKey(key)
.withUploadId(uploadId)
.withPartNumber(i)
.withFileOffset(filePosition)
.withFile(file)
.withPartSize(partSize);

// Upload the part and add the response's ETag to our list.
UploadPartResult uploadResult = s3Client.uploadPart(uploadRequest);
PartETag partETag = uploadResult.getPartETag();
assertEquals(i, partETag.getPartNumber());
assertEquals(DatatypeConverter.printHexBinary(
calculateDigest(fileInputStream, 0, (int) partSize)).toLowerCase(), partETag.getETag());
partETags.add(partETag);

filePosition += partSize;
try (FileInputStream fileInputStream = new FileInputStream(file)) {
for (int i = 1; filePosition < fileLength; i++) {
// Because the last part could be less than 5 MB, adjust the part size as
// needed.
partSize = Math.min(partSize, (fileLength - filePosition));

// Create the request to upload a part.
UploadPartRequest uploadRequest = new UploadPartRequest()
.withBucketName(bucketName)
.withKey(key)
.withUploadId(uploadId)
.withPartNumber(i)
.withFileOffset(filePosition)
.withFile(file)
.withPartSize(partSize);

// Upload the part and add the response's ETag to our list.
UploadPartResult uploadResult = s3Client.uploadPart(uploadRequest);
PartETag partETag = uploadResult.getPartETag();
assertEquals(i, partETag.getPartNumber());
assertEquals(DatatypeConverter.printHexBinary(
calculateDigest(fileInputStream, 0, (int) partSize)).toLowerCase(), partETag.getETag());
partETags.add(partETag);

filePosition += partSize;
}
}

return partETags;
Expand Down

0 comments on commit 41d14d6

Please sign in to comment.