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,15 @@ 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 ();
112+ // getMethod.abort();
116113 throw new OperationCancelledException ();
117114 }
118115 }
@@ -128,21 +125,21 @@ private int downloadFile(OwnCloudClient client, File targetFile) throws IOExcept
128125 }
129126 // Check if the file is completed
130127 // if transfer-encoding: chunked we cannot check if the file is complete
131- Header transferEncodingHeader = getMethod .getResponseHeader ("Transfer-Encoding" );
128+ String transferEncodingHeader = getMethod .getResponseHeader ("Transfer-Encoding" );
132129 boolean transferEncoding = false ;
133130
134131 if (transferEncodingHeader != null ) {
135- transferEncoding = "chunked" .equals (transferEncodingHeader . getValue () );
132+ transferEncoding = "chunked" .equals (transferEncodingHeader );
136133 }
137134
138135 if (transferred == totalToTransfer || transferEncoding ) {
139136 savedFile = true ;
140- Header modificationTime = getMethod .getResponseHeader ("Last-Modified" );
137+ String modificationTime = getMethod .getResponseHeader ("Last-Modified" );
141138 if (modificationTime == null ) {
142139 modificationTime = getMethod .getResponseHeader ("last-modified" );
143140 }
144141 if (modificationTime != null ) {
145- Date d = WebdavUtils .parseResponseDate (modificationTime . getValue () );
142+ Date d = WebdavUtils .parseResponseDate (modificationTime );
146143 modificationTimestamp = (d != null ) ? d .getTime () : 0 ;
147144 } else {
148145 Log_OC .e (TAG , "Could not read modification time from response downloading " + remotePath );
@@ -153,15 +150,8 @@ private int downloadFile(OwnCloudClient client, File targetFile) throws IOExcept
153150 Log_OC .e (TAG , "Could not read eTag from response downloading " + remotePath );
154151 }
155152
156- } else {
157- client .exhaustResponse (getMethod .getResponseBodyAsStream ());
158- // TODO some kind of error control!
159153 }
160-
161- } else {
162- client .exhaustResponse (getMethod .getResponseBodyAsStream ());
163154 }
164-
165155 } finally {
166156 if (fos != null ) fos .close ();
167157 if (!savedFile && targetFile .exists ()) {
0 commit comments