本文整理汇总了Java中com.aliyun.oss.model.OSSObject类的典型用法代码示例。如果您正苦于以下问题:Java OSSObject类的具体用法?Java OSSObject怎么用?Java OSSObject使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
OSSObject类属于com.aliyun.oss.model包,在下文中一共展示了OSSObject类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: download1
import com.aliyun.oss.model.OSSObject; //导入依赖的package包/类
@GetMapping("/aliyun/download1")
public String download1() throws IOException {
StringBuffer result = new StringBuffer();
OSSObject ossObject = aliyunOssClient.getObject(OssConstant.ALIYUN_OSS_BUCKET_NAME, "text.txt");
InputStream content = ossObject.getObjectContent();
if (content != null) {
BufferedReader reader = new BufferedReader(new InputStreamReader(content));
while (true) {
String line = reader.readLine();
if (line == null) break;
result.append("\n" + line);
}
content.close();
}
return result.toString();
}
示例2: download1
import com.aliyun.oss.model.OSSObject; //导入依赖的package包/类
@GetMapping("/aliyun/download1")
public String download1() throws IOException {
StringBuffer result = new StringBuffer();
OSSObject ossObject = aliyunOssClient.getObject(OssConstant.ALIYUN_OSS_BUCKET_NAME, "text.txt");
InputStream content = ossObject.getObjectContent();
if (content != null) {
BufferedReader reader = new BufferedReader(new InputStreamReader(content));
while (true) {
String line = reader.readLine();
if (line == null) {
break;
}
result.append("\n" + line);
}
content.close();
}
return result.toString();
}
示例3: test
import com.aliyun.oss.model.OSSObject; //导入依赖的package包/类
@Test
public void test() throws OSSException, ClientException, IOException {
OSSClient client = new OSSClient("oss-cn-hangzhou.aliyuncs.com", "", "", "");
// BucketInfo info = client.getBucketInfo("edrmry");
boolean exists = client.doesBucketExist("edrmry");
System.out.println(exists);
// System.out.println(client.listBuckets().size());
// client.createBucket("dzh1");
PutObjectResult r = client.putObject("edrmry", "dzh1.jpg", new FileInputStream("/Users/dzh/Pictures/8.pic.jpg"));
System.out.println(r.getETag());
OSSObject o = client.getObject("edrmry", "dzh1");
InputStream is = o.getObjectContent();
FileOutputStream fos = new FileOutputStream("/Users/dzh/Pictures/8.pic.2.jpg");
int len = 0;
byte[] buf = new byte[32];
while ((len = is.read(buf)) != -1) {
fos.write(buf, 0, len);
}
fos.flush();
fos.close();
}
示例4: parseToCCSObject
import com.aliyun.oss.model.OSSObject; //导入依赖的package包/类
/**
* OSSObject到CCSObject
*/
public static CCSObject parseToCCSObject(OSSObject ossObject) {
CCSObject ccsObject = new CCSObject();
ccsObject.setBucketName(ossObject.getBucketName());
ccsObject.setCcsPath(ossObject.getKey());
ccsObject.setObjectContent(ossObject.getObjectContent());
ccsObject.setCcsObjectMetadata(parseToCCSObjectMetadata(ossObject.getObjectMetadata()));
return ccsObject;
}
示例5: getObject
import com.aliyun.oss.model.OSSObject; //导入依赖的package包/类
public static InputStream getObject(String bucketName, String fileName) {
// 初始化OSSClient
OSSClient client = getOSSClient();
// client.getObject(new GetObjectRequest(bucketName, key),new
// File(filename));
OSSObject ossObject = client.getObject(bucketName, fileName);
InputStream inputStream = ossObject.getObjectContent();
return inputStream;
}
示例6: getBlob
import com.aliyun.oss.model.OSSObject; //导入依赖的package包/类
@Override
public Blob getBlob(String container, String name, GetOptions options) {
OSS oss = api.getOSSClient(OSSApi.DEFAULT_REGION);
String region = oss.getBucketLocation(container);
oss = api.getOSSClient(region);
GetObjectRequest req = new GetObjectRequest(container, name);
OSSObject object = oss.getObject(req);
String filename = object.getKey();
return blobBuilder(container)
.name(filename)
.payload(object.getObjectContent())
.build();
}
示例7: get
import com.aliyun.oss.model.OSSObject; //导入依赖的package包/类
public InputStream get(@Nonnull String bucketName, @Nonnull String folder, @Nonnull String name) {
checkNotNull(bucketName);
checkNotNull(folder);
checkNotNull(name);
String key = formatKey(folder, name);
OSSObject object = ossClient.getObject(bucketName, key);
return object.getObjectContent();
}
示例8: getOSSObject
import com.aliyun.oss.model.OSSObject; //导入依赖的package包/类
public Optional<OSSObject> getOSSObject(){
if(ossObject!=null){
return ossObject;
}
if(!ossClient.doesObjectExist(bucketName, key)){
ossObject = Optional.empty();
}else{
ossObject = Optional.ofNullable(ossClient.getObject(bucketName, key));
}
return ossObject;
}
示例9: override
import com.aliyun.oss.model.OSSObject; //导入依赖的package包/类
public ObjectOperation override(File file){
Optional<OSSObject> opt = getOSSObject();
if(!opt.isPresent()){
throw new BaseException("key["+key+"] is not exists in bucket["+bucketName+"]");
}
return store(file);
}
示例10: blobMetadata
import com.aliyun.oss.model.OSSObject; //导入依赖的package包/类
@Override
public BlobMetadata blobMetadata(String container, String name) {
OSS oss = api.getOSSClient(OSSApi.DEFAULT_REGION);
String region = oss.getBucketLocation(container);
oss = api.getOSSClient(region);
OSSObject object = oss.getObject(container, name);
Calendar time = Calendar.getInstance();
time.set(Calendar.HOUR, time.get(Calendar.HOUR) + 1);
Date expires = time.getTime();
URL url = oss.generatePresignedUrl(container, name, expires);
URI uri = null;
try {
uri = url.toURI();
} catch (URISyntaxException e) {
logger.warn(e, e.getMessage());
}
Location location = new LocationBuilder()
.id(region)
.scope(LocationScope.REGION)
.description(region)
.build();
ContentMetadata cm = ContentMetadataBuilder.create()
.expires(expires)
.contentDisposition(object.getObjectMetadata().getContentDisposition())
.contentEncoding(object.getObjectMetadata().getContentEncoding())
.contentLength(object.getObjectMetadata().getContentLength())
.contentType(object.getObjectMetadata().getContentType())
.build();
return new BlobMetadataImpl(
object.getKey(),
object.getKey(),
location,
uri,
object.getObjectMetadata().getETag(),
object.getObjectMetadata().getLastModified(),
object.getObjectMetadata().getLastModified(),
object.getObjectMetadata().getUserMetadata(),
uri,
object.getBucketName(),
cm);
}
示例11: getObject
import com.aliyun.oss.model.OSSObject; //导入依赖的package包/类
public static void getObject(OSSClient client, String bucketName, String key) throws IOException {
// 获取Object,返回结果为OSSObject对象
OSSObject object = client.getObject(bucketName, key);
// 获取Object的输入流
InputStream objectContent = object.getObjectContent();
// 处理Object
// 关闭流
objectContent.close();
}