Fixed local path NULL when making favourite a file not down ; fixed change of local...
[pub/Android/ownCloud.git] / src / eu / alefzero / webdav / WebdavClient.java
index ccb08ca..61f1660 100644 (file)
@@ -98,15 +98,15 @@ public class WebdavClient extends HttpClient {
                 int readResult;\r
                 while ((readResult = bis.read(bytes)) != -1) {\r
                     if (mDataTransferListener != null)\r
-                        mDataTransferListener.transferProgress(readResult);\r
+                        mDataTransferListener.onTransferProgress(readResult);\r
                     fos.write(bytes, 0, readResult);\r
                 }\r
+                fos.close();\r
                 ret = true;\r
             } else {\r
                 exhaustResponse(get.getResponseBodyAsStream());\r
             }\r
             Log.e(TAG, "Download of " + remoteFilePath + " to " + targetFile + " finished with HTTP status " + status + (!ret?"(FAIL)":""));\r
-            \r
         } catch (Exception e) {\r
             logException(e, "dowloading " + remoteFilePath);\r
             \r
@@ -151,39 +151,32 @@ public class WebdavClient extends HttpClient {
     /**\r
      * Creates or update a file in the remote server with the contents of a local file.\r
      * \r
-     * \r
      * @param localFile         Path to the local file to upload.\r
      * @param remoteTarget      Remote path to the file to create or update, URL DECODED\r
      * @param contentType       MIME type of the file.\r
-     * @return                  'True' then the upload was successfully completed\r
+     * @return                  Status HTTP code returned by the server.\r
+     * @throws IOException      When a transport error that could not be recovered occurred while uploading the file to the server.\r
+     * @throws HttpException    When a violation of the HTTP protocol occurred. \r
      */\r
-    public boolean putFile(String localFile, String remoteTarget, String contentType) {\r
-        boolean result = false;\r
+    public int putFile(String localFile, String remoteTarget, String contentType) throws HttpException, IOException {\r
         int status = -1;\r
         PutMethod put = new PutMethod(mUri.toString() + WebdavUtils.encodePath(remoteTarget));\r
         \r
         try {\r
             File f = new File(localFile);\r
             FileRequestEntity entity = new FileRequestEntity(f, contentType);\r
-            entity.setOnDatatransferProgressListener(mDataTransferListener);\r
+            entity.addOnDatatransferProgressListener(mDataTransferListener);\r
             put.setRequestEntity(entity);\r
             status = executeMethod(put);\r
             \r
-            result = (status == HttpStatus.SC_OK || status == HttpStatus.SC_CREATED || status == HttpStatus.SC_NO_CONTENT);\r
-            \r
-            Log.d(TAG, "PUT to " + remoteTarget + " finished with HTTP status " + status + (!result?"(FAIL)":""));\r
-\r
             exhaustResponse(put.getResponseBodyAsStream());\r
             \r
-        } catch (Exception e) {\r
-            logException(e, "uploading " + localFile + " to " + remoteTarget);\r
-            \r
         } finally {\r
             put.releaseConnection();    // let the connection available for other methods\r
         }\r
-        return result;\r
+        return status;\r
     }\r
-\r
+    \r
     /**\r
      * Tries to log in to the current URI, with the current credentials\r
      * \r
@@ -239,9 +232,10 @@ public class WebdavClient extends HttpClient {
     /**\r
      * Check if a file exists in the OC server\r
      * \r
-     * @return      'Boolean.TRUE' if the file exists; 'Boolean.FALSE' it doesn't exist; NULL if couldn't be checked\r
+     * @return              'true' if the file exists; 'false' it doesn't exist\r
+     * @throws  Exception   When the existence could not be determined\r
      */\r
-    public Boolean existsFile(String path) {\r
+    public boolean existsFile(String path) throws IOException, HttpException {\r
         HeadMethod head = new HeadMethod(mUri.toString() + WebdavUtils.encodePath(path));\r
         try {\r
             int status = executeMethod(head);\r
@@ -249,10 +243,6 @@ public class WebdavClient extends HttpClient {
             exhaustResponse(head.getResponseBodyAsStream());\r
             return (status == HttpStatus.SC_OK);\r
             \r
-        } catch (Exception e) {\r
-            logException(e, "checking existence of " + path);\r
-            return null;\r
-            \r
         } finally {\r
             head.releaseConnection();    // let the connection available for other methods\r
         }\r
@@ -295,7 +285,7 @@ public class WebdavClient extends HttpClient {
      * \r
      * @param responseBodyAsStream      InputStream with the HTTP response to exhaust.\r
      */\r
-    private static void exhaustResponse(InputStream responseBodyAsStream) {\r
+    public void exhaustResponse(InputStream responseBodyAsStream) {\r
         if (responseBodyAsStream != null) {\r
             try {\r
                 while (responseBodyAsStream.read(sExhaustBuffer) >= 0);\r
@@ -342,5 +332,9 @@ public class WebdavClient extends HttpClient {
     public void setBaseUri(Uri uri) {\r
         mUri = uri;\r
     }\r
-    \r
+\r
+    public Uri getBaseUri() {\r
+        return mUri;\r
+    }\r
+\r
 }\r