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 异常
|
* @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);
|
||||||
}
|
try (BufferedInputStream bis = new BufferedInputStream(new FileInputStream(localFile))) {
|
||||||
GridFSBucket bucket = getBucket(bucketName);
|
bucket.uploadFromStream(fileName, bis);
|
||||||
try (BufferedInputStream bis = new BufferedInputStream(new FileInputStream(localFile))) {
|
}
|
||||||
bucket.uploadFromStream(fileName, bis);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -77,18 +76,17 @@ 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);
|
||||||
}
|
byte[] buffer = new byte[1024];
|
||||||
GridFSBucket bucket = getBucket(bucketName);
|
try (GridFSDownloadStream gis = bucket.openDownloadStream(fileName);
|
||||||
byte[] buffer = new byte[1024];
|
BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(targetFile))
|
||||||
try (GridFSDownloadStream gis = bucket.openDownloadStream(fileName);
|
) {
|
||||||
BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(targetFile))
|
while (gis.read(buffer) != -1) {
|
||||||
) {
|
bos.write(buffer);
|
||||||
while (gis.read(buffer) != -1) {
|
}
|
||||||
bos.write(buffer);
|
bos.flush();
|
||||||
}
|
}
|
||||||
bos.flush();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user