minor code refactor

This commit is contained in:
hxuanyu 2020-06-04 13:25:17 +10:00
parent d999f18f93
commit 8de01e2860

View File

@ -60,14 +60,13 @@ public class GridFsManager {
* @throws IOException 异常 * @throws IOException 异常
*/ */
public void store(File localFile, String bucketName, String fileName) throws IOException { public void store(File localFile, String bucketName, String fileName) throws IOException {
if (db == null) { if (available()) {
return;
}
GridFSBucket bucket = getBucket(bucketName); GridFSBucket bucket = getBucket(bucketName);
try (BufferedInputStream bis = new BufferedInputStream(new FileInputStream(localFile))) { try (BufferedInputStream bis = new BufferedInputStream(new FileInputStream(localFile))) {
bucket.uploadFromStream(fileName, bis); bucket.uploadFromStream(fileName, bis);
} }
} }
}
/** /**
* GridFS 下载文件 * GridFS 下载文件
@ -77,9 +76,7 @@ public class GridFsManager {
* @throws IOException 异常 * @throws IOException 异常
*/ */
public void download(File targetFile, String bucketName, String fileName) throws IOException { public void download(File targetFile, String bucketName, String fileName) throws IOException {
if (db == null) { if (available()) {
return;
}
GridFSBucket bucket = getBucket(bucketName); GridFSBucket bucket = getBucket(bucketName);
byte[] buffer = new byte[1024]; byte[] buffer = new byte[1024];
try (GridFSDownloadStream gis = bucket.openDownloadStream(fileName); try (GridFSDownloadStream gis = bucket.openDownloadStream(fileName);
@ -91,6 +88,7 @@ public class GridFsManager {
bos.flush(); bos.flush();
} }
} }
}
/** /**
* 删除几天前的文件 * 删除几天前的文件