mirror of
https://github.com/PowerJob/PowerJob.git
synced 2025-07-17 00:00:04 +08:00
minor code refactor
This commit is contained in:
parent
d999f18f93
commit
8de01e2860
@ -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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 删除几天前的文件
|
* 删除几天前的文件
|
||||||
|
Loading…
x
Reference in New Issue
Block a user