Merge pull request #3 from hxuanyu/master

[opt] refined file copy
This commit is contained in:
Yukino 2020-06-04 14:10:34 +08:00 committed by GitHub
commit deacae9dd7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -78,12 +78,13 @@ public class GridFsManager {
public void download(File targetFile, String bucketName, String fileName) throws IOException {
if (available()) {
GridFSBucket bucket = getBucket(bucketName);
byte[] buffer = new byte[1024];
try (GridFSDownloadStream gis = bucket.openDownloadStream(fileName);
BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(targetFile))
) {
while (gis.read(buffer) != -1) {
bos.write(buffer);
byte[] buffer = new byte[1024];
int bytes = 0;
while ((bytes = gis.read(buffer)) != -1) {
bos.write(buffer, 0, bytes);
}
bos.flush();
}