1919
2020import com .facebook .react .bridge .ReadableMapKeySetIterator ;
2121
22- public class Downloader extends AsyncTask <DownloadParams , int [], DownloadResult > {
22+ public class Downloader extends AsyncTask <DownloadParams , long [], DownloadResult > {
2323 private DownloadParams mParam ;
2424 private AtomicBoolean mAbort = new AtomicBoolean (false );
2525 DownloadResult res ;
@@ -64,7 +64,7 @@ private void download(DownloadParams param, DownloadResult res) throws Exception
6464 connection .connect ();
6565
6666 int statusCode = connection .getResponseCode ();
67- int lengthOfFile = connection .getContentLength ();
67+ long lengthOfFile = connection .getContentLengthLong ();
6868
6969 boolean isRedirect = (
7070 statusCode != HttpURLConnection .HTTP_OK &&
@@ -85,7 +85,7 @@ private void download(DownloadParams param, DownloadResult res) throws Exception
8585 connection .connect ();
8686
8787 statusCode = connection .getResponseCode ();
88- lengthOfFile = connection .getContentLength ();
88+ lengthOfFile = connection .getContentLengthLong ();
8989 }
9090 if (statusCode >= 200 && statusCode < 300 ) {
9191 Map <String , List <String >> headers = connection .getHeaderFields ();
@@ -107,7 +107,7 @@ private void download(DownloadParams param, DownloadResult res) throws Exception
107107 output = new FileOutputStream (param .dest );
108108
109109 byte data [] = new byte [8 * 1024 ];
110- int total = 0 ;
110+ long total = 0 ;
111111 int count ;
112112 double lastProgressValue = 0 ;
113113
@@ -116,14 +116,14 @@ private void download(DownloadParams param, DownloadResult res) throws Exception
116116
117117 total += count ;
118118 if (param .progressDivider <= 0 ) {
119- publishProgress (new int []{lengthOfFile , total });
119+ publishProgress (new long []{lengthOfFile , total });
120120 } else {
121121 double progress = Math .round (((double ) total * 100 ) / lengthOfFile );
122122 if (progress % param .progressDivider == 0 ) {
123123 if ((progress != lastProgressValue ) || (total == lengthOfFile )) {
124124 Log .d ("Downloader" , "EMIT: " + String .valueOf (progress ) + ", TOTAL:" + String .valueOf (total ));
125125 lastProgressValue = progress ;
126- publishProgress (new int []{lengthOfFile , total });
126+ publishProgress (new long []{lengthOfFile , total });
127127 }
128128 }
129129 }
@@ -146,7 +146,7 @@ protected void stop() {
146146 }
147147
148148 @ Override
149- protected void onProgressUpdate (int []... values ) {
149+ protected void onProgressUpdate (long []... values ) {
150150 super .onProgressUpdate (values );
151151 mParam .onDownloadProgress .onDownloadProgress (values [0 ][0 ], values [0 ][1 ]);
152152 }
0 commit comments