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,12 +60,11 @@ public class GridFsManager {
|
||||
* @throws IOException 异常
|
||||
*/
|
||||
public void store(File localFile, String bucketName, String fileName) throws IOException {
|
||||
if (db == null) {
|
||||
return;
|
||||
}
|
||||
GridFSBucket bucket = getBucket(bucketName);
|
||||
try (BufferedInputStream bis = new BufferedInputStream(new FileInputStream(localFile))) {
|
||||
bucket.uploadFromStream(fileName, bis);
|
||||
if (available()) {
|
||||
GridFSBucket bucket = getBucket(bucketName);
|
||||
try (BufferedInputStream bis = new BufferedInputStream(new FileInputStream(localFile))) {
|
||||
bucket.uploadFromStream(fileName, bis);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -77,18 +76,17 @@ public class GridFsManager {
|
||||
* @throws IOException 异常
|
||||
*/
|
||||
public void download(File targetFile, String bucketName, String fileName) throws IOException {
|
||||
if (db == null) {
|
||||
return;
|
||||
}
|
||||
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);
|
||||
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);
|
||||
}
|
||||
bos.flush();
|
||||
}
|
||||
bos.flush();
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user