本文整理汇总了Java中com.aliyun.oss.OSSClient.getObject方法的典型用法代码示例。如果您正苦于以下问题:Java OSSClient.getObject方法的具体用法?Java OSSClient.getObject怎么用?Java OSSClient.getObject使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.aliyun.oss.OSSClient
的用法示例。
在下文中一共展示了OSSClient.getObject方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getObject
import com.aliyun.oss.OSSClient; //导入方法依赖的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;
}
示例2: test
import com.aliyun.oss.OSSClient; //导入方法依赖的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();
}
示例3: getObject
import com.aliyun.oss.OSSClient; //导入方法依赖的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();
}