|
1 | 1 | package com.alipay.rdf.file.storage; |
2 | 2 |
|
3 | | -import java.io.ByteArrayInputStream; |
4 | | -import java.io.File; |
5 | | -import java.io.FileInputStream; |
6 | | -import java.io.FileNotFoundException; |
7 | | -import java.io.IOException; |
8 | | -import java.io.InputStream; |
9 | | -import java.util.ArrayList; |
10 | | -import java.util.List; |
11 | | -import java.util.regex.Pattern; |
12 | | - |
13 | 3 | import com.alipay.rdf.file.exception.RdfErrorEnum; |
14 | 4 | import com.alipay.rdf.file.exception.RdfFileException; |
15 | 5 | import com.alipay.rdf.file.interfaces.FileFactory; |
|
25 | 15 | import com.aliyun.oss.OSSClient; |
26 | 16 | import com.aliyun.oss.OSSErrorCode; |
27 | 17 | import com.aliyun.oss.OSSException; |
28 | | -import com.aliyun.oss.model.AppendObjectRequest; |
29 | | -import com.aliyun.oss.model.AppendObjectResult; |
30 | | -import com.aliyun.oss.model.CompleteMultipartUploadRequest; |
31 | | -import com.aliyun.oss.model.CompleteMultipartUploadResult; |
32 | | -import com.aliyun.oss.model.CopyObjectResult; |
33 | | -import com.aliyun.oss.model.GetObjectRequest; |
34 | | -import com.aliyun.oss.model.InitiateMultipartUploadRequest; |
35 | | -import com.aliyun.oss.model.InitiateMultipartUploadResult; |
36 | | -import com.aliyun.oss.model.ListObjectsRequest; |
37 | | -import com.aliyun.oss.model.OSSObject; |
38 | | -import com.aliyun.oss.model.OSSObjectSummary; |
39 | | -import com.aliyun.oss.model.ObjectListing; |
40 | | -import com.aliyun.oss.model.ObjectMetadata; |
41 | | -import com.aliyun.oss.model.PartETag; |
42 | | -import com.aliyun.oss.model.PutObjectResult; |
43 | | -import com.aliyun.oss.model.UploadFileRequest; |
44 | | -import com.aliyun.oss.model.UploadPartCopyRequest; |
45 | | -import com.aliyun.oss.model.UploadPartCopyResult; |
| 18 | +import com.aliyun.oss.model.*; |
| 19 | + |
| 20 | +import java.io.*; |
| 21 | +import java.util.ArrayList; |
| 22 | +import java.util.List; |
| 23 | +import java.util.regex.Pattern; |
46 | 24 |
|
47 | 25 | /** |
48 | 26 | * Copyright (C) 2013-2018 Ant Financial Services Group |
@@ -232,6 +210,7 @@ public List<String> listFiles(String folderName, FilePathFilter... fileFilters) |
232 | 210 | * helper method for adding FilePathFilter check when listing files |
233 | 211 | * |
234 | 212 | * @param folderName |
| 213 | + * @param all |
235 | 214 | * @param fileFilters |
236 | 215 | * @return |
237 | 216 | */ |
@@ -276,11 +255,15 @@ public List<String> listAllFiles(String folderName, FilePathFilter... fileFilter |
276 | 255 | public void download(String srcOSSPath, String toFile) { |
277 | 256 | srcOSSPath = toOSSPath(srcOSSPath); |
278 | 257 | List<String> fileNames = listAllFiles(srcOSSPath); |
279 | | - if (isExist(srcOSSPath)) { |
| 258 | + if(fileNames.isEmpty()){ |
| 259 | + // 以下两种情况需要抛出异常: |
| 260 | + // 1.单个文件场景且文件未找到 |
| 261 | + // 2.文件夹场景但文件夹下没有任何文件(可能是文件夹名称错误也可能是事实上该文件夹下就没有文件,因为oss无法区分这两种情况) |
| 262 | + if(!isExist(srcOSSPath)){ |
| 263 | + throw new RdfFileException("rdf-file# oss donwLoad srcOSSPath=" + srcOSSPath + " 不存在", |
| 264 | + RdfErrorEnum.NOT_EXSIT); |
| 265 | + } |
280 | 266 | fileNames.add(srcOSSPath); |
281 | | - } else { |
282 | | - throw new RdfFileException("rdf-file# oss donwLoad srcOSSPath=" + srcOSSPath + " 不存在", |
283 | | - RdfErrorEnum.NOT_EXSIT); |
284 | 267 | } |
285 | 268 | String temp = ""; |
286 | 269 | for (String name : fileNames) { |
|
0 commit comments