日本熟妇hd丰满老熟妇,中文字幕一区二区三区在线不卡 ,亚洲成片在线观看,免费女同在线一区二区

當(dāng)下載的文件太大或者一次性下載耗時太長時,您可以通過流式下載,一次處理部分內(nèi)容,直到完成文件的下載。

注意事項(xiàng)

示例代碼

以下代碼用于流式下載examplebucket中的exampleobject.txt文件。

import com.aliyun.oss.OSS;
import com.aliyun.oss.common.auth.*;
import com.aliyun.oss.OSSClientBuilder;
import com.aliyun.oss.OSSException;
import com.aliyun.oss.model.*;
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Demo {
    public static void main(String[] args) throws Exception {
        // Endpoint以華東1(杭州)為例,其它Region請按實(shí)際情況填寫。關(guān)于其他Region對應(yīng)的Endpoint信息,請參見訪問域名和數(shù)據(jù)中心。
        String endpoint = "https://oss-cn-hangzhou.aliyuncs.com";
        // 從環(huán)境變量中獲取訪問憑證。運(yùn)行本代碼示例之前,請確保已設(shè)置環(huán)境變量OSS_ACCESS_KEY_ID和OSS_ACCESS_KEY_SECRET。
        EnvironmentVariableCredentialsProvider credentialsProvider = CredentialsProviderFactory.newEnvironmentVariableCredentialsProvider();
        // 填寫B(tài)ucket名稱,例如examplebucket。
        String bucketName = "examplebucket";
        // 填寫Object完整路徑,例如exampledir/exampleobject.txt。Object完整路徑中不能包含Bucket名稱。
        String objectName = "exampledir/exampleobject.txt";
        // 填寫B(tài)ucket所在地域。以華東1(杭州)為例,Region填寫為cn-hangzhou。
        String region = "cn-hangzhou";

         // 創(chuàng)建OSSClient實(shí)例。
        ClientBuilderConfiguration clientBuilderConfiguration = new ClientBuilderConfiguration();
        clientBuilderConfiguration.setSignatureVersion(SignVersion.V4);        
        OSS ossClient = OSSClientBuilder.create()
        .endpoint(endpoint)
        .credentialsProvider(credentialsProvider)
        .clientConfiguration(clientBuilderConfiguration)
        .region(region)               
        .build();
        
        try {
            // ossObject包含文件所在的存儲空間名稱、文件名稱、文件元數(shù)據(jù)以及一個輸入流。
            OSSObject ossObject = ossClient.getObject(bucketName, objectName);              

            // 讀取文件內(nèi)容。
            System.out.println("Object content:");
            BufferedReader reader = new BufferedReader(new InputStreamReader(ossObject.getObjectContent()));
            while (true) {
                String line = reader.readLine();
                if (line == null) break;

                System.out.println("\n" + line);
            }
            // 數(shù)據(jù)讀取完成后,獲取的流必須關(guān)閉,否則會造成連接泄漏,導(dǎo)致請求無連接可用,程序無法正常工作。
            reader.close();
            // ossObject對象使用完畢后必須關(guān)閉,否則會造成連接泄漏,導(dǎo)致請求無連接可用,程序無法正常工作。            
            ossObject.close();
       
        } catch (OSSException oe) {
            System.out.println("Caught an OSSException, which means your request made it to OSS, "
                    + "but was rejected with an error response for some reason.");
            System.out.println("Error Message:" + oe.getErrorMessage());
            System.out.println("Error Code:" + oe.getErrorCode());
            System.out.println("Request ID:" + oe.getRequestId());
            System.out.println("Host ID:" + oe.getHostId());
        } catch (Throwable ce) {
            System.out.println("Caught an ClientException, which means the client encountered "
                    + "a serious internal problem while trying to communicate with OSS, "
                    + "such as not being able to access the network.");
            System.out.println("Error Message:" + ce.getMessage());
        } finally {
            if (ossClient != null) {
                ossClient.shutdown();
            }
        }
    }
}            

相關(guān)文檔

  • 關(guān)于流式下載的完整示例代碼,請參見GitHub示例

  • 關(guān)于流式下載的API接口說明,請參見GetObject