Java Code Examples for com.aliyun.oss.model.OSSObject#getObjectContent()

The following examples show how to use com.aliyun.oss.model.OSSObject#getObjectContent() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DemoController.java    From zheng with MIT License 6 votes vote down vote up
@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();
}
 
Example 2
Source File: TestOSSService.java    From jframe with Apache License 2.0 6 votes vote down vote up
@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();
}
 
Example 3
Source File: OSSNotebookRepo.java    From zeppelin with Apache License 2.0 5 votes vote down vote up
@Override
public Note get(String noteId, String notePath, AuthenticationInfo subject) throws IOException {
  OSSObject ossObject = ossClient.getObject(bucketName,
          rootFolder + "/" + buildNoteFileName(noteId, notePath));
  InputStream in = null;
  try {
    in = ossObject.getObjectContent();
    return Note.fromJson(IOUtils.toString(in));
  } finally {
    if (in != null) {
      in.close();
    }
  }
}
 
Example 4
Source File: OssUtil.java    From feeyo-hlsserver with Apache License 2.0 4 votes vote down vote up
/**
 * 获取OSS Object输入流
 */
public InputStream readObject(String fileName, long streamId) {
	OSSObject ossObject = ossClient.getObject(bucketName, String.valueOf(streamId) + "/" + fileName);
	InputStream inputStream = ossObject.getObjectContent();
	return inputStream;
}
 
Example 5
Source File: AliFileFileHandler.java    From seezoon-framework-all with Apache License 2.0 4 votes vote down vote up
@Override
public InputStream download(String relativePath) throws FileNotFoundException {
	OSSObject object = ossClient.getObject(bucketName, handleRelativePath(relativePath));
	return object.getObjectContent();
}