public InputStream getObject(String key, long startPos, long endPos, long contentLength)
      throws IOException {
    String baseUrl = String.format("http://%s/%s", mDownloadHost, key);
    String privateUrl = mAuth.privateDownloadUrl(baseUrl);
    URL url = new URL(privateUrl);
    String objectUrl = String.format("http://%s/%s?%s", mEndPoint, key, url.getQuery());
    Request request = new Request.Builder().url(objectUrl)
        .addHeader("Range",
            "bytes=" + String.valueOf(startPos) + "-"
                + String.valueOf(endPos < contentLength ? endPos - 1 : contentLength - 1))
        .addHeader("Host", mDownloadHost).get().build();
    Response response = mOkHttpClient.newCall(request).execute();
    if (response.code() == HttpStatus.SC_NOT_FOUND) {
      throw new NotFoundException("Qiniu kodo: " + response.message());
    }
    if (response.code() != 200 && response.code() != 206) {
      throw new IOException(String.format("Qiniu kodo:get object failed errcode:%d,errmsg:%s",
          response.code(), response.message()));
    }
    return response.body().byteStream();
  }
public InputStream getObject ( String key , long startPos , long endPos , long contentLength ) throws IOException { String baseUrl = String . format ( "http://%s/%s" , mDownloadHost , key ) ; String privateUrl = mAuth . privateDownloadUrl ( baseUrl ) ; URL url = new URL ( privateUrl ) ; String objectUrl = String . format ( "http://%s/%s?%s" , mEndPoint , key , url . getQuery ( ) ) ; Request request = new Request . Builder ( ) . url ( objectUrl ) . addHeader ( "Range" , "bytes=" + String . valueOf ( startPos ) + "-" + String . valueOf ( endPos < contentLength ? endPos - 1 : contentLength - 1 ) ) . addHeader ( "Host" , mDownloadHost ) . get ( ) . build ( ) ; Response response = mOkHttpClient . newCall ( request ) . execute ( ) ; if ( response . code ( ) == HttpStatus . SC_NOT_FOUND ) { throw new NotFoundException ( "Qiniu kodo: " + response . message ( ) ) ; } if ( response . code ( ) != 200 && response . code ( ) != 206 ) { throw new IOException ( String . format ( "Qiniu kodo:get object failed errcode:%d,errmsg:%s" , response . code ( ) , response . message ( ) ) ) ; } return response . body ( ) . byteStream ( ) ; }
Gets object from Qiniu kodo. All requests are authenticated by default，default expires 3600s We
use okhttp as our HTTP client and support two main parameters in the external adjustment, MAX
request and timeout time.
@param key object key
@param startPos start index for object
@param endPos end index for object
@return inputstream
@param contentLength object file size
@throws IOException