Skip to content

Commit

Permalink
perf($OSS): transform IO by NIO
Browse files Browse the repository at this point in the history
  • Loading branch information
johnnymillergh committed Aug 22, 2021
1 parent b5cb77c commit bce0cf4
Showing 1 changed file with 4 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.io.IoUtil;
import cn.hutool.core.io.NioUtil;
import com.jmsoftware.maf.osscenter.read.entity.SerializableStatObjectResponse;
import com.jmsoftware.maf.osscenter.read.service.ReadResourceService;
import com.jmsoftware.maf.springcloudstarter.minio.MinioHelper;
Expand Down Expand Up @@ -49,7 +50,7 @@ public ResponseEntity<StreamingResponseBody> asyncStreamSingleResource(@NotBlank
.contentLength(statObjectResponse.size())
.contentType(MediaType.parseMediaType(statObjectResponse.contentType()))
.body(outputStream -> {
IoUtil.copy(getObjectResponse, outputStream);
NioUtil.copyByNIO(getObjectResponse, outputStream, NioUtil.DEFAULT_BUFFER_SIZE, null);
IoUtil.close(getObjectResponse);
});
}
Expand All @@ -75,7 +76,7 @@ public ResponseEntity<StreamingResponseBody> asyncDownloadSingleResource(@NotBla
.contentLength(statObjectResponse.size())
.contentType(MediaType.parseMediaType(statObjectResponse.contentType()))
.body((outputStream -> {
IoUtil.copy(getObjectResponse, outputStream);
NioUtil.copyByNIO(getObjectResponse, outputStream, NioUtil.DEFAULT_LARGE_BUFFER_SIZE, null);
IoUtil.close(getObjectResponse);
}));
}
Expand All @@ -102,7 +103,7 @@ private ResponseEntity<StreamingResponseBody> asyncGetResourceRegion(String buck
.contentLength(rangeLength)
.contentType(MediaType.parseMediaType(statObjectResponse.contentType()))
.body(outputStream -> {
IoUtil.copy(getObjectResponse, outputStream);
NioUtil.copyByNIO(getObjectResponse, outputStream, NioUtil.DEFAULT_LARGE_BUFFER_SIZE, null);
IoUtil.close(getObjectResponse);
});
}
Expand Down

0 comments on commit bce0cf4

Please sign in to comment.