+ boolean downloadFile(String filepath, File targetPath) {
+ HttpGet get = new HttpGet(mUri.toString() + filepath.replace(" ", "%20"));
+ get.setHeader("Host", mUri.getHost());
+ get.setHeader("User-Agent", "Android-ownCloud");
+
+ try {
+ HttpResponse response = mHttpClient.execute(mTargetHost, get, mHttpContext);
+ if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {
+ return false;
+ }
+ BufferedInputStream bis = new BufferedInputStream(response.getEntity().getContent());
+ FileOutputStream fos = new FileOutputStream(targetPath);
+
+ byte[] bytes = new byte[512];
+ int readResult;
+ while ((readResult = bis.read(bytes)) != -1) fos.write(bytes, 0, readResult);
+
+ } catch (IOException e) {
+ e.printStackTrace();
+ return false;
+ }