Skip to content

Commit 5edc6e7

Browse files
committed
format
1 parent 184082c commit 5edc6e7

File tree

3 files changed

+17
-20
lines changed

3 files changed

+17
-20
lines changed

library/src/main/java/com/qiniu/android/http/Client.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,8 @@
1919
import java.util.List;
2020
import java.util.concurrent.TimeUnit;
2121

22-
import okhttp3.Authenticator;
2322
import okhttp3.Call;
2423
import okhttp3.Callback;
25-
import okhttp3.Credentials;
2624
import okhttp3.Dns;
2725
import okhttp3.HttpUrl;
2826
import okhttp3.Interceptor;
@@ -31,8 +29,6 @@
3129
import okhttp3.OkHttpClient;
3230
import okhttp3.Request;
3331
import okhttp3.RequestBody;
34-
import okhttp3.Response;
35-
import okhttp3.Route;
3632

3733
/**
3834
* Created by bailong on 15/11/12.
@@ -55,7 +51,7 @@ public Client(ProxyConfiguration proxy, int connectTimeout, int responseTimeout,
5551

5652
if (proxy != null) {
5753
builder.proxy(proxy.proxy());
58-
if (proxy.user != null && proxy.password != null){
54+
if (proxy.user != null && proxy.password != null) {
5955
builder.proxyAuthenticator(proxy.authenticator());
6056
}
6157
}

library/src/main/java/com/qiniu/android/http/ProxyConfiguration.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,12 @@ public ProxyConfiguration(String hostAddress, int port, String user, String pass
3636
public ProxyConfiguration(String hostAddress, int port) {
3737
this(hostAddress, port, null, null, Proxy.Type.HTTP);
3838
}
39-
Proxy proxy(){
39+
40+
Proxy proxy() {
4041
return new Proxy(type, new InetSocketAddress(hostAddress, port));
4142
}
4243

43-
Authenticator authenticator(){
44+
Authenticator authenticator() {
4445
return new Authenticator() {
4546
@Override
4647
public okhttp3.Request authenticate(Route route, okhttp3.Response response) throws IOException {

library/src/main/java/com/qiniu/android/storage/ResumeUploader.java

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -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,12 +195,12 @@ 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 long calcPutSize(int offset) {
198+
private long calcPutSize(long offset) {
199199
long left = size - offset;
200200
return left < config.chunkSize ? left : config.chunkSize;
201201
}
202202

203-
private long calcBlockSize(int offset) {
203+
private long calcBlockSize(long offset) {
204204
long left = size - offset;
205205
return left < Configuration.BLOCK_SIZE ? left : Configuration.BLOCK_SIZE;
206206
}
@@ -209,7 +209,7 @@ 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 = (int)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,24 +279,24 @@ 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 = (int)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

@@ -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

Comments
 (0)