Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/185.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 使用gzip压缩,通过restapi从googledrive下载文件_Android_Google Drive Api_Gzip - Fatal编程技术网

Android 使用gzip压缩,通过restapi从googledrive下载文件

Android 使用gzip压缩,通过restapi从googledrive下载文件,android,google-drive-api,gzip,Android,Google Drive Api,Gzip,我正在使用以下代码从Google drive下载一个公共共享文件。它很好用 InputStream input = null; OutputStream output = null; HttpURLConnection httpsURLConnectionToGoogleDrive = (HttpURLConnection) new URL(downloadUrl).openConnection(); httpsURLConnectionToGoogleDrive.connect(); lo

我正在使用以下代码从Google drive下载一个公共共享文件。它很好用

InputStream input = null;
OutputStream output = null;

HttpURLConnection httpsURLConnectionToGoogleDrive = (HttpURLConnection) new URL(downloadUrl).openConnection();
httpsURLConnectionToGoogleDrive.connect();

long fileLength = httpsURLConnectionToGoogleDrive.getContentLength();
input = httpsURLConnectionToGoogleDrive.getInputStream();

byte data[] = new byte[MediaHttpUploader.MINIMUM_CHUNK_SIZE];
int count;
while ((count = input.read(data)) != -1) {
    // allow canceling with back button
    if (isCancelled()) {
        input.close();
        return null;
    }
    total += count;
    log("Received Up To : "+ total + " ("+ count +") ");
    // publishing the progress....
    if (fileLength > 0) { // only if total length is known
        publishProgress((int) (total * 100 / fileLength));
    }
    output.write(data, 0, count);
}
现在,我想添加gzip压缩以节省带宽。我从中添加了以下代码:-

httpsURLConnectionToGoogleDrive.setRequestProperty("Accept-Encoding", "gzip");
httpsURLConnectionToGoogleDrive.setRequestProperty("User-Agent", "my program (gzip)");

但我无法让它工作。我被困在这里了。怎么办?

驱动器API已经将请求管理为默认的gzip,因此您不需要额外的努力。只有当您要创建自己的库时,才应该为gzip指定头。

驱动器API已经将请求管理为默认的gzip,因此您不需要额外的努力。只有当您要创建自己的库时,才应该为gzip指定头。

我使用的是Drive-restapi。所以我们需要自己处理这个问题,我想我使用的是Drive rest API。所以我想我们需要自己处理这件事