37
37
*/
38
38
final class ResumeUploader implements Runnable {
39
39
40
- private final int size ;
40
+ private final long size ;
41
41
private final String key ;
42
42
private final UpCompletionHandler completionHandler ;
43
43
private final UploadOptions options ;
@@ -60,7 +60,7 @@ final class ResumeUploader implements Runnable {
60
60
this .config = config ;
61
61
this .f = f ;
62
62
this .recorderKey = recorderKey ;
63
- this .size = ( int ) f .length ();
63
+ this .size = f .length ();
64
64
this .key = key ;
65
65
this .headers = new StringMap ().put ("Authorization" , "UpToken " + token .token );
66
66
this .file = null ;
@@ -105,7 +105,7 @@ private static boolean isNotChunkToQiniu(ResponseInfo info, JSONObject response)
105
105
}
106
106
107
107
public void run () {
108
- int offset = recoveryFromRecord ();
108
+ long offset = recoveryFromRecord ();
109
109
try {
110
110
file = new RandomAccessFile (f , "r" );
111
111
} catch (FileNotFoundException e ) {
@@ -126,7 +126,7 @@ public void run() {
126
126
* @param progress 上传进度
127
127
* @param _completionHandler 上传完成处理动作
128
128
*/
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 ,
130
130
CompletionHandler _completionHandler , UpCancellationSignal c ) {
131
131
String path = format (Locale .ENGLISH , "/mkblk/%d" , blockSize );
132
132
try {
@@ -141,9 +141,9 @@ private void makeBlock(URI address, int offset, int blockSize, int chunkSize, Pr
141
141
post (u , chunkBuffer , 0 , chunkSize , progress , _completionHandler , c );
142
142
}
143
143
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 ,
145
145
CompletionHandler _completionHandler , UpCancellationSignal c ) {
146
- int chunkOffset = offset % Configuration .BLOCK_SIZE ;
146
+ int chunkOffset = ( int ) ( offset % Configuration .BLOCK_SIZE ) ;
147
147
String path = format (Locale .ENGLISH , "/bput/%s/%d" , context , chunkOffset );
148
148
try {
149
149
file .seek (offset );
@@ -195,21 +195,21 @@ private void post(URI uri, byte[] data, int offset, int size, ProgressHandler pr
195
195
client .asyncPost (uri .toString (), data , offset , size , headers , progress , completion , c );
196
196
}
197
197
198
- private int calcPutSize (int offset ) {
199
- int left = size - offset ;
198
+ private long calcPutSize (long offset ) {
199
+ long left = size - offset ;
200
200
return left < config .chunkSize ? left : config .chunkSize ;
201
201
}
202
202
203
- private int calcBlockSize (int offset ) {
204
- int left = size - offset ;
203
+ private long calcBlockSize (long offset ) {
204
+ long left = size - offset ;
205
205
return left < Configuration .BLOCK_SIZE ? left : Configuration .BLOCK_SIZE ;
206
206
}
207
207
208
208
private boolean isCancelled () {
209
209
return options .cancellationSignal .isCancelled ();
210
210
}
211
211
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 ) {
213
213
if (isCancelled ()) {
214
214
ResponseInfo i = ResponseInfo .cancelled ();
215
215
completionHandler .complete (key , i , null );
@@ -239,7 +239,7 @@ public void complete(ResponseInfo info, JSONObject response) {
239
239
return ;
240
240
}
241
241
242
- final int chunkSize = calcPutSize (offset );
242
+ final int chunkSize = ( int ) calcPutSize (offset );
243
243
ProgressHandler progress = new ProgressHandler () {
244
244
@ Override
245
245
public void onProgress (int bytesWritten , int totalSize ) {
@@ -279,28 +279,28 @@ public void complete(ResponseInfo info, JSONObject response) {
279
279
try {
280
280
context = response .getString ("ctx" );
281
281
crc = response .getLong ("crc32" );
282
- } catch (JSONException e ) {
282
+ } catch (Exception e ) {
283
283
e .printStackTrace ();
284
284
}
285
285
if ((context == null || crc != ResumeUploader .this .crc32 ) && retried < config .retryMax ) {
286
286
nextTask (offset , retried + 1 , config .upBackup .address );
287
287
return ;
288
288
}
289
- contexts [offset / Configuration .BLOCK_SIZE ] = context ;
289
+ contexts [( int ) ( offset / Configuration .BLOCK_SIZE ) ] = context ;
290
290
record (offset + chunkSize );
291
291
nextTask (offset + chunkSize , retried , address );
292
292
}
293
293
};
294
294
if (offset % Configuration .BLOCK_SIZE == 0 ) {
295
- int blockSize = calcBlockSize (offset );
295
+ int blockSize = ( int ) calcBlockSize (offset );
296
296
makeBlock (address , offset , blockSize , chunkSize , progress , complete , options .cancellationSignal );
297
297
return ;
298
298
}
299
- String context = contexts [offset / Configuration .BLOCK_SIZE ];
299
+ String context = contexts [( int ) ( offset / Configuration .BLOCK_SIZE ) ];
300
300
putChunk (address , offset , chunkSize , context , progress , complete , options .cancellationSignal );
301
301
}
302
302
303
- private int recoveryFromRecord () {
303
+ private long recoveryFromRecord () {
304
304
if (config .recorder == null ) {
305
305
return 0 ;
306
306
}
@@ -316,9 +316,9 @@ private int recoveryFromRecord() {
316
316
e .printStackTrace ();
317
317
return 0 ;
318
318
}
319
- int offset = obj .optInt ("offset" , 0 );
319
+ long offset = obj .optLong ("offset" , 0 );
320
320
long modify = obj .optLong ("modify_time" , 0 );
321
- int fSize = obj .optInt ("size" , 0 );
321
+ long fSize = obj .optLong ("size" , 0 );
322
322
JSONArray array = obj .optJSONArray ("contexts" );
323
323
if (offset == 0 || modify != modifyTime || fSize != size || array == null || array .length () == 0 ) {
324
324
return 0 ;
@@ -343,7 +343,7 @@ private void removeRecord() {
343
343
// "modify_time": lastFileModifyTime,
344
344
// "contexts": contexts
345
345
//}
346
- private void record (int offset ) {
346
+ private void record (long offset ) {
347
347
if (config .recorder == null || offset == 0 ) {
348
348
return ;
349
349
}
0 commit comments