If you need only part of the data in an object, you can use range download to download data within the specified range.

Run the following code to perform a range download task:

// objectKey is equivalent to objectName and indicates the complete path of the object that you want to download from OSS. The path must include the file extension of the object. For example, you can set objectKey to abc/efg/123.jpg.
GetObjectRequest get = new GetObjectRequest("<bucketName>", "<objectKey>");

// Set the download range.
get.setRange(new Range(0, 99)); // Download the 100 bytes of data within the range of Byte 0 to Byte 99. The valid range starts from Byte 0.
// get.setRange(new Range(100, Range.INFINITE)); // Download the data within the range of Byte 100 to the end of the object.

OSSAsyncTask task = oss.asyncGetObject(get, new OSSCompletedCallback<GetObjectRequest, GetObjectResult>() {
    @Override
    public void onSuccess(GetObjectRequest request, GetObjectResult result) {
        // The object is downloaded.
        InputStream inputStream = result.getObjectContent();

        byte[] buffer = new byte[2048];
        int len;

        try {
            while ((len = inputStream.read(buffer)) ! = -1) {
                // Process the downloaded data
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    @Override
    public void onFailure(GetObjectRequest request, ClientException clientExcepion, ServiceException serviceException) {
        // Handle request exceptions.
        if (clientExcepion ! = null) {
            // Handle client exceptions, such as network exceptions.
            clientExcepion.printStackTrace();
        }
        if (serviceException ! = null) {
            // Handle service exceptions.
            Log.e("ErrorCode", serviceException.getErrorCode());
            Log.e("RequestId", serviceException.getRequestId());
            Log.e("HostId", serviceException.getHostId());
            Log.e("RawMessage", serviceException.getRawMessage());
        }
    }
});