import java.io.File;\r
import java.io.FileOutputStream;\r
import java.io.IOException;\r
-import java.net.URLDecoder;\r
import java.net.URLEncoder;\r
\r
import org.apache.commons.httpclient.Credentials;\r
import org.apache.commons.httpclient.methods.GetMethod;\r
import org.apache.commons.httpclient.methods.HeadMethod;\r
import org.apache.commons.httpclient.methods.PutMethod;\r
-import org.apache.commons.httpclient.methods.RequestEntity;\r
import org.apache.commons.httpclient.params.HttpMethodParams;\r
import org.apache.commons.httpclient.protocol.Protocol;\r
import org.apache.http.HttpStatus;\r
import org.apache.jackrabbit.webdav.client.methods.MkColMethod;\r
\r
import eu.alefzero.owncloud.authenticator.EasySSLSocketFactory;\r
+import eu.alefzero.owncloud.files.interfaces.OnDatatransferProgressListener;\r
\r
import android.net.Uri;\r
import android.util.Log;\r
private Credentials mCredentials;\r
final private static String TAG = "WebdavClient";\r
private static final String USER_AGENT = "Android-ownCloud";\r
+ private OnDatatransferProgressListener mDataTransferListener;\r
\r
public WebdavClient(Uri uri) {\r
mUri = uri;\r
return mCredentials;\r
}\r
\r
- public void allowUnsignedCertificates() {\r
+ public void allowSelfsignedCertificates() {\r
// https\r
Protocol.registerProtocol("https", new Protocol("https",\r
new EasySSLSocketFactory(), 443));\r
public boolean downloadFile(String filepath, File targetPath) {\r
// HttpGet get = new HttpGet(mUri.toString() + filepath.replace(" ",\r
// "%20"));\r
+ String[] splitted_filepath = filepath.split("/");\r
+ filepath = "";\r
+ for (String s : splitted_filepath) {\r
+ if (s.equals("")) continue;\r
+ filepath += "/" + URLEncoder.encode(s);\r
+ }\r
\r
- Log.e("ASD", mUri.toString() + URLDecoder.decode(filepath) + "");\r
+ Log.e("ASD", mUri.toString() + filepath.replace(" ", "%20") + "");\r
GetMethod get = new GetMethod(mUri.toString()\r
- + URLEncoder.encode(filepath));\r
+ + filepath.replace(" ", "%20"));\r
\r
// get.setHeader("Host", mUri.getHost());\r
// get.setHeader("User-Agent", "Android-ownCloud");\r
\r
try {\r
- Log.e("ASD", get.toString());\r
int status = executeMethod(get);\r
+ Log.e(TAG, "status return: " + status);\r
if (status != HttpStatus.SC_OK) {\r
return false;\r
}\r
get.getResponseBodyAsStream());\r
FileOutputStream fos = new FileOutputStream(targetPath);\r
\r
- byte[] bytes = new byte[512];\r
+ byte[] bytes = new byte[4096];\r
int readResult;\r
- while ((readResult = bis.read(bytes)) != -1)\r
+ while ((readResult = bis.read(bytes)) != -1) {\r
+ if (mDataTransferListener != null)\r
+ mDataTransferListener.transferProgress(readResult);\r
fos.write(bytes, 0, readResult);\r
+ }\r
\r
} catch (IOException e) {\r
e.printStackTrace();\r
return true;\r
}\r
\r
+ public void setDataTransferProgressListener(OnDatatransferProgressListener listener) {\r
+ mDataTransferListener = listener;\r
+ }\r
+ \r
public boolean putFile(String localFile, String remoteTarget,\r
String contentType) {\r
boolean result = true;\r
try {\r
Log.e("ASD", contentType + "");\r
File f = new File(localFile);\r
- RequestEntity entity = new FileRequestEntity(f, contentType);\r
+ FileRequestEntity entity = new FileRequestEntity(f, contentType);\r
+ entity.setOnDatatransferProgressListener(mDataTransferListener);\r
Log.e("ASD", f.exists() + " " + entity.getContentLength());\r
PutMethod put = new PutMethod(mUri.toString() + remoteTarget);\r
put.setRequestEntity(entity);\r