Skip to content

Commit

Permalink
Update TOSLowLevelOutputStream.java
Browse files Browse the repository at this point in the history
  • Loading branch information
thu-david committed Jun 14, 2024
1 parent 3da6876 commit 4f76074
Showing 1 changed file with 7 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
Expand Down Expand Up @@ -106,13 +107,11 @@ protected void uploadPartInternal(
@Nullable String md5)
throws IOException {
long fileSize = file.length();
long offset = partNumber * (mPartitionSize - 1);
long partSize = mPartitionSize;
try (FileInputStream content = new FileInputStream(file)) {
content.skip(offset);
InputStream wrappedContent = new TosRepeatableBoundedFileInputStream(content, mPartitionSize);
if (fileSize - offset < mPartitionSize) {
partSize = fileSize - offset;
if (isLastPart) {
partSize = fileSize;
}
final UploadPartV2Input input = new UploadPartV2Input()
.setBucket(mBucketName)
Expand Down Expand Up @@ -180,14 +179,14 @@ protected void createEmptyObject(String key) throws IOException {

@Override
protected void putObject(String key, File file, @Nullable String md5) throws IOException {
try {
try (InputStream content = Files.newInputStream(file.toPath())) {
PutObjectInput putObjectInput = new PutObjectInput()
.setBucket(mBucketName)
.setKey(key)
.setContent(new FileInputStream(file))
.setContentLength(0);
.setContent(content)
.setContentLength(file.length()); // Set the correct content length
mContentHash = getClient().putObject(putObjectInput).getEtag();
} catch (TosClientException e) {
} catch (IOException e) {
throw new IOException(e);
}
}
Expand Down

0 comments on commit 4f76074

Please sign in to comment.