Commit bb684b52 by aquilescanta Committed by Oliver Woodman

Promote getResponseHeaders to DataSource

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=199607604
parent ccc41f1a
...@@ -32,6 +32,7 @@ import java.io.IOException; ...@@ -32,6 +32,7 @@ import java.io.IOException;
import java.net.SocketTimeoutException; import java.net.SocketTimeoutException;
import java.net.UnknownHostException; import java.net.UnknownHostException;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
...@@ -247,7 +248,7 @@ public class CronetDataSource extends UrlRequest.Callback implements HttpDataSou ...@@ -247,7 +248,7 @@ public class CronetDataSource extends UrlRequest.Callback implements HttpDataSou
@Override @Override
public Map<String, List<String>> getResponseHeaders() { public Map<String, List<String>> getResponseHeaders() {
return responseInfo == null ? null : responseInfo.getAllHeaders(); return responseInfo == null ? Collections.emptyMap() : responseInfo.getAllHeaders();
} }
@Override @Override
......
...@@ -30,6 +30,7 @@ import java.io.EOFException; ...@@ -30,6 +30,7 @@ import java.io.EOFException;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.InterruptedIOException; import java.io.InterruptedIOException;
import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.atomic.AtomicReference;
...@@ -131,7 +132,7 @@ public class OkHttpDataSource implements HttpDataSource { ...@@ -131,7 +132,7 @@ public class OkHttpDataSource implements HttpDataSource {
@Override @Override
public Map<String, List<String>> getResponseHeaders() { public Map<String, List<String>> getResponseHeaders() {
return response == null ? null : response.headers().toMultimap(); return response == null ? Collections.emptyMap() : response.headers().toMultimap();
} }
@Override @Override
......
...@@ -19,6 +19,9 @@ import android.net.Uri; ...@@ -19,6 +19,9 @@ import android.net.Uri;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import com.google.android.exoplayer2.C; import com.google.android.exoplayer2.C;
import java.io.IOException; import java.io.IOException;
import java.util.Collections;
import java.util.List;
import java.util.Map;
/** /**
* A component from which streams of data can be read. * A component from which streams of data can be read.
...@@ -83,6 +86,14 @@ public interface DataSource { ...@@ -83,6 +86,14 @@ public interface DataSource {
@Nullable Uri getUri(); @Nullable Uri getUri();
/** /**
* When the source is open, returns the response headers associated with the last {@link #open}
* call. Otherwise, returns an empty map.
*/
default Map<String, List<String>> getResponseHeaders() {
return Collections.emptyMap();
}
/**
* Closes the source. * Closes the source.
* <p> * <p>
* Note: This method must be called even if the corresponding call to {@link #open(DataSpec)} * Note: This method must be called even if the corresponding call to {@link #open(DataSpec)}
......
...@@ -21,6 +21,8 @@ import android.util.Log; ...@@ -21,6 +21,8 @@ import android.util.Log;
import com.google.android.exoplayer2.util.Assertions; import com.google.android.exoplayer2.util.Assertions;
import com.google.android.exoplayer2.util.Util; import com.google.android.exoplayer2.util.Util;
import java.io.IOException; import java.io.IOException;
import java.util.List;
import java.util.Map;
/** /**
* A {@link DataSource} that supports multiple URI schemes. The supported schemes are: * A {@link DataSource} that supports multiple URI schemes. The supported schemes are:
...@@ -158,6 +160,13 @@ public final class DefaultDataSource implements DataSource { ...@@ -158,6 +160,13 @@ public final class DefaultDataSource implements DataSource {
} }
@Override @Override
public Map<String, List<String>> getResponseHeaders() {
return dataSource == null
? DataSource.super.getResponseHeaders()
: dataSource.getResponseHeaders();
}
@Override
public void close() throws IOException { public void close() throws IOException {
if (dataSource != null) { if (dataSource != null) {
try { try {
......
...@@ -32,6 +32,7 @@ import java.net.HttpURLConnection; ...@@ -32,6 +32,7 @@ import java.net.HttpURLConnection;
import java.net.NoRouteToHostException; import java.net.NoRouteToHostException;
import java.net.ProtocolException; import java.net.ProtocolException;
import java.net.URL; import java.net.URL;
import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.atomic.AtomicReference;
...@@ -162,7 +163,7 @@ public class DefaultHttpDataSource implements HttpDataSource { ...@@ -162,7 +163,7 @@ public class DefaultHttpDataSource implements HttpDataSource {
@Override @Override
public Map<String, List<String>> getResponseHeaders() { public Map<String, List<String>> getResponseHeaders() {
return connection == null ? null : connection.getHeaderFields(); return connection == null ? Collections.emptyMap() : connection.getHeaderFields();
} }
@Override @Override
......
...@@ -341,10 +341,6 @@ public interface HttpDataSource extends DataSource { ...@@ -341,10 +341,6 @@ public interface HttpDataSource extends DataSource {
*/ */
void clearAllRequestProperties(); void clearAllRequestProperties();
/** @Override
* Returns the headers provided in the response, or {@code null} if response headers are
* unavailable.
*/
Map<String, List<String>> getResponseHeaders(); Map<String, List<String>> getResponseHeaders();
} }
...@@ -31,6 +31,8 @@ import java.io.IOException; ...@@ -31,6 +31,8 @@ import java.io.IOException;
import java.io.InterruptedIOException; import java.io.InterruptedIOException;
import java.lang.annotation.Retention; import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy; import java.lang.annotation.RetentionPolicy;
import java.util.List;
import java.util.Map;
/** /**
* A {@link DataSource} that reads and writes a {@link Cache}. Requests are fulfilled from the cache * A {@link DataSource} that reads and writes a {@link Cache}. Requests are fulfilled from the cache
...@@ -333,6 +335,14 @@ public final class CacheDataSource implements DataSource { ...@@ -333,6 +335,14 @@ public final class CacheDataSource implements DataSource {
} }
@Override @Override
public Map<String, List<String>> getResponseHeaders() {
// TODO: Implement.
return isReadingFromUpstream()
? upstreamDataSource.getResponseHeaders()
: DataSource.super.getResponseHeaders();
}
@Override
public void close() throws IOException { public void close() throws IOException {
uri = null; uri = null;
actualUri = null; actualUri = null;
......
...@@ -20,6 +20,8 @@ import com.google.android.exoplayer2.C; ...@@ -20,6 +20,8 @@ import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.upstream.DataSource; import com.google.android.exoplayer2.upstream.DataSource;
import com.google.android.exoplayer2.upstream.DataSpec; import com.google.android.exoplayer2.upstream.DataSpec;
import java.io.IOException; import java.io.IOException;
import java.util.List;
import java.util.Map;
import javax.crypto.Cipher; import javax.crypto.Cipher;
/** /**
...@@ -60,14 +62,18 @@ public final class AesCipherDataSource implements DataSource { ...@@ -60,14 +62,18 @@ public final class AesCipherDataSource implements DataSource {
} }
@Override @Override
public void close() throws IOException { public Uri getUri() {
cipher = null; return upstream.getUri();
upstream.close();
} }
@Override @Override
public Uri getUri() { public Map<String, List<String>> getResponseHeaders() {
return upstream.getUri(); return upstream.getResponseHeaders();
} }
@Override
public void close() throws IOException {
cipher = null;
upstream.close();
}
} }
...@@ -27,6 +27,8 @@ import java.security.InvalidKeyException; ...@@ -27,6 +27,8 @@ import java.security.InvalidKeyException;
import java.security.Key; import java.security.Key;
import java.security.NoSuchAlgorithmException; import java.security.NoSuchAlgorithmException;
import java.security.spec.AlgorithmParameterSpec; import java.security.spec.AlgorithmParameterSpec;
import java.util.List;
import java.util.Map;
import javax.crypto.Cipher; import javax.crypto.Cipher;
import javax.crypto.CipherInputStream; import javax.crypto.CipherInputStream;
import javax.crypto.NoSuchPaddingException; import javax.crypto.NoSuchPaddingException;
...@@ -86,14 +88,6 @@ import javax.crypto.spec.SecretKeySpec; ...@@ -86,14 +88,6 @@ import javax.crypto.spec.SecretKeySpec;
} }
@Override @Override
public void close() throws IOException {
if (cipherInputStream != null) {
cipherInputStream = null;
upstream.close();
}
}
@Override
public int read(byte[] buffer, int offset, int readLength) throws IOException { public int read(byte[] buffer, int offset, int readLength) throws IOException {
Assertions.checkState(cipherInputStream != null); Assertions.checkState(cipherInputStream != null);
int bytesRead = cipherInputStream.read(buffer, offset, readLength); int bytesRead = cipherInputStream.read(buffer, offset, readLength);
...@@ -108,4 +102,16 @@ import javax.crypto.spec.SecretKeySpec; ...@@ -108,4 +102,16 @@ import javax.crypto.spec.SecretKeySpec;
return upstream.getUri(); return upstream.getUri();
} }
@Override
public Map<String, List<String>> getResponseHeaders() {
return upstream.getResponseHeaders();
}
@Override
public void close() throws IOException {
if (cipherInputStream != null) {
cipherInputStream = null;
upstream.close();
}
}
} }
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