66 */
77package com .owncloud .android .lib .resources .files ;
88
9- import com .owncloud .android .lib .common .OwnCloudClient ;
9+ import com .nextcloud .common .NextcloudClient ;
10+ import com .nextcloud .operations .GetMethod ;
1011import com .owncloud .android .lib .common .network .OnDatatransferProgressListener ;
1112import com .owncloud .android .lib .common .network .WebdavUtils ;
1213import com .owncloud .android .lib .common .operations .OperationCancelledException ;
1314import com .owncloud .android .lib .common .operations .RemoteOperation ;
1415import com .owncloud .android .lib .common .operations .RemoteOperationResult ;
1516import com .owncloud .android .lib .common .utils .Log_OC ;
1617
17- import org .apache .commons .httpclient .Header ;
1818import org .apache .commons .httpclient .HttpStatus ;
19- import org .apache .commons .httpclient .methods .GetMethod ;
2019
2120import java .io .BufferedInputStream ;
2221import java .io .File ;
@@ -58,7 +57,7 @@ public DownloadFileRemoteOperation(String remotePath, String temporalFolderPath)
5857 }
5958
6059 @ Override
61- protected RemoteOperationResult run (OwnCloudClient client ) {
60+ public RemoteOperationResult run (NextcloudClient client ) {
6261 RemoteOperationResult result ;
6362
6463 /// download will be performed to a temporal file, then moved to the final location
@@ -82,15 +81,15 @@ protected RemoteOperationResult run(OwnCloudClient client) {
8281 }
8382
8483
85- private int downloadFile (OwnCloudClient client , File targetFile ) throws IOException , OperationCancelledException , CreateLocalFileException {
84+ private int downloadFile (NextcloudClient client , File targetFile ) throws IOException , OperationCancelledException , CreateLocalFileException {
8685 int status ;
8786 boolean savedFile = false ;
88- getMethod = new GetMethod (client .getFilesDavUri (remotePath ));
87+ getMethod = new GetMethod (client .getFilesDavUri (remotePath ), false );
8988 Iterator <OnDatatransferProgressListener > it ;
9089
9190 FileOutputStream fos = null ;
9291 try {
93- status = client .executeMethod (getMethod );
92+ status = client .execute (getMethod );
9493 if (isSuccess (status )) {
9594 try {
9695 targetFile .createNewFile ();
@@ -102,17 +101,14 @@ private int downloadFile(OwnCloudClient client, File targetFile) throws IOExcept
102101 fos = new FileOutputStream (targetFile );
103102 long transferred = 0 ;
104103
105- Header contentLength = getMethod .getResponseHeader ("Content-Length" );
106- long totalToTransfer = (contentLength != null &&
107- contentLength .getValue ().length () > 0 ) ?
108- Long .parseLong (contentLength .getValue ()) : 0 ;
104+ String contentLength = getMethod .getResponseHeader ("Content-Length" );
105+ long totalToTransfer = (contentLength != null ) ? Long .parseLong (contentLength ) : 0 ;
109106
110107 byte [] bytes = new byte [4096 ];
111108 int readResult ;
112109 while ((readResult = bis .read (bytes )) != -1 ) {
113110 synchronized (mCancellationRequested ) {
114111 if (mCancellationRequested .get ()) {
115- getMethod .abort ();
116112 throw new OperationCancelledException ();
117113 }
118114 }
@@ -128,21 +124,21 @@ private int downloadFile(OwnCloudClient client, File targetFile) throws IOExcept
128124 }
129125 // Check if the file is completed
130126 // if transfer-encoding: chunked we cannot check if the file is complete
131- Header transferEncodingHeader = getMethod .getResponseHeader ("Transfer-Encoding" );
127+ String transferEncodingHeader = getMethod .getResponseHeader ("Transfer-Encoding" );
132128 boolean transferEncoding = false ;
133129
134130 if (transferEncodingHeader != null ) {
135- transferEncoding = "chunked" .equals (transferEncodingHeader . getValue () );
131+ transferEncoding = "chunked" .equals (transferEncodingHeader );
136132 }
137133
138134 if (transferred == totalToTransfer || transferEncoding ) {
139135 savedFile = true ;
140- Header modificationTime = getMethod .getResponseHeader ("Last-Modified" );
136+ String modificationTime = getMethod .getResponseHeader ("Last-Modified" );
141137 if (modificationTime == null ) {
142138 modificationTime = getMethod .getResponseHeader ("last-modified" );
143139 }
144140 if (modificationTime != null ) {
145- Date d = WebdavUtils .parseResponseDate (modificationTime . getValue () );
141+ Date d = WebdavUtils .parseResponseDate (modificationTime );
146142 modificationTimestamp = (d != null ) ? d .getTime () : 0 ;
147143 } else {
148144 Log_OC .e (TAG , "Could not read modification time from response downloading " + remotePath );
@@ -153,15 +149,8 @@ private int downloadFile(OwnCloudClient client, File targetFile) throws IOExcept
153149 Log_OC .e (TAG , "Could not read eTag from response downloading " + remotePath );
154150 }
155151
156- } else {
157- client .exhaustResponse (getMethod .getResponseBodyAsStream ());
158- // TODO some kind of error control!
159152 }
160-
161- } else {
162- client .exhaustResponse (getMethod .getResponseBodyAsStream ());
163153 }
164-
165154 } finally {
166155 if (fos != null ) fos .close ();
167156 if (!savedFile && targetFile .exists ()) {
0 commit comments