|
@@ -1,7 +1,10 @@
|
|
package com.css.simulation.resource.common.util;
|
|
package com.css.simulation.resource.common.util;
|
|
|
|
|
|
|
|
+import api.common.pojo.constants.DictConstants;
|
|
|
|
+import api.common.pojo.param.RedisParameter;
|
|
|
|
+import api.common.util.ObjectUtil;
|
|
import com.css.simulation.resource.common.controller.RedisController;
|
|
import com.css.simulation.resource.common.controller.RedisController;
|
|
-import com.css.simulation.resource.common.util.processbar.ProgressStream;
|
|
|
|
|
|
+import com.css.simulation.resource.common.util.processbar.ProgressInputStream;
|
|
import io.minio.*;
|
|
import io.minio.*;
|
|
import io.minio.errors.ErrorResponseException;
|
|
import io.minio.errors.ErrorResponseException;
|
|
import io.minio.errors.InsufficientDataException;
|
|
import io.minio.errors.InsufficientDataException;
|
|
@@ -12,7 +15,6 @@ import jdk.nashorn.internal.runtime.regexp.joni.exception.InternalException;
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
import java.io.BufferedInputStream;
|
|
import java.io.BufferedInputStream;
|
|
-import java.io.FileInputStream;
|
|
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
import java.io.InputStream;
|
|
import java.io.InputStream;
|
|
import java.security.InvalidKeyException;
|
|
import java.security.InvalidKeyException;
|
|
@@ -132,13 +134,26 @@ public class MinioUtil {
|
|
RedisController redisController
|
|
RedisController redisController
|
|
) throws IOException, InsufficientDataException, ErrorResponseException, NoSuchAlgorithmException, InvalidKeyException, InvalidResponseException, XmlParserException, InternalException, io.minio.errors.ServerException, io.minio.errors.InternalException {
|
|
) throws IOException, InsufficientDataException, ErrorResponseException, NoSuchAlgorithmException, InvalidKeyException, InvalidResponseException, XmlParserException, InternalException, io.minio.errors.ServerException, io.minio.errors.InternalException {
|
|
InputStream inputStream = multipartFile.getInputStream();
|
|
InputStream inputStream = multipartFile.getInputStream();
|
|
- InputStream pis =
|
|
|
|
- new BufferedInputStream(
|
|
|
|
- new ProgressStream(redisController, objectPath, inputStream));
|
|
|
|
- minioClient.putObject(
|
|
|
|
- PutObjectArgs.builder().bucket(bucketName).object(objectName).stream(
|
|
|
|
- pis, pis.available(), -1)
|
|
|
|
- .build());
|
|
|
|
|
|
+ long fileSize = multipartFile.getSize();
|
|
|
|
+ //进度计算参数:传输量,进度标尺,文件大小,进度值
|
|
|
|
+ long[] longs = {0L, 0L, fileSize, 0L};
|
|
|
|
+ InputStream pis = new BufferedInputStream(
|
|
|
|
+ new ProgressInputStream(inputStream){
|
|
|
|
+ @Override
|
|
|
|
+ public void getStep(int readBytes){
|
|
|
|
+ RedisParameter redisParameter = getProgress(readBytes,longs);
|
|
|
|
+ if(ObjectUtil.isNotNull(redisParameter)){
|
|
|
|
+ //System.out.println("progress----:" + redisParameter.getValue());
|
|
|
|
+ redisParameter.setKey(DictConstants.ALGORITHM_KEY + objectPath);//进度缓存的 key
|
|
|
|
+ redisController.set(redisParameter);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ minioClient.putObject(PutObjectArgs.builder()
|
|
|
|
+ .bucket(bucketName)
|
|
|
|
+ .object(objectName)
|
|
|
|
+ .stream(pis, fileSize, -1)
|
|
|
|
+ .build());
|
|
pis.close();
|
|
pis.close();
|
|
}
|
|
}
|
|
|
|
|
|
@@ -171,4 +186,19 @@ public class MinioUtil {
|
|
.object(objectName)
|
|
.object(objectName)
|
|
.build());
|
|
.build());
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ public static RedisParameter getProgress(int readBytes,long[] longs){
|
|
|
|
+ double progressStep = 0.05;//进度条的步长
|
|
|
|
+ longs[0] += readBytes;//累加
|
|
|
|
+ if(longs[0] >= longs[1]){
|
|
|
|
+ longs[3] += 1;
|
|
|
|
+ double progress = progressStep * longs[3];//进度
|
|
|
|
+ longs[1] = (long) (longs[2] * progress);//标尺增长
|
|
|
|
+ RedisParameter redisParameter = new RedisParameter();
|
|
|
|
+ redisParameter.setValue(String.format("%.2f",progress-progressStep));
|
|
|
|
+ redisParameter.setMinutes(1);
|
|
|
|
+ return redisParameter;
|
|
|
|
+ }
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
}
|
|
}
|