mirror of
https://github.com/samsonjs/media.git
synced 2026-04-27 15:07:40 +00:00
Deprecate/remove DataSource constructors that accept listeners
------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=207713478
This commit is contained in:
parent
829f55e9cd
commit
af507efb2a
12 changed files with 294 additions and 80 deletions
|
|
@ -16,7 +16,6 @@
|
||||||
package com.google.android.exoplayer2.ext.cronet;
|
package com.google.android.exoplayer2.ext.cronet;
|
||||||
|
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.support.annotation.Nullable;
|
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import com.google.android.exoplayer2.C;
|
import com.google.android.exoplayer2.C;
|
||||||
|
|
@ -25,7 +24,6 @@ import com.google.android.exoplayer2.upstream.BaseDataSource;
|
||||||
import com.google.android.exoplayer2.upstream.DataSourceException;
|
import com.google.android.exoplayer2.upstream.DataSourceException;
|
||||||
import com.google.android.exoplayer2.upstream.DataSpec;
|
import com.google.android.exoplayer2.upstream.DataSpec;
|
||||||
import com.google.android.exoplayer2.upstream.HttpDataSource;
|
import com.google.android.exoplayer2.upstream.HttpDataSource;
|
||||||
import com.google.android.exoplayer2.upstream.TransferListener;
|
|
||||||
import com.google.android.exoplayer2.util.Assertions;
|
import com.google.android.exoplayer2.util.Assertions;
|
||||||
import com.google.android.exoplayer2.util.Clock;
|
import com.google.android.exoplayer2.util.Clock;
|
||||||
import com.google.android.exoplayer2.util.ConditionVariable;
|
import com.google.android.exoplayer2.util.ConditionVariable;
|
||||||
|
|
@ -156,15 +154,18 @@ public class CronetDataSource extends BaseDataSource implements HttpDataSource {
|
||||||
* @param contentTypePredicate An optional {@link Predicate}. If a content type is rejected by the
|
* @param contentTypePredicate An optional {@link Predicate}. If a content type is rejected by the
|
||||||
* predicate then an {@link InvalidContentTypeException} is thrown from {@link
|
* predicate then an {@link InvalidContentTypeException} is thrown from {@link
|
||||||
* #open(DataSpec)}.
|
* #open(DataSpec)}.
|
||||||
* @param listener An optional listener.
|
|
||||||
*/
|
*/
|
||||||
public CronetDataSource(
|
public CronetDataSource(
|
||||||
CronetEngine cronetEngine,
|
CronetEngine cronetEngine, Executor executor, Predicate<String> contentTypePredicate) {
|
||||||
Executor executor,
|
this(
|
||||||
Predicate<String> contentTypePredicate,
|
cronetEngine,
|
||||||
@Nullable TransferListener listener) {
|
executor,
|
||||||
this(cronetEngine, executor, contentTypePredicate, listener, DEFAULT_CONNECT_TIMEOUT_MILLIS,
|
contentTypePredicate,
|
||||||
DEFAULT_READ_TIMEOUT_MILLIS, false, null, false);
|
DEFAULT_CONNECT_TIMEOUT_MILLIS,
|
||||||
|
DEFAULT_READ_TIMEOUT_MILLIS,
|
||||||
|
false,
|
||||||
|
null,
|
||||||
|
false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -177,7 +178,6 @@ public class CronetDataSource extends BaseDataSource implements HttpDataSource {
|
||||||
* @param contentTypePredicate An optional {@link Predicate}. If a content type is rejected by the
|
* @param contentTypePredicate An optional {@link Predicate}. If a content type is rejected by the
|
||||||
* predicate then an {@link InvalidContentTypeException} is thrown from {@link
|
* predicate then an {@link InvalidContentTypeException} is thrown from {@link
|
||||||
* #open(DataSpec)}.
|
* #open(DataSpec)}.
|
||||||
* @param listener An optional listener.
|
|
||||||
* @param connectTimeoutMs The connection timeout, in milliseconds.
|
* @param connectTimeoutMs The connection timeout, in milliseconds.
|
||||||
* @param readTimeoutMs The read timeout, in milliseconds.
|
* @param readTimeoutMs The read timeout, in milliseconds.
|
||||||
* @param resetTimeoutOnRedirects Whether the connect timeout is reset when a redirect occurs.
|
* @param resetTimeoutOnRedirects Whether the connect timeout is reset when a redirect occurs.
|
||||||
|
|
@ -187,13 +187,20 @@ public class CronetDataSource extends BaseDataSource implements HttpDataSource {
|
||||||
CronetEngine cronetEngine,
|
CronetEngine cronetEngine,
|
||||||
Executor executor,
|
Executor executor,
|
||||||
Predicate<String> contentTypePredicate,
|
Predicate<String> contentTypePredicate,
|
||||||
@Nullable TransferListener listener,
|
|
||||||
int connectTimeoutMs,
|
int connectTimeoutMs,
|
||||||
int readTimeoutMs,
|
int readTimeoutMs,
|
||||||
boolean resetTimeoutOnRedirects,
|
boolean resetTimeoutOnRedirects,
|
||||||
RequestProperties defaultRequestProperties) {
|
RequestProperties defaultRequestProperties) {
|
||||||
this(cronetEngine, executor, contentTypePredicate, listener, connectTimeoutMs,
|
this(
|
||||||
readTimeoutMs, resetTimeoutOnRedirects, Clock.DEFAULT, defaultRequestProperties, false);
|
cronetEngine,
|
||||||
|
executor,
|
||||||
|
contentTypePredicate,
|
||||||
|
connectTimeoutMs,
|
||||||
|
readTimeoutMs,
|
||||||
|
resetTimeoutOnRedirects,
|
||||||
|
Clock.DEFAULT,
|
||||||
|
defaultRequestProperties,
|
||||||
|
false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -206,7 +213,6 @@ public class CronetDataSource extends BaseDataSource implements HttpDataSource {
|
||||||
* @param contentTypePredicate An optional {@link Predicate}. If a content type is rejected by the
|
* @param contentTypePredicate An optional {@link Predicate}. If a content type is rejected by the
|
||||||
* predicate then an {@link InvalidContentTypeException} is thrown from {@link
|
* predicate then an {@link InvalidContentTypeException} is thrown from {@link
|
||||||
* #open(DataSpec)}.
|
* #open(DataSpec)}.
|
||||||
* @param listener An optional listener.
|
|
||||||
* @param connectTimeoutMs The connection timeout, in milliseconds.
|
* @param connectTimeoutMs The connection timeout, in milliseconds.
|
||||||
* @param readTimeoutMs The read timeout, in milliseconds.
|
* @param readTimeoutMs The read timeout, in milliseconds.
|
||||||
* @param resetTimeoutOnRedirects Whether the connect timeout is reset when a redirect occurs.
|
* @param resetTimeoutOnRedirects Whether the connect timeout is reset when a redirect occurs.
|
||||||
|
|
@ -218,14 +224,20 @@ public class CronetDataSource extends BaseDataSource implements HttpDataSource {
|
||||||
CronetEngine cronetEngine,
|
CronetEngine cronetEngine,
|
||||||
Executor executor,
|
Executor executor,
|
||||||
Predicate<String> contentTypePredicate,
|
Predicate<String> contentTypePredicate,
|
||||||
@Nullable TransferListener listener,
|
|
||||||
int connectTimeoutMs,
|
int connectTimeoutMs,
|
||||||
int readTimeoutMs,
|
int readTimeoutMs,
|
||||||
boolean resetTimeoutOnRedirects,
|
boolean resetTimeoutOnRedirects,
|
||||||
RequestProperties defaultRequestProperties,
|
RequestProperties defaultRequestProperties,
|
||||||
boolean handleSetCookieRequests) {
|
boolean handleSetCookieRequests) {
|
||||||
this(cronetEngine, executor, contentTypePredicate, listener, connectTimeoutMs,
|
this(
|
||||||
readTimeoutMs, resetTimeoutOnRedirects, Clock.DEFAULT, defaultRequestProperties,
|
cronetEngine,
|
||||||
|
executor,
|
||||||
|
contentTypePredicate,
|
||||||
|
connectTimeoutMs,
|
||||||
|
readTimeoutMs,
|
||||||
|
resetTimeoutOnRedirects,
|
||||||
|
Clock.DEFAULT,
|
||||||
|
defaultRequestProperties,
|
||||||
handleSetCookieRequests);
|
handleSetCookieRequests);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -233,7 +245,6 @@ public class CronetDataSource extends BaseDataSource implements HttpDataSource {
|
||||||
CronetEngine cronetEngine,
|
CronetEngine cronetEngine,
|
||||||
Executor executor,
|
Executor executor,
|
||||||
Predicate<String> contentTypePredicate,
|
Predicate<String> contentTypePredicate,
|
||||||
@Nullable TransferListener listener,
|
|
||||||
int connectTimeoutMs,
|
int connectTimeoutMs,
|
||||||
int readTimeoutMs,
|
int readTimeoutMs,
|
||||||
boolean resetTimeoutOnRedirects,
|
boolean resetTimeoutOnRedirects,
|
||||||
|
|
@ -253,9 +264,6 @@ public class CronetDataSource extends BaseDataSource implements HttpDataSource {
|
||||||
this.handleSetCookieRequests = handleSetCookieRequests;
|
this.handleSetCookieRequests = handleSetCookieRequests;
|
||||||
requestProperties = new RequestProperties();
|
requestProperties = new RequestProperties();
|
||||||
operation = new ConditionVariable();
|
operation = new ConditionVariable();
|
||||||
if (listener != null) {
|
|
||||||
addTransferListener(listener);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// HttpDataSource implementation.
|
// HttpDataSource implementation.
|
||||||
|
|
|
||||||
|
|
@ -335,8 +335,19 @@ public final class CronetDataSourceFactory extends BaseFactory {
|
||||||
if (cronetEngine == null) {
|
if (cronetEngine == null) {
|
||||||
return fallbackFactory.createDataSource();
|
return fallbackFactory.createDataSource();
|
||||||
}
|
}
|
||||||
return new CronetDataSource(cronetEngine, executor, contentTypePredicate, transferListener,
|
CronetDataSource dataSource =
|
||||||
connectTimeoutMs, readTimeoutMs, resetTimeoutOnRedirects, defaultRequestProperties);
|
new CronetDataSource(
|
||||||
|
cronetEngine,
|
||||||
|
executor,
|
||||||
|
contentTypePredicate,
|
||||||
|
connectTimeoutMs,
|
||||||
|
readTimeoutMs,
|
||||||
|
resetTimeoutOnRedirects,
|
||||||
|
defaultRequestProperties);
|
||||||
|
if (transferListener != null) {
|
||||||
|
dataSource.addTransferListener(transferListener);
|
||||||
|
}
|
||||||
|
return dataSource;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -102,13 +102,13 @@ public final class CronetDataSourceTest {
|
||||||
mockCronetEngine,
|
mockCronetEngine,
|
||||||
mockExecutor,
|
mockExecutor,
|
||||||
mockContentTypePredicate,
|
mockContentTypePredicate,
|
||||||
mockTransferListener,
|
|
||||||
TEST_CONNECT_TIMEOUT_MS,
|
TEST_CONNECT_TIMEOUT_MS,
|
||||||
TEST_READ_TIMEOUT_MS,
|
TEST_READ_TIMEOUT_MS,
|
||||||
true, // resetTimeoutOnRedirects
|
true, // resetTimeoutOnRedirects
|
||||||
Clock.DEFAULT,
|
Clock.DEFAULT,
|
||||||
null,
|
null,
|
||||||
false);
|
false);
|
||||||
|
dataSourceUnderTest.addTransferListener(mockTransferListener);
|
||||||
when(mockContentTypePredicate.evaluate(anyString())).thenReturn(true);
|
when(mockContentTypePredicate.evaluate(anyString())).thenReturn(true);
|
||||||
when(mockCronetEngine.newUrlRequestBuilder(
|
when(mockCronetEngine.newUrlRequestBuilder(
|
||||||
anyString(), any(UrlRequest.Callback.class), any(Executor.class)))
|
anyString(), any(UrlRequest.Callback.class), any(Executor.class)))
|
||||||
|
|
@ -723,13 +723,13 @@ public final class CronetDataSourceTest {
|
||||||
mockCronetEngine,
|
mockCronetEngine,
|
||||||
mockExecutor,
|
mockExecutor,
|
||||||
mockContentTypePredicate,
|
mockContentTypePredicate,
|
||||||
mockTransferListener,
|
|
||||||
TEST_CONNECT_TIMEOUT_MS,
|
TEST_CONNECT_TIMEOUT_MS,
|
||||||
TEST_READ_TIMEOUT_MS,
|
TEST_READ_TIMEOUT_MS,
|
||||||
true, // resetTimeoutOnRedirects
|
true, // resetTimeoutOnRedirects
|
||||||
Clock.DEFAULT,
|
Clock.DEFAULT,
|
||||||
null,
|
null,
|
||||||
true);
|
true);
|
||||||
|
dataSourceUnderTest.addTransferListener(mockTransferListener);
|
||||||
dataSourceUnderTest.setRequestProperty("Content-Type", TEST_CONTENT_TYPE);
|
dataSourceUnderTest.setRequestProperty("Content-Type", TEST_CONTENT_TYPE);
|
||||||
|
|
||||||
mockSingleRedirectSuccess();
|
mockSingleRedirectSuccess();
|
||||||
|
|
@ -754,13 +754,13 @@ public final class CronetDataSourceTest {
|
||||||
mockCronetEngine,
|
mockCronetEngine,
|
||||||
mockExecutor,
|
mockExecutor,
|
||||||
mockContentTypePredicate,
|
mockContentTypePredicate,
|
||||||
mockTransferListener,
|
|
||||||
TEST_CONNECT_TIMEOUT_MS,
|
TEST_CONNECT_TIMEOUT_MS,
|
||||||
TEST_READ_TIMEOUT_MS,
|
TEST_READ_TIMEOUT_MS,
|
||||||
true, // resetTimeoutOnRedirects
|
true, // resetTimeoutOnRedirects
|
||||||
Clock.DEFAULT,
|
Clock.DEFAULT,
|
||||||
null,
|
null,
|
||||||
true);
|
true);
|
||||||
|
dataSourceUnderTest.addTransferListener(mockTransferListener);
|
||||||
dataSourceUnderTest.setRequestProperty("Content-Type", TEST_CONTENT_TYPE);
|
dataSourceUnderTest.setRequestProperty("Content-Type", TEST_CONTENT_TYPE);
|
||||||
|
|
||||||
mockSingleRedirectSuccess();
|
mockSingleRedirectSuccess();
|
||||||
|
|
@ -793,13 +793,13 @@ public final class CronetDataSourceTest {
|
||||||
mockCronetEngine,
|
mockCronetEngine,
|
||||||
mockExecutor,
|
mockExecutor,
|
||||||
mockContentTypePredicate,
|
mockContentTypePredicate,
|
||||||
mockTransferListener,
|
|
||||||
TEST_CONNECT_TIMEOUT_MS,
|
TEST_CONNECT_TIMEOUT_MS,
|
||||||
TEST_READ_TIMEOUT_MS,
|
TEST_READ_TIMEOUT_MS,
|
||||||
true, // resetTimeoutOnRedirects
|
true, // resetTimeoutOnRedirects
|
||||||
Clock.DEFAULT,
|
Clock.DEFAULT,
|
||||||
null,
|
null,
|
||||||
true);
|
true);
|
||||||
|
dataSourceUnderTest.addTransferListener(mockTransferListener);
|
||||||
mockSingleRedirectSuccess();
|
mockSingleRedirectSuccess();
|
||||||
mockFollowRedirectSuccess();
|
mockFollowRedirectSuccess();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -38,12 +38,16 @@ public final class RtmpDataSource extends BaseDataSource {
|
||||||
private Uri uri;
|
private Uri uri;
|
||||||
|
|
||||||
public RtmpDataSource() {
|
public RtmpDataSource() {
|
||||||
this(null);
|
super(/* isNetwork= */ true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @param listener An optional listener. */
|
/**
|
||||||
|
* @param listener An optional listener.
|
||||||
|
* @deprecated Use {@link #RtmpDataSource()} and {@link #addTransferListener(TransferListener)}.
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
public RtmpDataSource(@Nullable TransferListener listener) {
|
public RtmpDataSource(@Nullable TransferListener listener) {
|
||||||
super(/* isNetwork= */ true);
|
this();
|
||||||
if (listener != null) {
|
if (listener != null) {
|
||||||
addTransferListener(listener);
|
addTransferListener(listener);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -45,20 +45,21 @@ public final class AssetDataSource extends BaseDataSource {
|
||||||
private long bytesRemaining;
|
private long bytesRemaining;
|
||||||
private boolean opened;
|
private boolean opened;
|
||||||
|
|
||||||
/**
|
/** @param context A context. */
|
||||||
* @param context A context.
|
|
||||||
*/
|
|
||||||
public AssetDataSource(Context context) {
|
public AssetDataSource(Context context) {
|
||||||
this(context, null);
|
super(/* isNetwork= */ false);
|
||||||
|
this.assetManager = context.getAssets();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param context A context.
|
* @param context A context.
|
||||||
* @param listener An optional listener.
|
* @param listener An optional listener.
|
||||||
|
* @deprecated Use {@link #AssetDataSource(Context)} and {@link
|
||||||
|
* #addTransferListener(TransferListener)}.
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
public AssetDataSource(Context context, @Nullable TransferListener listener) {
|
public AssetDataSource(Context context, @Nullable TransferListener listener) {
|
||||||
super(/* isNetwork= */ false);
|
this(context);
|
||||||
this.assetManager = context.getAssets();
|
|
||||||
if (listener != null) {
|
if (listener != null) {
|
||||||
addTransferListener(listener);
|
addTransferListener(listener);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -53,16 +53,19 @@ public final class ContentDataSource extends BaseDataSource {
|
||||||
* @param context A context.
|
* @param context A context.
|
||||||
*/
|
*/
|
||||||
public ContentDataSource(Context context) {
|
public ContentDataSource(Context context) {
|
||||||
this(context, null);
|
super(/* isNetwork= */ false);
|
||||||
|
this.resolver = context.getContentResolver();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param context A context.
|
* @param context A context.
|
||||||
* @param listener An optional listener.
|
* @param listener An optional listener.
|
||||||
|
* @deprecated Use {@link #ContentDataSource(Context)} and {@link
|
||||||
|
* #addTransferListener(TransferListener)}.
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
public ContentDataSource(Context context, @Nullable TransferListener listener) {
|
public ContentDataSource(Context context, @Nullable TransferListener listener) {
|
||||||
super(/* isNetwork= */ false);
|
this(context);
|
||||||
this.resolver = context.getContentResolver();
|
|
||||||
if (listener != null) {
|
if (listener != null) {
|
||||||
addTransferListener(listener);
|
addTransferListener(listener);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -74,11 +74,74 @@ public final class DefaultDataSource implements DataSource {
|
||||||
* Constructs a new instance, optionally configured to follow cross-protocol redirects.
|
* Constructs a new instance, optionally configured to follow cross-protocol redirects.
|
||||||
*
|
*
|
||||||
* @param context A context.
|
* @param context A context.
|
||||||
* @param listener An optional listener.
|
* @param userAgent The User-Agent to use when requesting remote data.
|
||||||
* @param userAgent The User-Agent string that should be used when requesting remote data.
|
|
||||||
* @param allowCrossProtocolRedirects Whether cross-protocol redirects (i.e. redirects from HTTP
|
* @param allowCrossProtocolRedirects Whether cross-protocol redirects (i.e. redirects from HTTP
|
||||||
* to HTTPS and vice versa) are enabled when fetching remote data.
|
* to HTTPS and vice versa) are enabled when fetching remote data.
|
||||||
*/
|
*/
|
||||||
|
public DefaultDataSource(Context context, String userAgent, boolean allowCrossProtocolRedirects) {
|
||||||
|
this(
|
||||||
|
context,
|
||||||
|
userAgent,
|
||||||
|
DefaultHttpDataSource.DEFAULT_CONNECT_TIMEOUT_MILLIS,
|
||||||
|
DefaultHttpDataSource.DEFAULT_READ_TIMEOUT_MILLIS,
|
||||||
|
allowCrossProtocolRedirects);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs a new instance, optionally configured to follow cross-protocol redirects.
|
||||||
|
*
|
||||||
|
* @param context A context.
|
||||||
|
* @param userAgent The User-Agent to use when requesting remote data.
|
||||||
|
* @param connectTimeoutMillis The connection timeout that should be used when requesting remote
|
||||||
|
* data, in milliseconds. A timeout of zero is interpreted as an infinite timeout.
|
||||||
|
* @param readTimeoutMillis The read timeout that should be used when requesting remote data, in
|
||||||
|
* milliseconds. A timeout of zero is interpreted as an infinite timeout.
|
||||||
|
* @param allowCrossProtocolRedirects Whether cross-protocol redirects (i.e. redirects from HTTP
|
||||||
|
* to HTTPS and vice versa) are enabled when fetching remote data.
|
||||||
|
*/
|
||||||
|
public DefaultDataSource(
|
||||||
|
Context context,
|
||||||
|
String userAgent,
|
||||||
|
int connectTimeoutMillis,
|
||||||
|
int readTimeoutMillis,
|
||||||
|
boolean allowCrossProtocolRedirects) {
|
||||||
|
this(
|
||||||
|
context,
|
||||||
|
new DefaultHttpDataSource(
|
||||||
|
userAgent,
|
||||||
|
/* contentTypePredicate= */ null,
|
||||||
|
connectTimeoutMillis,
|
||||||
|
readTimeoutMillis,
|
||||||
|
allowCrossProtocolRedirects,
|
||||||
|
/* defaultRequestProperties= */ null));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs a new instance that delegates to a provided {@link DataSource} for URI schemes other
|
||||||
|
* than file, asset and content.
|
||||||
|
*
|
||||||
|
* @param context A context.
|
||||||
|
* @param baseDataSource A {@link DataSource} to use for URI schemes other than file, asset and
|
||||||
|
* content. This {@link DataSource} should normally support at least http(s).
|
||||||
|
*/
|
||||||
|
public DefaultDataSource(Context context, DataSource baseDataSource) {
|
||||||
|
this.context = context.getApplicationContext();
|
||||||
|
this.baseDataSource = Assertions.checkNotNull(baseDataSource);
|
||||||
|
transferListeners = new ArrayList<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs a new instance, optionally configured to follow cross-protocol redirects.
|
||||||
|
*
|
||||||
|
* @param context A context.
|
||||||
|
* @param listener An optional listener.
|
||||||
|
* @param userAgent The User-Agent to use when requesting remote data.
|
||||||
|
* @param allowCrossProtocolRedirects Whether cross-protocol redirects (i.e. redirects from HTTP
|
||||||
|
* to HTTPS and vice versa) are enabled when fetching remote data.
|
||||||
|
* @deprecated Use {@link #DefaultDataSource(Context, String, boolean)} and {@link
|
||||||
|
* #addTransferListener(TransferListener)}.
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
public DefaultDataSource(
|
public DefaultDataSource(
|
||||||
Context context,
|
Context context,
|
||||||
@Nullable TransferListener listener,
|
@Nullable TransferListener listener,
|
||||||
|
|
@ -93,14 +156,17 @@ public final class DefaultDataSource implements DataSource {
|
||||||
*
|
*
|
||||||
* @param context A context.
|
* @param context A context.
|
||||||
* @param listener An optional listener.
|
* @param listener An optional listener.
|
||||||
* @param userAgent The User-Agent string that should be used when requesting remote data.
|
* @param userAgent The User-Agent to use when requesting remote data.
|
||||||
* @param connectTimeoutMillis The connection timeout that should be used when requesting remote
|
* @param connectTimeoutMillis The connection timeout that should be used when requesting remote
|
||||||
* data, in milliseconds. A timeout of zero is interpreted as an infinite timeout.
|
* data, in milliseconds. A timeout of zero is interpreted as an infinite timeout.
|
||||||
* @param readTimeoutMillis The read timeout that should be used when requesting remote data, in
|
* @param readTimeoutMillis The read timeout that should be used when requesting remote data, in
|
||||||
* milliseconds. A timeout of zero is interpreted as an infinite timeout.
|
* milliseconds. A timeout of zero is interpreted as an infinite timeout.
|
||||||
* @param allowCrossProtocolRedirects Whether cross-protocol redirects (i.e. redirects from HTTP
|
* @param allowCrossProtocolRedirects Whether cross-protocol redirects (i.e. redirects from HTTP
|
||||||
* to HTTPS and vice versa) are enabled when fetching remote data.
|
* to HTTPS and vice versa) are enabled when fetching remote data.
|
||||||
|
* @deprecated Use {@link #DefaultDataSource(Context, String, int, int, boolean)} and {@link
|
||||||
|
* #addTransferListener(TransferListener)}.
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
public DefaultDataSource(
|
public DefaultDataSource(
|
||||||
Context context,
|
Context context,
|
||||||
@Nullable TransferListener listener,
|
@Nullable TransferListener listener,
|
||||||
|
|
@ -108,9 +174,17 @@ public final class DefaultDataSource implements DataSource {
|
||||||
int connectTimeoutMillis,
|
int connectTimeoutMillis,
|
||||||
int readTimeoutMillis,
|
int readTimeoutMillis,
|
||||||
boolean allowCrossProtocolRedirects) {
|
boolean allowCrossProtocolRedirects) {
|
||||||
this(context, listener,
|
this(
|
||||||
new DefaultHttpDataSource(userAgent, null, listener, connectTimeoutMillis,
|
context,
|
||||||
readTimeoutMillis, allowCrossProtocolRedirects, null));
|
listener,
|
||||||
|
new DefaultHttpDataSource(
|
||||||
|
userAgent,
|
||||||
|
/* contentTypePredicate= */ null,
|
||||||
|
listener,
|
||||||
|
connectTimeoutMillis,
|
||||||
|
readTimeoutMillis,
|
||||||
|
allowCrossProtocolRedirects,
|
||||||
|
/* defaultRequestProperties= */ null));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -121,12 +195,13 @@ public final class DefaultDataSource implements DataSource {
|
||||||
* @param listener An optional listener.
|
* @param listener An optional listener.
|
||||||
* @param baseDataSource A {@link DataSource} to use for URI schemes other than file, asset and
|
* @param baseDataSource A {@link DataSource} to use for URI schemes other than file, asset and
|
||||||
* content. This {@link DataSource} should normally support at least http(s).
|
* content. This {@link DataSource} should normally support at least http(s).
|
||||||
|
* @deprecated Use {@link #DefaultDataSource(Context, DataSource)} and {@link
|
||||||
|
* #addTransferListener(TransferListener)}.
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
public DefaultDataSource(
|
public DefaultDataSource(
|
||||||
Context context, @Nullable TransferListener listener, DataSource baseDataSource) {
|
Context context, @Nullable TransferListener listener, DataSource baseDataSource) {
|
||||||
this.context = context.getApplicationContext();
|
this(context, baseDataSource);
|
||||||
this.baseDataSource = Assertions.checkNotNull(baseDataSource);
|
|
||||||
transferListeners = new ArrayList<>();
|
|
||||||
if (listener != null) {
|
if (listener != null) {
|
||||||
transferListeners.add(listener);
|
transferListeners.add(listener);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -92,7 +92,67 @@ public class DefaultHttpDataSource extends BaseDataSource implements HttpDataSou
|
||||||
* #open(DataSpec)}.
|
* #open(DataSpec)}.
|
||||||
*/
|
*/
|
||||||
public DefaultHttpDataSource(String userAgent, @Nullable Predicate<String> contentTypePredicate) {
|
public DefaultHttpDataSource(String userAgent, @Nullable Predicate<String> contentTypePredicate) {
|
||||||
this(userAgent, contentTypePredicate, null);
|
this(
|
||||||
|
userAgent,
|
||||||
|
contentTypePredicate,
|
||||||
|
DEFAULT_CONNECT_TIMEOUT_MILLIS,
|
||||||
|
DEFAULT_READ_TIMEOUT_MILLIS);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param userAgent The User-Agent string that should be used.
|
||||||
|
* @param contentTypePredicate An optional {@link Predicate}. If a content type is rejected by the
|
||||||
|
* predicate then a {@link HttpDataSource.InvalidContentTypeException} is thrown from {@link
|
||||||
|
* #open(DataSpec)}.
|
||||||
|
* @param connectTimeoutMillis The connection timeout, in milliseconds. A timeout of zero is
|
||||||
|
* interpreted as an infinite timeout.
|
||||||
|
* @param readTimeoutMillis The read timeout, in milliseconds. A timeout of zero is interpreted as
|
||||||
|
* an infinite timeout.
|
||||||
|
*/
|
||||||
|
public DefaultHttpDataSource(
|
||||||
|
String userAgent,
|
||||||
|
@Nullable Predicate<String> contentTypePredicate,
|
||||||
|
int connectTimeoutMillis,
|
||||||
|
int readTimeoutMillis) {
|
||||||
|
this(
|
||||||
|
userAgent,
|
||||||
|
contentTypePredicate,
|
||||||
|
connectTimeoutMillis,
|
||||||
|
readTimeoutMillis,
|
||||||
|
/* allowCrossProtocolRedirects= */ false,
|
||||||
|
/* defaultRequestProperties= */ null);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param userAgent The User-Agent string that should be used.
|
||||||
|
* @param contentTypePredicate An optional {@link Predicate}. If a content type is rejected by the
|
||||||
|
* predicate then a {@link HttpDataSource.InvalidContentTypeException} is thrown from {@link
|
||||||
|
* #open(DataSpec)}.
|
||||||
|
* @param connectTimeoutMillis The connection timeout, in milliseconds. A timeout of zero is
|
||||||
|
* interpreted as an infinite timeout. Pass {@link #DEFAULT_CONNECT_TIMEOUT_MILLIS} to use the
|
||||||
|
* default value.
|
||||||
|
* @param readTimeoutMillis The read timeout, in milliseconds. A timeout of zero is interpreted as
|
||||||
|
* an infinite timeout. Pass {@link #DEFAULT_READ_TIMEOUT_MILLIS} to use the default value.
|
||||||
|
* @param allowCrossProtocolRedirects Whether cross-protocol redirects (i.e. redirects from HTTP
|
||||||
|
* to HTTPS and vice versa) are enabled.
|
||||||
|
* @param defaultRequestProperties The default request properties to be sent to the server as HTTP
|
||||||
|
* headers or {@code null} if not required.
|
||||||
|
*/
|
||||||
|
public DefaultHttpDataSource(
|
||||||
|
String userAgent,
|
||||||
|
@Nullable Predicate<String> contentTypePredicate,
|
||||||
|
int connectTimeoutMillis,
|
||||||
|
int readTimeoutMillis,
|
||||||
|
boolean allowCrossProtocolRedirects,
|
||||||
|
@Nullable RequestProperties defaultRequestProperties) {
|
||||||
|
super(/* isNetwork= */ true);
|
||||||
|
this.userAgent = Assertions.checkNotEmpty(userAgent);
|
||||||
|
this.contentTypePredicate = contentTypePredicate;
|
||||||
|
this.requestProperties = new RequestProperties();
|
||||||
|
this.connectTimeoutMillis = connectTimeoutMillis;
|
||||||
|
this.readTimeoutMillis = readTimeoutMillis;
|
||||||
|
this.allowCrossProtocolRedirects = allowCrossProtocolRedirects;
|
||||||
|
this.defaultRequestProperties = defaultRequestProperties;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -101,7 +161,10 @@ public class DefaultHttpDataSource extends BaseDataSource implements HttpDataSou
|
||||||
* predicate then a {@link HttpDataSource.InvalidContentTypeException} is thrown from {@link
|
* predicate then a {@link HttpDataSource.InvalidContentTypeException} is thrown from {@link
|
||||||
* #open(DataSpec)}.
|
* #open(DataSpec)}.
|
||||||
* @param listener An optional listener.
|
* @param listener An optional listener.
|
||||||
|
* @deprecated Use {@link #DefaultHttpDataSource(String, Predicate)} and {@link
|
||||||
|
* #addTransferListener(TransferListener)}.
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
public DefaultHttpDataSource(
|
public DefaultHttpDataSource(
|
||||||
String userAgent,
|
String userAgent,
|
||||||
@Nullable Predicate<String> contentTypePredicate,
|
@Nullable Predicate<String> contentTypePredicate,
|
||||||
|
|
@ -120,7 +183,10 @@ public class DefaultHttpDataSource extends BaseDataSource implements HttpDataSou
|
||||||
* interpreted as an infinite timeout.
|
* interpreted as an infinite timeout.
|
||||||
* @param readTimeoutMillis The read timeout, in milliseconds. A timeout of zero is interpreted as
|
* @param readTimeoutMillis The read timeout, in milliseconds. A timeout of zero is interpreted as
|
||||||
* an infinite timeout.
|
* an infinite timeout.
|
||||||
|
* @deprecated Use {@link #DefaultHttpDataSource(String, Predicate, int, int)} and {@link
|
||||||
|
* #addTransferListener(TransferListener)}.
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
public DefaultHttpDataSource(
|
public DefaultHttpDataSource(
|
||||||
String userAgent,
|
String userAgent,
|
||||||
@Nullable Predicate<String> contentTypePredicate,
|
@Nullable Predicate<String> contentTypePredicate,
|
||||||
|
|
@ -146,7 +212,10 @@ public class DefaultHttpDataSource extends BaseDataSource implements HttpDataSou
|
||||||
* to HTTPS and vice versa) are enabled.
|
* to HTTPS and vice versa) are enabled.
|
||||||
* @param defaultRequestProperties The default request properties to be sent to the server as HTTP
|
* @param defaultRequestProperties The default request properties to be sent to the server as HTTP
|
||||||
* headers or {@code null} if not required.
|
* headers or {@code null} if not required.
|
||||||
|
* @deprecated Use {@link #DefaultHttpDataSource(String, Predicate, int, int, boolean,
|
||||||
|
* RequestProperties)} and {@link #addTransferListener(TransferListener)}.
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
public DefaultHttpDataSource(
|
public DefaultHttpDataSource(
|
||||||
String userAgent,
|
String userAgent,
|
||||||
@Nullable Predicate<String> contentTypePredicate,
|
@Nullable Predicate<String> contentTypePredicate,
|
||||||
|
|
@ -155,14 +224,13 @@ public class DefaultHttpDataSource extends BaseDataSource implements HttpDataSou
|
||||||
int readTimeoutMillis,
|
int readTimeoutMillis,
|
||||||
boolean allowCrossProtocolRedirects,
|
boolean allowCrossProtocolRedirects,
|
||||||
@Nullable RequestProperties defaultRequestProperties) {
|
@Nullable RequestProperties defaultRequestProperties) {
|
||||||
super(/* isNetwork= */ true);
|
this(
|
||||||
this.userAgent = Assertions.checkNotEmpty(userAgent);
|
userAgent,
|
||||||
this.contentTypePredicate = contentTypePredicate;
|
contentTypePredicate,
|
||||||
this.requestProperties = new RequestProperties();
|
connectTimeoutMillis,
|
||||||
this.connectTimeoutMillis = connectTimeoutMillis;
|
readTimeoutMillis,
|
||||||
this.readTimeoutMillis = readTimeoutMillis;
|
allowCrossProtocolRedirects,
|
||||||
this.allowCrossProtocolRedirects = allowCrossProtocolRedirects;
|
defaultRequestProperties);
|
||||||
this.defaultRequestProperties = defaultRequestProperties;
|
|
||||||
if (listener != null) {
|
if (listener != null) {
|
||||||
addTransferListener(listener);
|
addTransferListener(listener);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -42,12 +42,16 @@ public final class FileDataSource extends BaseDataSource {
|
||||||
private boolean opened;
|
private boolean opened;
|
||||||
|
|
||||||
public FileDataSource() {
|
public FileDataSource() {
|
||||||
this(null);
|
super(/* isNetwork= */ false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @param listener An optional listener. */
|
/**
|
||||||
|
* @param listener An optional listener.
|
||||||
|
* @deprecated Use {@link #FileDataSource()} and {@link #addTransferListener(TransferListener)}
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
public FileDataSource(@Nullable TransferListener listener) {
|
public FileDataSource(@Nullable TransferListener listener) {
|
||||||
super(/* isNetwork= */ false);
|
this();
|
||||||
if (listener != null) {
|
if (listener != null) {
|
||||||
addTransferListener(listener);
|
addTransferListener(listener);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -74,16 +74,19 @@ public final class RawResourceDataSource extends BaseDataSource {
|
||||||
* @param context A context.
|
* @param context A context.
|
||||||
*/
|
*/
|
||||||
public RawResourceDataSource(Context context) {
|
public RawResourceDataSource(Context context) {
|
||||||
this(context, null);
|
super(/* isNetwork= */ false);
|
||||||
|
this.resources = context.getResources();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param context A context.
|
* @param context A context.
|
||||||
* @param listener An optional listener.
|
* @param listener An optional listener.
|
||||||
|
* @deprecated Use {@link #RawResourceDataSource(Context)} and {@link
|
||||||
|
* #addTransferListener(TransferListener)}.
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
public RawResourceDataSource(Context context, @Nullable TransferListener listener) {
|
public RawResourceDataSource(Context context, @Nullable TransferListener listener) {
|
||||||
super(/* isNetwork= */ false);
|
this(context);
|
||||||
this.resources = context.getResources();
|
|
||||||
if (listener != null) {
|
if (listener != null) {
|
||||||
addTransferListener(listener);
|
addTransferListener(listener);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -45,10 +45,8 @@ public final class UdpDataSource extends BaseDataSource {
|
||||||
*/
|
*/
|
||||||
public static final int DEFAULT_MAX_PACKET_SIZE = 2000;
|
public static final int DEFAULT_MAX_PACKET_SIZE = 2000;
|
||||||
|
|
||||||
/**
|
/** The default socket timeout, in milliseconds. */
|
||||||
* The default socket timeout, in milliseconds.
|
public static final int DEFAULT_SOCKET_TIMEOUT_MILLIS = 8 * 1000;
|
||||||
*/
|
|
||||||
public static final int DEAFULT_SOCKET_TIMEOUT_MILLIS = 8 * 1000;
|
|
||||||
|
|
||||||
private final int socketTimeoutMillis;
|
private final int socketTimeoutMillis;
|
||||||
private final byte[] packetBuffer;
|
private final byte[] packetBuffer;
|
||||||
|
|
@ -63,31 +61,70 @@ public final class UdpDataSource extends BaseDataSource {
|
||||||
|
|
||||||
private int packetRemaining;
|
private int packetRemaining;
|
||||||
|
|
||||||
/** @param listener An optional listener. */
|
public UdpDataSource() {
|
||||||
|
this(DEFAULT_MAX_PACKET_SIZE);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs a new instance.
|
||||||
|
*
|
||||||
|
* @param maxPacketSize The maximum datagram packet size, in bytes.
|
||||||
|
*/
|
||||||
|
public UdpDataSource(int maxPacketSize) {
|
||||||
|
this(maxPacketSize, DEFAULT_SOCKET_TIMEOUT_MILLIS);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs a new instance.
|
||||||
|
*
|
||||||
|
* @param maxPacketSize The maximum datagram packet size, in bytes.
|
||||||
|
* @param socketTimeoutMillis The socket timeout in milliseconds. A timeout of zero is interpreted
|
||||||
|
* as an infinite timeout.
|
||||||
|
*/
|
||||||
|
public UdpDataSource(int maxPacketSize, int socketTimeoutMillis) {
|
||||||
|
super(/* isNetwork= */ true);
|
||||||
|
this.socketTimeoutMillis = socketTimeoutMillis;
|
||||||
|
packetBuffer = new byte[maxPacketSize];
|
||||||
|
packet = new DatagramPacket(packetBuffer, 0, maxPacketSize);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs a new instance.
|
||||||
|
*
|
||||||
|
* @param listener An optional listener.
|
||||||
|
* @deprecated Use {@link #UdpDataSource()} and {@link #addTransferListener(TransferListener)}.
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
public UdpDataSource(@Nullable TransferListener listener) {
|
public UdpDataSource(@Nullable TransferListener listener) {
|
||||||
this(listener, DEFAULT_MAX_PACKET_SIZE);
|
this(listener, DEFAULT_MAX_PACKET_SIZE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Constructs a new instance.
|
||||||
|
*
|
||||||
* @param listener An optional listener.
|
* @param listener An optional listener.
|
||||||
* @param maxPacketSize The maximum datagram packet size, in bytes.
|
* @param maxPacketSize The maximum datagram packet size, in bytes.
|
||||||
|
* @deprecated Use {@link #UdpDataSource(int)} and {@link #addTransferListener(TransferListener)}.
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
public UdpDataSource(@Nullable TransferListener listener, int maxPacketSize) {
|
public UdpDataSource(@Nullable TransferListener listener, int maxPacketSize) {
|
||||||
this(listener, maxPacketSize, DEAFULT_SOCKET_TIMEOUT_MILLIS);
|
this(listener, maxPacketSize, DEFAULT_SOCKET_TIMEOUT_MILLIS);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Constructs a new instance.
|
||||||
|
*
|
||||||
* @param listener An optional listener.
|
* @param listener An optional listener.
|
||||||
* @param maxPacketSize The maximum datagram packet size, in bytes.
|
* @param maxPacketSize The maximum datagram packet size, in bytes.
|
||||||
* @param socketTimeoutMillis The socket timeout in milliseconds. A timeout of zero is interpreted
|
* @param socketTimeoutMillis The socket timeout in milliseconds. A timeout of zero is interpreted
|
||||||
* as an infinite timeout.
|
* as an infinite timeout.
|
||||||
|
* @deprecated Use {@link #UdpDataSource(int, int)} and {@link
|
||||||
|
* #addTransferListener(TransferListener)}.
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
public UdpDataSource(
|
public UdpDataSource(
|
||||||
@Nullable TransferListener listener, int maxPacketSize, int socketTimeoutMillis) {
|
@Nullable TransferListener listener, int maxPacketSize, int socketTimeoutMillis) {
|
||||||
super(/* isNetwork= */ true);
|
this(maxPacketSize, socketTimeoutMillis);
|
||||||
this.socketTimeoutMillis = socketTimeoutMillis;
|
|
||||||
packetBuffer = new byte[maxPacketSize];
|
|
||||||
packet = new DatagramPacket(packetBuffer, 0, maxPacketSize);
|
|
||||||
if (listener != null) {
|
if (listener != null) {
|
||||||
addTransferListener(listener);
|
addTransferListener(listener);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -60,7 +60,11 @@ public class FakeDataSource extends BaseDataSource {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public DataSource createDataSource() {
|
public DataSource createDataSource() {
|
||||||
return new FakeDataSource(fakeDataSet, transferListener, isNetwork);
|
FakeDataSource dataSource = new FakeDataSource(fakeDataSet, isNetwork);
|
||||||
|
if (transferListener != null) {
|
||||||
|
dataSource.addTransferListener(transferListener);
|
||||||
|
}
|
||||||
|
return dataSource;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -79,18 +83,14 @@ public class FakeDataSource extends BaseDataSource {
|
||||||
}
|
}
|
||||||
|
|
||||||
public FakeDataSource(FakeDataSet fakeDataSet) {
|
public FakeDataSource(FakeDataSet fakeDataSet) {
|
||||||
this(fakeDataSet, null, /* isNetwork= */ false);
|
this(fakeDataSet, /* isNetwork= */ false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public FakeDataSource(
|
public FakeDataSource(FakeDataSet fakeDataSet, boolean isNetwork) {
|
||||||
FakeDataSet fakeDataSet, @Nullable TransferListener transferListener, boolean isNetwork) {
|
|
||||||
super(isNetwork);
|
super(isNetwork);
|
||||||
Assertions.checkNotNull(fakeDataSet);
|
Assertions.checkNotNull(fakeDataSet);
|
||||||
this.fakeDataSet = fakeDataSet;
|
this.fakeDataSet = fakeDataSet;
|
||||||
this.openedDataSpecs = new ArrayList<>();
|
this.openedDataSpecs = new ArrayList<>();
|
||||||
if (transferListener != null) {
|
|
||||||
addTransferListener(transferListener);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public final FakeDataSet getDataSet() {
|
public final FakeDataSet getDataSet() {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue