3737 */
3838final class ResumeUploader implements Runnable {
3939
40- private final int size ;
40+ private final long size ;
4141 private final String key ;
4242 private final UpCompletionHandler completionHandler ;
4343 private final UploadOptions options ;
@@ -60,7 +60,7 @@ final class ResumeUploader implements Runnable {
6060 this .config = config ;
6161 this .f = f ;
6262 this .recorderKey = recorderKey ;
63- this .size = ( int ) f .length ();
63+ this .size = f .length ();
6464 this .key = key ;
6565 this .headers = new StringMap ().put ("Authorization" , "UpToken " + token .token );
6666 this .file = null ;
@@ -105,7 +105,7 @@ private static boolean isNotChunkToQiniu(ResponseInfo info, JSONObject response)
105105 }
106106
107107 public void run () {
108- int offset = recoveryFromRecord ();
108+ long offset = recoveryFromRecord ();
109109 try {
110110 file = new RandomAccessFile (f , "r" );
111111 } catch (FileNotFoundException e ) {
@@ -126,7 +126,7 @@ public void run() {
126126 * @param progress 上传进度
127127 * @param _completionHandler 上传完成处理动作
128128 */
129- private void makeBlock (URI address , int offset , int blockSize , int chunkSize , ProgressHandler progress ,
129+ private void makeBlock (URI address , long offset , int blockSize , int chunkSize , ProgressHandler progress ,
130130 CompletionHandler _completionHandler , UpCancellationSignal c ) {
131131 String path = format (Locale .ENGLISH , "/mkblk/%d" , blockSize );
132132 try {
@@ -141,9 +141,9 @@ private void makeBlock(URI address, int offset, int blockSize, int chunkSize, Pr
141141 post (u , chunkBuffer , 0 , chunkSize , progress , _completionHandler , c );
142142 }
143143
144- private void putChunk (URI address , int offset , int chunkSize , String context , ProgressHandler progress ,
144+ private void putChunk (URI address , long offset , int chunkSize , String context , ProgressHandler progress ,
145145 CompletionHandler _completionHandler , UpCancellationSignal c ) {
146- int chunkOffset = offset % Configuration .BLOCK_SIZE ;
146+ int chunkOffset = ( int ) ( offset % Configuration .BLOCK_SIZE ) ;
147147 String path = format (Locale .ENGLISH , "/bput/%s/%d" , context , chunkOffset );
148148 try {
149149 file .seek (offset );
@@ -195,21 +195,21 @@ private void post(URI uri, byte[] data, int offset, int size, ProgressHandler pr
195195 client .asyncPost (uri .toString (), data , offset , size , headers , progress , completion , c );
196196 }
197197
198- private int calcPutSize (int offset ) {
199- int left = size - offset ;
198+ private long calcPutSize (long offset ) {
199+ long left = size - offset ;
200200 return left < config .chunkSize ? left : config .chunkSize ;
201201 }
202202
203- private int calcBlockSize (int offset ) {
204- int left = size - offset ;
203+ private long calcBlockSize (long offset ) {
204+ long left = size - offset ;
205205 return left < Configuration .BLOCK_SIZE ? left : Configuration .BLOCK_SIZE ;
206206 }
207207
208208 private boolean isCancelled () {
209209 return options .cancellationSignal .isCancelled ();
210210 }
211211
212- private void nextTask (final int offset , final int retried , final URI address ) {
212+ private void nextTask (final long offset , final int retried , final URI address ) {
213213 if (isCancelled ()) {
214214 ResponseInfo i = ResponseInfo .cancelled ();
215215 completionHandler .complete (key , i , null );
@@ -239,7 +239,7 @@ public void complete(ResponseInfo info, JSONObject response) {
239239 return ;
240240 }
241241
242- final int chunkSize = calcPutSize (offset );
242+ final int chunkSize = ( int ) calcPutSize (offset );
243243 ProgressHandler progress = new ProgressHandler () {
244244 @ Override
245245 public void onProgress (int bytesWritten , int totalSize ) {
@@ -279,28 +279,28 @@ public void complete(ResponseInfo info, JSONObject response) {
279279 try {
280280 context = response .getString ("ctx" );
281281 crc = response .getLong ("crc32" );
282- } catch (JSONException e ) {
282+ } catch (Exception e ) {
283283 e .printStackTrace ();
284284 }
285285 if ((context == null || crc != ResumeUploader .this .crc32 ) && retried < config .retryMax ) {
286286 nextTask (offset , retried + 1 , config .upBackup .address );
287287 return ;
288288 }
289- contexts [offset / Configuration .BLOCK_SIZE ] = context ;
289+ contexts [( int ) ( offset / Configuration .BLOCK_SIZE ) ] = context ;
290290 record (offset + chunkSize );
291291 nextTask (offset + chunkSize , retried , address );
292292 }
293293 };
294294 if (offset % Configuration .BLOCK_SIZE == 0 ) {
295- int blockSize = calcBlockSize (offset );
295+ int blockSize = ( int ) calcBlockSize (offset );
296296 makeBlock (address , offset , blockSize , chunkSize , progress , complete , options .cancellationSignal );
297297 return ;
298298 }
299- String context = contexts [offset / Configuration .BLOCK_SIZE ];
299+ String context = contexts [( int ) ( offset / Configuration .BLOCK_SIZE ) ];
300300 putChunk (address , offset , chunkSize , context , progress , complete , options .cancellationSignal );
301301 }
302302
303- private int recoveryFromRecord () {
303+ private long recoveryFromRecord () {
304304 if (config .recorder == null ) {
305305 return 0 ;
306306 }
@@ -316,9 +316,9 @@ private int recoveryFromRecord() {
316316 e .printStackTrace ();
317317 return 0 ;
318318 }
319- int offset = obj .optInt ("offset" , 0 );
319+ long offset = obj .optLong ("offset" , 0 );
320320 long modify = obj .optLong ("modify_time" , 0 );
321- int fSize = obj .optInt ("size" , 0 );
321+ long fSize = obj .optLong ("size" , 0 );
322322 JSONArray array = obj .optJSONArray ("contexts" );
323323 if (offset == 0 || modify != modifyTime || fSize != size || array == null || array .length () == 0 ) {
324324 return 0 ;
@@ -343,7 +343,7 @@ private void removeRecord() {
343343 // "modify_time": lastFileModifyTime,
344344 // "contexts": contexts
345345 //}
346- private void record (int offset ) {
346+ private void record (long offset ) {
347347 if (config .recorder == null || offset == 0 ) {
348348 return ;
349349 }
0 commit comments