mirror of
https://gitee.com/mirrors/Spring-Cloud-Alibaba.git
synced 2021-06-26 13:25:11 +08:00
Optional value should only be accessed after calling isPresent()
This commit is contained in:
parent
44884d7ed4
commit
dc0a60b178
@ -16,6 +16,14 @@
|
|||||||
|
|
||||||
package com.alibaba.alicloud.oss.resource;
|
package com.alibaba.alicloud.oss.resource;
|
||||||
|
|
||||||
|
import com.aliyun.oss.ClientException;
|
||||||
|
import com.aliyun.oss.OSS;
|
||||||
|
import com.aliyun.oss.OSSException;
|
||||||
|
import com.aliyun.oss.model.Bucket;
|
||||||
|
import com.aliyun.oss.model.OSSObject;
|
||||||
|
import org.springframework.core.io.Resource;
|
||||||
|
import org.springframework.util.Assert;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@ -23,15 +31,7 @@ import java.io.InputStream;
|
|||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.net.URISyntaxException;
|
import java.net.URISyntaxException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
import java.util.Optional;
|
||||||
import org.springframework.core.io.Resource;
|
|
||||||
import org.springframework.util.Assert;
|
|
||||||
|
|
||||||
import com.aliyun.oss.ClientException;
|
|
||||||
import com.aliyun.oss.OSS;
|
|
||||||
import com.aliyun.oss.OSSException;
|
|
||||||
import com.aliyun.oss.model.Bucket;
|
|
||||||
import com.aliyun.oss.model.OSSObject;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implements {@link Resource} for reading and writing objects in Aliyun Object Storage
|
* Implements {@link Resource} for reading and writing objects in Aliyun Object Storage
|
||||||
@ -155,9 +155,9 @@ public class OssStorageResource implements Resource {
|
|||||||
* @return the bucket if it exists, or null otherwise
|
* @return the bucket if it exists, or null otherwise
|
||||||
*/
|
*/
|
||||||
public Bucket getBucket() {
|
public Bucket getBucket() {
|
||||||
return this.oss.listBuckets().stream()
|
Optional<Bucket> value = this.oss.listBuckets().stream()
|
||||||
.filter(bucket -> bucket.getName().equals(this.bucketName)).findFirst()
|
.filter(bucket -> bucket.getName().equals(this.bucketName)).findFirst();
|
||||||
.get();
|
return value.orElse(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user