mDataTransferListener.transferProgress(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
/**\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
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
/**\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
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
* \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
public void setBaseUri(Uri uri) {\r
mUri = uri;\r
}\r
+\r
+ public Uri getBaseUri() {\r
+ return mUri;\r
+ }\r
\r
}\r