X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/blobdiff_plain/700c9427cdc20a4ef434d8060ab318b7e2655a4f..1e63d71c91c8c4ecf048adc719c7158630d5d063:/src/eu/alefzero/webdav/WebdavClient.java diff --git a/src/eu/alefzero/webdav/WebdavClient.java b/src/eu/alefzero/webdav/WebdavClient.java index f7cc060e..0a231c08 100644 --- a/src/eu/alefzero/webdav/WebdavClient.java +++ b/src/eu/alefzero/webdav/WebdavClient.java @@ -21,8 +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; import org.apache.commons.httpclient.HttpClient; @@ -31,13 +29,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,7 +45,7 @@ public class WebdavClient extends HttpClient { private Credentials mCredentials; final private static String TAG = "WebdavClient"; private static final String USER_AGENT = "Android-ownCloud"; - private OnUploadProgressListener mUploadProgressListener; + private OnDatatransferProgressListener mDataTransferListener; public WebdavClient(Uri uri) { mUri = uri; @@ -66,25 +64,28 @@ public class WebdavClient extends HttpClient { return mCredentials; } - public void allowUnsignedCertificates() { + public void allowSelfsignedCertificates() { // https Protocol.registerProtocol("https", new Protocol("https", new EasySSLSocketFactory(), 443)); } - public boolean downloadFile(String filepath, File targetPath) { + public boolean downloadFile(String remoteFilepath, File targetPath) { // HttpGet get = new HttpGet(mUri.toString() + filepath.replace(" ", // "%20")); - String[] splitted_filepath = filepath.split("/"); - filepath = ""; + /* dvelasco - this is not necessary anymore; OCFile.mRemotePath (the origin of remoteFielPath) keeps valid URL strings + String[] splitted_filepath = remoteFilepath.split("/"); + remoteFilepath = ""; for (String s : splitted_filepath) { if (s.equals("")) continue; - filepath += "/" + URLEncoder.encode(s); + remoteFilepath += "/" + URLEncoder.encode(s); } - Log.e("ASD", mUri.toString() + filepath.replace(" ", "%20") + ""); + Log.e("ASD", mUri.toString() + remoteFilepath.replace(" ", "%20") + ""); GetMethod get = new GetMethod(mUri.toString() - + filepath.replace(" ", "%20")); + + remoteFilepath.replace(" ", "%20")); + */ + GetMethod get = new GetMethod(mUri.toString() + remoteFilepath); // get.setHeader("Host", mUri.getHost()); // get.setHeader("User-Agent", "Android-ownCloud"); @@ -99,10 +100,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(); @@ -111,8 +115,8 @@ public class WebdavClient extends HttpClient { return true; } - public void setUploadListener(OnUploadProgressListener listener) { - mUploadProgressListener = listener; + public void setDataTransferProgressListener(OnDatatransferProgressListener listener) { + mDataTransferListener = listener; } public boolean putFile(String localFile, String remoteTarget, @@ -123,7 +127,7 @@ public class WebdavClient extends HttpClient { Log.e("ASD", contentType + ""); File f = new File(localFile); FileRequestEntity entity = new FileRequestEntity(f, contentType); - entity.setOnUploadProgressListener(mUploadProgressListener); + entity.setOnDatatransferProgressListener(mDataTransferListener); Log.e("ASD", f.exists() + " " + entity.getContentLength()); PutMethod put = new PutMethod(mUri.toString() + remoteTarget); put.setRequestEntity(entity); @@ -153,8 +157,7 @@ public class WebdavClient extends HttpClient { public boolean createDirectory(String path) { try { - MkColMethod mkcol = new MkColMethod(mUri.toString() + "/" + path - + "/"); + MkColMethod mkcol = new MkColMethod(mUri.toString() + path); int status = executeMethod(mkcol); Log.d(TAG, "Status returned " + status); Log.d(TAG, "uri: " + mkcol.getURI().toString());