use of org.whispersystems.signalservice.api.push.exceptions.ResumeLocationInvalidException in project Signal-Android by WhisperSystems.
the class PushServiceSocket method getResumeInfo.
private ResumeInfo getResumeInfo(String resumableUrl, long contentLength) throws IOException {
ConnectionHolder connectionHolder = getRandom(cdnClientsMap.get(2), random);
OkHttpClient okHttpClient = connectionHolder.getClient().newBuilder().connectTimeout(soTimeoutMillis, TimeUnit.MILLISECONDS).readTimeout(soTimeoutMillis, TimeUnit.MILLISECONDS).build();
final long offset;
final String contentRange;
Request.Builder request = new Request.Builder().url(buildConfiguredUrl(connectionHolder, resumableUrl)).put(RequestBody.create(null, "")).addHeader("Content-Range", String.format(Locale.US, "bytes */%d", contentLength));
if (connectionHolder.getHostHeader().isPresent()) {
request.header("host", connectionHolder.getHostHeader().get());
}
Call call = okHttpClient.newCall(request.build());
synchronized (connections) {
connections.add(call);
}
try {
Response response;
try {
response = call.execute();
} catch (IOException e) {
throw new PushNetworkException(e);
}
if (response.isSuccessful()) {
offset = contentLength;
contentRange = null;
} else if (response.code() == 308) {
String rangeCompleted = response.header("Range");
if (rangeCompleted == null) {
offset = 0;
} else {
offset = Long.parseLong(rangeCompleted.split("-")[1]) + 1;
}
contentRange = String.format(Locale.US, "bytes %d-%d/%d", offset, contentLength - 1, contentLength);
} else if (response.code() == 404) {
throw new ResumeLocationInvalidException();
} else {
throw new NonSuccessfulResumableUploadResponseCodeException(response.code(), "Response: " + response);
}
} finally {
synchronized (connections) {
connections.remove(call);
}
}
return new ResumeInfo(contentRange, offset);
}
use of org.whispersystems.signalservice.api.push.exceptions.ResumeLocationInvalidException in project Signal-Android by signalapp.
the class PushServiceSocket method getResumeInfo.
private ResumeInfo getResumeInfo(String resumableUrl, long contentLength) throws IOException {
ConnectionHolder connectionHolder = getRandom(cdnClientsMap.get(2), random);
OkHttpClient okHttpClient = connectionHolder.getClient().newBuilder().connectTimeout(soTimeoutMillis, TimeUnit.MILLISECONDS).readTimeout(soTimeoutMillis, TimeUnit.MILLISECONDS).build();
final long offset;
final String contentRange;
Request.Builder request = new Request.Builder().url(buildConfiguredUrl(connectionHolder, resumableUrl)).put(RequestBody.create(null, "")).addHeader("Content-Range", String.format(Locale.US, "bytes */%d", contentLength));
if (connectionHolder.getHostHeader().isPresent()) {
request.header("host", connectionHolder.getHostHeader().get());
}
Call call = okHttpClient.newCall(request.build());
synchronized (connections) {
connections.add(call);
}
try {
Response response;
try {
response = call.execute();
} catch (IOException e) {
throw new PushNetworkException(e);
}
if (response.isSuccessful()) {
offset = contentLength;
contentRange = null;
} else if (response.code() == 308) {
String rangeCompleted = response.header("Range");
if (rangeCompleted == null) {
offset = 0;
} else {
offset = Long.parseLong(rangeCompleted.split("-")[1]) + 1;
}
contentRange = String.format(Locale.US, "bytes %d-%d/%d", offset, contentLength - 1, contentLength);
} else if (response.code() == 404) {
throw new ResumeLocationInvalidException();
} else {
throw new NonSuccessfulResumableUploadResponseCodeException(response.code(), "Response: " + response);
}
} finally {
synchronized (connections) {
connections.remove(call);
}
}
return new ResumeInfo(contentRange, offset);
}
Aggregations