use of com.zhouzifei.tool.common.ServiceException in project simpleFS by shengdingbox.
the class QiniuApiClient method init.
@Override
public QiniuApiClient init(FileProperties fileProperties) {
final QiniuFileProperties qiniuFileProperties = fileProperties.getQiniu();
String accessKey = qiniuFileProperties.getAccessKey();
String secretKey = qiniuFileProperties.getSecretKey();
this.bucket = qiniuFileProperties.getBucketName();
String url = qiniuFileProperties.getUrl();
checkDomainUrl(url);
if (StringUtils.isNullOrEmpty(accessKey) || StringUtils.isNullOrEmpty(secretKey) || StringUtils.isNullOrEmpty(bucket)) {
throw new ServiceException("[" + this.storageType + "]尚未配置七牛云,文件上传功能暂时不可用!");
}
auth = Auth.create(accessKey, secretKey);
return this;
}
use of com.zhouzifei.tool.common.ServiceException in project simpleFS by shengdingbox.
the class FileUtil method down.
// 下载视频
public static void down(InputStream ins, String saveFile) {
try (InputStream inputStream = StreamUtil.clone(ins)) {
int length = inputStream.available();
FileOutputStream fs = new FileOutputStream(saveFile);
byte[] buffer = new byte[1024];
int i = 0, j = 0;
int byteRead;
while ((byteRead = inputStream.read(buffer)) != -1) {
i++;
fs.write(buffer, 0, byteRead);
if (i % 500 == 0) {
j++;
File file2 = new File(saveFile);
// 控制输出小数点后的位数
DecimalFormat df = new DecimalFormat("#.##");
float f = (file2.length() / (float) length) * 100;
System.out.print("已下载:" + df.format(f) + "%\t\t");
if (j % 5 == 0) {
log.info("下载完成");
}
}
}
log.info("\n已下载:100.00%");
ins.close();
fs.close();
} catch (Exception e) {
throw new ServiceException("9999999", "文件下载失败", e);
}
}
use of com.zhouzifei.tool.common.ServiceException in project simpleFS by shengdingbox.
the class StreamUtil method clone.
/**
* 复制InputStream
*
* @param is InputStream
* @return
*/
public static InputStream clone(InputStream is) {
if (null == is) {
throw new ServiceException("无法获取文件流,文件不可用!");
}
try {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
int len;
while ((len = is.read(buffer)) > -1) {
baos.write(buffer, 0, len);
}
baos.flush();
return new ByteArrayInputStream(baos.toByteArray());
} catch (IOException e) {
throw new ServiceException("无法复制当前文件流!{}", e.getMessage());
}
}
Aggregations