Commit 9cdd246a by Yu-Hsuan Lin Committed by Oliver Woodman

support okhttp3

parent cc1f3e5c
...@@ -36,7 +36,7 @@ android { ...@@ -36,7 +36,7 @@ android {
dependencies { dependencies {
compile project(':library') compile project(':library')
compile('com.squareup.okhttp:okhttp:2.5.0') { compile('com.squareup.okhttp3:okhttp:+') {
exclude group: 'org.json' exclude group: 'org.json'
} }
} }
...@@ -22,14 +22,6 @@ import com.google.android.exoplayer.upstream.TransferListener; ...@@ -22,14 +22,6 @@ import com.google.android.exoplayer.upstream.TransferListener;
import com.google.android.exoplayer.util.Assertions; import com.google.android.exoplayer.util.Assertions;
import com.google.android.exoplayer.util.Predicate; import com.google.android.exoplayer.util.Predicate;
import com.squareup.okhttp.CacheControl;
import com.squareup.okhttp.HttpUrl;
import com.squareup.okhttp.OkHttpClient;
import com.squareup.okhttp.Request;
import com.squareup.okhttp.RequestBody;
import com.squareup.okhttp.Response;
import com.squareup.okhttp.internal.Util;
import java.io.EOFException; import java.io.EOFException;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
...@@ -39,6 +31,13 @@ import java.util.List; ...@@ -39,6 +31,13 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.atomic.AtomicReference;
import okhttp3.CacheControl;
import okhttp3.HttpUrl;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;
/** /**
* An {@link HttpDataSource} that delegates to Square's {@link OkHttpClient}. * An {@link HttpDataSource} that delegates to Square's {@link OkHttpClient}.
*/ */
...@@ -116,7 +115,7 @@ public class OkHttpDataSource implements HttpDataSource { ...@@ -116,7 +115,7 @@ public class OkHttpDataSource implements HttpDataSource {
@Override @Override
public String getUri() { public String getUri() {
return response == null ? null : response.request().urlString(); return response == null ? null : response.request().url().toString();
} }
@Override @Override
...@@ -184,15 +183,10 @@ public class OkHttpDataSource implements HttpDataSource { ...@@ -184,15 +183,10 @@ public class OkHttpDataSource implements HttpDataSource {
bytesToSkip = responseCode == 200 && dataSpec.position != 0 ? dataSpec.position : 0; bytesToSkip = responseCode == 200 && dataSpec.position != 0 ? dataSpec.position : 0;
// Determine the length of the data to be read, after skipping. // Determine the length of the data to be read, after skipping.
try { long contentLength = response.body().contentLength();
long contentLength = response.body().contentLength(); bytesToRead = dataSpec.length != C.LENGTH_UNBOUNDED ? dataSpec.length
bytesToRead = dataSpec.length != C.LENGTH_UNBOUNDED ? dataSpec.length : contentLength != -1 ? contentLength - bytesToSkip
: contentLength != -1 ? contentLength - bytesToSkip : C.LENGTH_UNBOUNDED;
: C.LENGTH_UNBOUNDED;
} catch (IOException e) {
closeConnectionQuietly();
throw new HttpDataSourceException(e, dataSpec);
}
opened = true; opened = true;
if (listener != null) { if (listener != null) {
...@@ -370,7 +364,7 @@ public class OkHttpDataSource implements HttpDataSource { ...@@ -370,7 +364,7 @@ public class OkHttpDataSource implements HttpDataSource {
* Closes the current connection quietly, if there is one. * Closes the current connection quietly, if there is one.
*/ */
private void closeConnectionQuietly() { private void closeConnectionQuietly() {
Util.closeQuietly(response.body()); response.body().close();
response = null; response = null;
responseByteStream = null; responseByteStream = null;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment