• Object Storage Service

  1. Help Center
  2. Object Storage Service
  3. Developer Guide (Java SDK)
  4. Object Download
  5. Performing a Streaming Download

Performing a Streaming Download

Sample code:

String endPoint = "yourdomainname";
String ak = "*** Provide your Access Key ***";
String sk = "*** Provide your Secret Key ***";

// Create an instance of ObsClient.
final ObsClient obsClient = new ObsClient(ak, sk, endPoint);

ObsObject obsObject = obsClient.getObject("bucketname", "objectkey");

// Read the object contents.
System.out.println("Object content:");
InputStream input = result.getObjectContent();
byte[] b = new byte[1024];
ByteArrayOutputStream bos = new ByteArrayOutputStream(); 
int len;
while ((len=input.read(b)) != -1){
       bos.write(b, 0, len);
System.out.println(new String(bos.toByteArray()));

// Close obsClient.
  • After ObsClient.getObject is called, an instance of ObsObject will be returned. This instance contains the residing bucket, name, properties, and input streams of the object.
  • You can perform operations on the input streams of an object to read and write the object contents to a local file or to the memory.

Object input streams obtained by ObsObject.getObjectContent must be closed explicitly. Otherwise, resource leakage occurs.