X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/blobdiff_plain/435b31ba4f3597cc7a43270cd4a54fb0180956c1..2b00ff1c7eb24dffcd70ced6c33db8ecf90e3f57:/src/eu/alefzero/webdav/WebdavClient.java diff --git a/src/eu/alefzero/webdav/WebdavClient.java b/src/eu/alefzero/webdav/WebdavClient.java index 6e1d287b..a8d22ce8 100644 --- a/src/eu/alefzero/webdav/WebdavClient.java +++ b/src/eu/alefzero/webdav/WebdavClient.java @@ -21,7 +21,6 @@ import java.io.BufferedInputStream; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; -import java.net.URLDecoder; import java.net.URLEncoder; import org.apache.commons.httpclient.Credentials; @@ -31,13 +30,13 @@ import org.apache.commons.httpclient.auth.AuthScope; import org.apache.commons.httpclient.methods.GetMethod; import org.apache.commons.httpclient.methods.HeadMethod; import org.apache.commons.httpclient.methods.PutMethod; -import org.apache.commons.httpclient.methods.RequestEntity; import org.apache.commons.httpclient.params.HttpMethodParams; import org.apache.commons.httpclient.protocol.Protocol; import org.apache.http.HttpStatus; import org.apache.jackrabbit.webdav.client.methods.MkColMethod; import eu.alefzero.owncloud.authenticator.EasySSLSocketFactory; +import eu.alefzero.owncloud.files.interfaces.OnDatatransferProgressListener; import android.net.Uri; import android.util.Log; @@ -47,6 +46,7 @@ public class WebdavClient extends HttpClient { private Credentials mCredentials; final private static String TAG = "WebdavClient"; private static final String USER_AGENT = "Android-ownCloud"; + private OnDatatransferProgressListener mDataTransferListener; public WebdavClient(Uri uri) { mUri = uri; @@ -65,7 +65,7 @@ public class WebdavClient extends HttpClient { return mCredentials; } - public void allowUnsignedCertificates() { + public void allowSelfsignedCertificates() { // https Protocol.registerProtocol("https", new Protocol("https", new EasySSLSocketFactory(), 443)); @@ -74,17 +74,23 @@ public class WebdavClient extends HttpClient { public boolean downloadFile(String filepath, File targetPath) { // HttpGet get = new HttpGet(mUri.toString() + filepath.replace(" ", // "%20")); + String[] splitted_filepath = filepath.split("/"); + filepath = ""; + for (String s : splitted_filepath) { + if (s.equals("")) continue; + filepath += "/" + URLEncoder.encode(s); + } - Log.e("ASD", mUri.toString() + URLDecoder.decode(filepath) + ""); + Log.e("ASD", mUri.toString() + filepath.replace(" ", "%20") + ""); GetMethod get = new GetMethod(mUri.toString() - + URLEncoder.encode(filepath)); + + filepath.replace(" ", "%20")); // get.setHeader("Host", mUri.getHost()); // get.setHeader("User-Agent", "Android-ownCloud"); try { - Log.e("ASD", get.toString()); int status = executeMethod(get); + Log.e(TAG, "status return: " + status); if (status != HttpStatus.SC_OK) { return false; } @@ -92,10 +98,13 @@ public class WebdavClient extends HttpClient { get.getResponseBodyAsStream()); FileOutputStream fos = new FileOutputStream(targetPath); - byte[] bytes = new byte[512]; + byte[] bytes = new byte[4096]; int readResult; - while ((readResult = bis.read(bytes)) != -1) + while ((readResult = bis.read(bytes)) != -1) { + if (mDataTransferListener != null) + mDataTransferListener.transferProgress(readResult); fos.write(bytes, 0, readResult); + } } catch (IOException e) { e.printStackTrace(); @@ -104,6 +113,10 @@ public class WebdavClient extends HttpClient { return true; } + public void setDataTransferProgressListener(OnDatatransferProgressListener listener) { + mDataTransferListener = listener; + } + public boolean putFile(String localFile, String remoteTarget, String contentType) { boolean result = true; @@ -111,7 +124,8 @@ public class WebdavClient extends HttpClient { try { Log.e("ASD", contentType + ""); File f = new File(localFile); - RequestEntity entity = new FileRequestEntity(f, contentType); + FileRequestEntity entity = new FileRequestEntity(f, contentType); + entity.setOnDatatransferProgressListener(mDataTransferListener); Log.e("ASD", f.exists() + " " + entity.getContentLength()); PutMethod put = new PutMethod(mUri.toString() + remoteTarget); put.setRequestEntity(entity);