Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 763b71a1 authored by vince-bourgmayer's avatar vince-bourgmayer
Browse files

add a GzipedPropfind class and use it in LightReadFolderRemoteOperation

parent 98471051
Loading
Loading
Loading
Loading
+64 −0
Original line number Diff line number Diff line
package com.owncloud.android.lib.common.method;


import org.apache.jackrabbit.webdav.client.methods.PropFindMethod;
import org.apache.jackrabbit.webdav.property.DavPropertyNameSet;
import org.apache.jackrabbit.webdav.xml.DomUtil;
import org.w3c.dom.Document;
import org.xml.sax.SAXException;

import java.io.IOException;
import java.util.zip.GZIPInputStream;

import javax.xml.parsers.ParserConfigurationException;

public class GzipedPropfind extends PropFindMethod {
    public GzipedPropfind(String uri) throws IOException {
        super(uri);
    }

    @Override
    public Document getResponseBodyAsDocument() throws IOException {
        /*if ( super.responseDocument != null) {
            // response has already been read
            return super.responseDocument;
        }*/
        GZIPInputStream in = null;
        in = new GZIPInputStream(getResponseBodyAsStream());
        //InputStream in = getResponseBodyAsStream();
        if (in != null) {
            // read response and try to build a xml document
            try {
                return DomUtil.parseDocument(in);
            } catch (ParserConfigurationException e) {
                IOException exception =
                        new IOException("XML parser configuration error");
                exception.initCause(e);
                throw exception;
            } catch (SAXException e) {
                IOException exception = new IOException("XML parsing error");
                exception.initCause(e);
                throw exception;
            } finally {
                in.close();
            }
        }
        // no body or no parseable.
        return null;
    }


    public GzipedPropfind(String uri, DavPropertyNameSet propNameSet, int depth) throws IOException {
        super(uri, propNameSet, depth);
    }

    public GzipedPropfind(String uri, int propfindType, int depth) throws IOException {
        super(uri, propfindType, depth);
    }

    public GzipedPropfind(String uri, int propfindType, DavPropertyNameSet propNameSet, int depth) throws IOException {
        super(uri, propfindType, propNameSet, depth);
    }


}
+3 −2
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@ package com.owncloud.android.lib.resources.files;
import android.util.Log;

import com.owncloud.android.lib.common.OwnCloudClient;
import com.owncloud.android.lib.common.method.GzipedPropfind;
import com.owncloud.android.lib.common.network.WebdavEntry;
import com.owncloud.android.lib.common.network.WebdavUtils;
import com.owncloud.android.lib.common.operations.RemoteOperation;
@@ -94,7 +95,7 @@ public class LightReadFolderRemoteOperation extends RemoteOperation {

        try {
            // remote request
            query = new PropFindMethod(client.getWebdavUri() + WebdavUtils.encodePath(mRemotePath),
            query = new GzipedPropfind(client.getWebdavUri() + WebdavUtils.encodePath(mRemotePath),
                WebdavUtils.getMinimumPropSet(),    // PropFind Properties
                this.depth);
            query.setRequestHeader("Accept-Encoding", "deflate,gzip");
@@ -172,7 +173,7 @@ public class LightReadFolderRemoteOperation extends RemoteOperation {

        // loop to update every child
        RemoteFile remoteFile;
        for (int i = 1; i < remoteData.getResponses().length; ++i) {
        for (int i =0 ; ++i < remoteData.getResponses().length;) {
            /// new OCFile instance with the data from the server
            we = new WebdavEntry(remoteData.getResponses()[i], client.getWebdavUri().getPath());
            remoteFile = fillOCFile(we);