mirror of
https://github.com/samsonjs/media.git
synced 2026-04-14 12:45:47 +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;
|
||||
|
||||
import android.net.Uri;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
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.DataSpec;
|
||||
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.Clock;
|
||||
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
|
||||
* predicate then an {@link InvalidContentTypeException} is thrown from {@link
|
||||
* #open(DataSpec)}.
|
||||
* @param listener An optional listener.
|
||||
*/
|
||||
public CronetDataSource(
|
||||
CronetEngine cronetEngine,
|
||||
Executor executor,
|
||||
Predicate<String> contentTypePredicate,
|
||||
@Nullable TransferListener listener) {
|
||||
this(cronetEngine, executor, contentTypePredicate, listener, DEFAULT_CONNECT_TIMEOUT_MILLIS,
|
||||
DEFAULT_READ_TIMEOUT_MILLIS, false, null, false);
|
||||
CronetEngine cronetEngine, Executor executor, Predicate<String> contentTypePredicate) {
|
||||
this(
|
||||
cronetEngine,
|
||||
executor,
|
||||
contentTypePredicate,
|
||||
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
|
||||
* predicate then an {@link InvalidContentTypeException} is thrown from {@link
|
||||
* #open(DataSpec)}.
|
||||
* @param listener An optional listener.
|
||||
* @param connectTimeoutMs The connection timeout, in milliseconds.
|
||||
* @param readTimeoutMs The read timeout, in milliseconds.
|
||||
* @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,
|
||||
Executor executor,
|
||||
Predicate<String> contentTypePredicate,
|
||||
@Nullable TransferListener listener,
|
||||
int connectTimeoutMs,
|
||||
int readTimeoutMs,
|
||||
boolean resetTimeoutOnRedirects,
|
||||
RequestProperties defaultRequestProperties) {
|
||||
this(cronetEngine, executor, contentTypePredicate, listener, connectTimeoutMs,
|
||||
readTimeoutMs, resetTimeoutOnRedirects, Clock.DEFAULT, defaultRequestProperties, false);
|
||||
this(
|
||||
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
|
||||
* predicate then an {@link InvalidContentTypeException} is thrown from {@link
|
||||
* #open(DataSpec)}.
|
||||
* @param listener An optional listener.
|
||||
* @param connectTimeoutMs The connection timeout, in milliseconds.
|
||||
* @param readTimeoutMs The read timeout, in milliseconds.
|
||||
* @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,
|
||||
Executor executor,
|
||||
Predicate<String> contentTypePredicate,
|
||||
@Nullable TransferListener listener,
|
||||
int connectTimeoutMs,
|
||||
int readTimeoutMs,
|
||||
boolean resetTimeoutOnRedirects,
|
||||
RequestProperties defaultRequestProperties,
|
||||
boolean handleSetCookieRequests) {
|
||||
this(cronetEngine, executor, contentTypePredicate, listener, connectTimeoutMs,
|
||||
readTimeoutMs, resetTimeoutOnRedirects, Clock.DEFAULT, defaultRequestProperties,
|
||||
this(
|
||||
cronetEngine,
|
||||
executor,
|
||||
contentTypePredicate,
|
||||
connectTimeoutMs,
|
||||
readTimeoutMs,
|
||||
resetTimeoutOnRedirects,
|
||||
Clock.DEFAULT,
|
||||
defaultRequestProperties,
|
||||
handleSetCookieRequests);
|
||||
}
|
||||
|
||||
|
|
@ -233,7 +245,6 @@ public class CronetDataSource extends BaseDataSource implements HttpDataSource {
|
|||
CronetEngine cronetEngine,
|
||||
Executor executor,
|
||||
Predicate<String> contentTypePredicate,
|
||||
@Nullable TransferListener listener,
|
||||
int connectTimeoutMs,
|
||||
int readTimeoutMs,
|
||||
boolean resetTimeoutOnRedirects,
|
||||
|
|
@ -253,9 +264,6 @@ public class CronetDataSource extends BaseDataSource implements HttpDataSource {
|
|||
this.handleSetCookieRequests = handleSetCookieRequests;
|
||||
requestProperties = new RequestProperties();
|
||||
operation = new ConditionVariable();
|
||||
if (listener != null) {
|
||||
addTransferListener(listener);
|
||||
}
|
||||
}
|
||||
|
||||
// HttpDataSource implementation.
|
||||
|
|
|
|||
|
|
@ -335,8 +335,19 @@ public final class CronetDataSourceFactory extends BaseFactory {
|
|||
if (cronetEngine == null) {
|
||||
return fallbackFactory.createDataSource();
|
||||
}
|
||||
return new CronetDataSource(cronetEngine, executor, contentTypePredicate, transferListener,
|
||||
connectTimeoutMs, readTimeoutMs, resetTimeoutOnRedirects, defaultRequestProperties);
|
||||
CronetDataSource dataSource =
|
||||
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,
|
||||
mockExecutor,
|
||||
mockContentTypePredicate,
|
||||
mockTransferListener,
|
||||
TEST_CONNECT_TIMEOUT_MS,
|
||||
TEST_READ_TIMEOUT_MS,
|
||||
true, // resetTimeoutOnRedirects
|
||||
Clock.DEFAULT,
|
||||
null,
|
||||
false);
|
||||
dataSourceUnderTest.addTransferListener(mockTransferListener);
|
||||
when(mockContentTypePredicate.evaluate(anyString())).thenReturn(true);
|
||||
when(mockCronetEngine.newUrlRequestBuilder(
|
||||
anyString(), any(UrlRequest.Callback.class), any(Executor.class)))
|
||||
|
|
@ -723,13 +723,13 @@ public final class CronetDataSourceTest {
|
|||
mockCronetEngine,
|
||||
mockExecutor,
|
||||
mockContentTypePredicate,
|
||||
mockTransferListener,
|
||||
TEST_CONNECT_TIMEOUT_MS,
|
||||
TEST_READ_TIMEOUT_MS,
|
||||
true, // resetTimeoutOnRedirects
|
||||
Clock.DEFAULT,
|
||||
null,
|
||||
true);
|
||||
dataSourceUnderTest.addTransferListener(mockTransferListener);
|
||||
dataSourceUnderTest.setRequestProperty("Content-Type", TEST_CONTENT_TYPE);
|
||||
|
||||
mockSingleRedirectSuccess();
|
||||
|
|
@ -754,13 +754,13 @@ public final class CronetDataSourceTest {
|
|||
mockCronetEngine,
|
||||
mockExecutor,
|
||||
mockContentTypePredicate,
|
||||
mockTransferListener,
|
||||
TEST_CONNECT_TIMEOUT_MS,
|
||||
TEST_READ_TIMEOUT_MS,
|
||||
true, // resetTimeoutOnRedirects
|
||||
Clock.DEFAULT,
|
||||
null,
|
||||
true);
|
||||
dataSourceUnderTest.addTransferListener(mockTransferListener);
|
||||
dataSourceUnderTest.setRequestProperty("Content-Type", TEST_CONTENT_TYPE);
|
||||
|
||||
mockSingleRedirectSuccess();
|
||||
|
|
@ -793,13 +793,13 @@ public final class CronetDataSourceTest {
|
|||
mockCronetEngine,
|
||||
mockExecutor,
|
||||
mockContentTypePredicate,
|
||||
mockTransferListener,
|
||||
TEST_CONNECT_TIMEOUT_MS,
|
||||
TEST_READ_TIMEOUT_MS,
|
||||
true, // resetTimeoutOnRedirects
|
||||
Clock.DEFAULT,
|
||||
null,
|
||||
true);
|
||||
dataSourceUnderTest.addTransferListener(mockTransferListener);
|
||||
mockSingleRedirectSuccess();
|
||||
mockFollowRedirectSuccess();
|
||||
|
||||
|
|
|
|||
|
|
@ -38,12 +38,16 @@ public final class RtmpDataSource extends BaseDataSource {
|
|||
private Uri uri;
|
||||
|
||||
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) {
|
||||
super(/* isNetwork= */ true);
|
||||
this();
|
||||
if (listener != null) {
|
||||
addTransferListener(listener);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -45,20 +45,21 @@ public final class AssetDataSource extends BaseDataSource {
|
|||
private long bytesRemaining;
|
||||
private boolean opened;
|
||||
|
||||
/**
|
||||
* @param context A context.
|
||||
*/
|
||||
/** @param context A context. */
|
||||
public AssetDataSource(Context context) {
|
||||
this(context, null);
|
||||
super(/* isNetwork= */ false);
|
||||
this.assetManager = context.getAssets();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param context A context.
|
||||
* @param listener An optional listener.
|
||||
* @deprecated Use {@link #AssetDataSource(Context)} and {@link
|
||||
* #addTransferListener(TransferListener)}.
|
||||
*/
|
||||
@Deprecated
|
||||
public AssetDataSource(Context context, @Nullable TransferListener listener) {
|
||||
super(/* isNetwork= */ false);
|
||||
this.assetManager = context.getAssets();
|
||||
this(context);
|
||||
if (listener != null) {
|
||||
addTransferListener(listener);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -53,16 +53,19 @@ public final class ContentDataSource extends BaseDataSource {
|
|||
* @param context A context.
|
||||
*/
|
||||
public ContentDataSource(Context context) {
|
||||
this(context, null);
|
||||
super(/* isNetwork= */ false);
|
||||
this.resolver = context.getContentResolver();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param context A context.
|
||||
* @param listener An optional listener.
|
||||
* @deprecated Use {@link #ContentDataSource(Context)} and {@link
|
||||
* #addTransferListener(TransferListener)}.
|
||||
*/
|
||||
@Deprecated
|
||||
public ContentDataSource(Context context, @Nullable TransferListener listener) {
|
||||
super(/* isNetwork= */ false);
|
||||
this.resolver = context.getContentResolver();
|
||||
this(context);
|
||||
if (listener != null) {
|
||||
addTransferListener(listener);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -74,11 +74,74 @@ public final class DefaultDataSource implements DataSource {
|
|||
* 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 string that should be used when requesting remote data.
|
||||
* @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.
|
||||
*/
|
||||
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(
|
||||
Context context,
|
||||
@Nullable TransferListener listener,
|
||||
|
|
@ -93,14 +156,17 @@ public final class DefaultDataSource implements DataSource {
|
|||
*
|
||||
* @param context A context.
|
||||
* @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
|
||||
* 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.
|
||||
* @deprecated Use {@link #DefaultDataSource(Context, String, int, int, boolean)} and {@link
|
||||
* #addTransferListener(TransferListener)}.
|
||||
*/
|
||||
@Deprecated
|
||||
public DefaultDataSource(
|
||||
Context context,
|
||||
@Nullable TransferListener listener,
|
||||
|
|
@ -108,9 +174,17 @@ public final class DefaultDataSource implements DataSource {
|
|||
int connectTimeoutMillis,
|
||||
int readTimeoutMillis,
|
||||
boolean allowCrossProtocolRedirects) {
|
||||
this(context, listener,
|
||||
new DefaultHttpDataSource(userAgent, null, listener, connectTimeoutMillis,
|
||||
readTimeoutMillis, allowCrossProtocolRedirects, null));
|
||||
this(
|
||||
context,
|
||||
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 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).
|
||||
* @deprecated Use {@link #DefaultDataSource(Context, DataSource)} and {@link
|
||||
* #addTransferListener(TransferListener)}.
|
||||
*/
|
||||
@Deprecated
|
||||
public DefaultDataSource(
|
||||
Context context, @Nullable TransferListener listener, DataSource baseDataSource) {
|
||||
this.context = context.getApplicationContext();
|
||||
this.baseDataSource = Assertions.checkNotNull(baseDataSource);
|
||||
transferListeners = new ArrayList<>();
|
||||
this(context, baseDataSource);
|
||||
if (listener != null) {
|
||||
transferListeners.add(listener);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -92,7 +92,67 @@ public class DefaultHttpDataSource extends BaseDataSource implements HttpDataSou
|
|||
* #open(DataSpec)}.
|
||||
*/
|
||||
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
|
||||
* #open(DataSpec)}.
|
||||
* @param listener An optional listener.
|
||||
* @deprecated Use {@link #DefaultHttpDataSource(String, Predicate)} and {@link
|
||||
* #addTransferListener(TransferListener)}.
|
||||
*/
|
||||
@Deprecated
|
||||
public DefaultHttpDataSource(
|
||||
String userAgent,
|
||||
@Nullable Predicate<String> contentTypePredicate,
|
||||
|
|
@ -120,7 +183,10 @@ public class DefaultHttpDataSource extends BaseDataSource implements HttpDataSou
|
|||
* interpreted as an infinite timeout.
|
||||
* @param readTimeoutMillis The read timeout, in milliseconds. A timeout of zero is interpreted as
|
||||
* an infinite timeout.
|
||||
* @deprecated Use {@link #DefaultHttpDataSource(String, Predicate, int, int)} and {@link
|
||||
* #addTransferListener(TransferListener)}.
|
||||
*/
|
||||
@Deprecated
|
||||
public DefaultHttpDataSource(
|
||||
String userAgent,
|
||||
@Nullable Predicate<String> contentTypePredicate,
|
||||
|
|
@ -146,7 +212,10 @@ public class DefaultHttpDataSource extends BaseDataSource implements HttpDataSou
|
|||
* 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.
|
||||
* @deprecated Use {@link #DefaultHttpDataSource(String, Predicate, int, int, boolean,
|
||||
* RequestProperties)} and {@link #addTransferListener(TransferListener)}.
|
||||
*/
|
||||
@Deprecated
|
||||
public DefaultHttpDataSource(
|
||||
String userAgent,
|
||||
@Nullable Predicate<String> contentTypePredicate,
|
||||
|
|
@ -155,14 +224,13 @@ public class DefaultHttpDataSource extends BaseDataSource implements HttpDataSou
|
|||
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;
|
||||
this(
|
||||
userAgent,
|
||||
contentTypePredicate,
|
||||
connectTimeoutMillis,
|
||||
readTimeoutMillis,
|
||||
allowCrossProtocolRedirects,
|
||||
defaultRequestProperties);
|
||||
if (listener != null) {
|
||||
addTransferListener(listener);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -42,12 +42,16 @@ public final class FileDataSource extends BaseDataSource {
|
|||
private boolean opened;
|
||||
|
||||
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) {
|
||||
super(/* isNetwork= */ false);
|
||||
this();
|
||||
if (listener != null) {
|
||||
addTransferListener(listener);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -74,16 +74,19 @@ public final class RawResourceDataSource extends BaseDataSource {
|
|||
* @param context A context.
|
||||
*/
|
||||
public RawResourceDataSource(Context context) {
|
||||
this(context, null);
|
||||
super(/* isNetwork= */ false);
|
||||
this.resources = context.getResources();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param context A context.
|
||||
* @param listener An optional listener.
|
||||
* @deprecated Use {@link #RawResourceDataSource(Context)} and {@link
|
||||
* #addTransferListener(TransferListener)}.
|
||||
*/
|
||||
@Deprecated
|
||||
public RawResourceDataSource(Context context, @Nullable TransferListener listener) {
|
||||
super(/* isNetwork= */ false);
|
||||
this.resources = context.getResources();
|
||||
this(context);
|
||||
if (listener != null) {
|
||||
addTransferListener(listener);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -45,10 +45,8 @@ public final class UdpDataSource extends BaseDataSource {
|
|||
*/
|
||||
public static final int DEFAULT_MAX_PACKET_SIZE = 2000;
|
||||
|
||||
/**
|
||||
* The default socket timeout, in milliseconds.
|
||||
*/
|
||||
public static final int DEAFULT_SOCKET_TIMEOUT_MILLIS = 8 * 1000;
|
||||
/** The default socket timeout, in milliseconds. */
|
||||
public static final int DEFAULT_SOCKET_TIMEOUT_MILLIS = 8 * 1000;
|
||||
|
||||
private final int socketTimeoutMillis;
|
||||
private final byte[] packetBuffer;
|
||||
|
|
@ -63,31 +61,70 @@ public final class UdpDataSource extends BaseDataSource {
|
|||
|
||||
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) {
|
||||
this(listener, DEFAULT_MAX_PACKET_SIZE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new instance.
|
||||
*
|
||||
* @param listener An optional listener.
|
||||
* @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) {
|
||||
this(listener, maxPacketSize, DEAFULT_SOCKET_TIMEOUT_MILLIS);
|
||||
this(listener, maxPacketSize, DEFAULT_SOCKET_TIMEOUT_MILLIS);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new instance.
|
||||
*
|
||||
* @param listener An optional listener.
|
||||
* @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.
|
||||
* @deprecated Use {@link #UdpDataSource(int, int)} and {@link
|
||||
* #addTransferListener(TransferListener)}.
|
||||
*/
|
||||
@Deprecated
|
||||
public UdpDataSource(
|
||||
@Nullable TransferListener listener, int maxPacketSize, int socketTimeoutMillis) {
|
||||
super(/* isNetwork= */ true);
|
||||
this.socketTimeoutMillis = socketTimeoutMillis;
|
||||
packetBuffer = new byte[maxPacketSize];
|
||||
packet = new DatagramPacket(packetBuffer, 0, maxPacketSize);
|
||||
this(maxPacketSize, socketTimeoutMillis);
|
||||
if (listener != null) {
|
||||
addTransferListener(listener);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -60,7 +60,11 @@ public class FakeDataSource extends BaseDataSource {
|
|||
|
||||
@Override
|
||||
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) {
|
||||
this(fakeDataSet, null, /* isNetwork= */ false);
|
||||
this(fakeDataSet, /* isNetwork= */ false);
|
||||
}
|
||||
|
||||
public FakeDataSource(
|
||||
FakeDataSet fakeDataSet, @Nullable TransferListener transferListener, boolean isNetwork) {
|
||||
public FakeDataSource(FakeDataSet fakeDataSet, boolean isNetwork) {
|
||||
super(isNetwork);
|
||||
Assertions.checkNotNull(fakeDataSet);
|
||||
this.fakeDataSet = fakeDataSet;
|
||||
this.openedDataSpecs = new ArrayList<>();
|
||||
if (transferListener != null) {
|
||||
addTransferListener(transferListener);
|
||||
}
|
||||
}
|
||||
|
||||
public final FakeDataSet getDataSet() {
|
||||
|
|
|
|||
Loading…
Reference in a new issue