Remove some deprecated DataSpec
constructors
PiperOrigin-RevId: 613137809
This commit is contained in:
parent
f8c407cfb6
commit
b1b8b2e6f9
@ -89,6 +89,7 @@
|
||||
* Remove deprecated symbols:
|
||||
* Remove `CronetDataSourceFactory`. Use `CronetDataSource.Factory`
|
||||
instead.
|
||||
* Remove some `DataSpec` constructors. Use `DataSpec.Builder` instead.
|
||||
|
||||
## 1.3
|
||||
|
||||
|
@ -427,232 +427,36 @@ public final class DataSpec {
|
||||
* @param position {@link #position}.
|
||||
* @param length {@link #length}.
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
public DataSpec(Uri uri, long position, long length) {
|
||||
this(uri, position, length, /* key= */ null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs an instance.
|
||||
*
|
||||
* @deprecated Use {@link Builder}.
|
||||
* @param uri {@link #uri}.
|
||||
* @param position {@link #position}.
|
||||
* @param length {@link #length}.
|
||||
* @param key {@link #key}.
|
||||
*/
|
||||
@Deprecated
|
||||
public DataSpec(Uri uri, long position, long length, @Nullable String key) {
|
||||
this(
|
||||
uri,
|
||||
/* uriPositionOffset= */ 0,
|
||||
HTTP_METHOD_GET,
|
||||
/* httpBody= */ null,
|
||||
/* httpRequestHeaders= */ Collections.emptyMap(),
|
||||
null,
|
||||
Collections.emptyMap(),
|
||||
position,
|
||||
length,
|
||||
/* key= */ null,
|
||||
/* flags= */ 0,
|
||||
key,
|
||||
0,
|
||||
/* customData= */ null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs an instance.
|
||||
*
|
||||
* @deprecated Use {@link Builder}.
|
||||
* @param uri {@link #uri}.
|
||||
* @param flags {@link #flags}.
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
@Deprecated
|
||||
public DataSpec(Uri uri, @Flags int flags) {
|
||||
this(uri, /* position= */ 0, C.LENGTH_UNSET, /* key= */ null, flags);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs an instance.
|
||||
*
|
||||
* @deprecated Use {@link Builder}.
|
||||
* @param uri {@link #uri}.
|
||||
* @param position {@link #position}.
|
||||
* @param length {@link #length}.
|
||||
* @param key {@link #key}.
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
@Deprecated
|
||||
public DataSpec(Uri uri, long position, long length, @Nullable String key) {
|
||||
this(uri, position, position, length, key, /* flags= */ 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs an instance.
|
||||
*
|
||||
* @deprecated Use {@link Builder}.
|
||||
* @param uri {@link #uri}.
|
||||
* @param position {@link #position}.
|
||||
* @param length {@link #length}.
|
||||
* @param key {@link #key}.
|
||||
* @param flags {@link #flags}.
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
@Deprecated
|
||||
public DataSpec(Uri uri, long position, long length, @Nullable String key, @Flags int flags) {
|
||||
this(uri, position, position, length, key, flags);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs an instance.
|
||||
*
|
||||
* @deprecated Use {@link Builder}.
|
||||
* @param uri {@link #uri}.
|
||||
* @param position {@link #position}, equal to {@link #position}.
|
||||
* @param length {@link #length}.
|
||||
* @param key {@link #key}.
|
||||
* @param flags {@link #flags}.
|
||||
* @param httpRequestHeaders {@link #httpRequestHeaders}
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
@Deprecated
|
||||
public DataSpec(
|
||||
Uri uri,
|
||||
long position,
|
||||
long length,
|
||||
@Nullable String key,
|
||||
@Flags int flags,
|
||||
Map<String, String> httpRequestHeaders) {
|
||||
this(
|
||||
uri,
|
||||
HTTP_METHOD_GET,
|
||||
/* httpBody= */ null,
|
||||
position,
|
||||
position,
|
||||
length,
|
||||
key,
|
||||
flags,
|
||||
httpRequestHeaders);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs an instance where {@link #uriPositionOffset} may be non-zero.
|
||||
*
|
||||
* @deprecated Use {@link Builder}.
|
||||
* @param uri {@link #uri}.
|
||||
* @param absoluteStreamPosition The sum of {@link #uriPositionOffset} and {@link #position}.
|
||||
* @param position {@link #position}.
|
||||
* @param length {@link #length}.
|
||||
* @param key {@link #key}.
|
||||
* @param flags {@link #flags}.
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
@Deprecated
|
||||
public DataSpec(
|
||||
Uri uri,
|
||||
long absoluteStreamPosition,
|
||||
long position,
|
||||
long length,
|
||||
@Nullable String key,
|
||||
@Flags int flags) {
|
||||
this(uri, /* postBody= */ null, absoluteStreamPosition, position, length, key, flags);
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a instance where {@link #uriPositionOffset} may be non-zero. The {@link #httpMethod}
|
||||
* is inferred from {@code postBody}. If {@code postBody} is non-null then {@link #httpMethod} is
|
||||
* set to {@link #HTTP_METHOD_POST}. If {@code postBody} is null then {@link #httpMethod} is set
|
||||
* to {@link #HTTP_METHOD_GET}.
|
||||
*
|
||||
* @deprecated Use {@link Builder}. Note that the httpMethod must be set explicitly for the
|
||||
* Builder.
|
||||
* @param uri {@link #uri}.
|
||||
* @param postBody {@link #httpBody} The body of the HTTP request, which is also used to infer the
|
||||
* {@link #httpMethod}.
|
||||
* @param absoluteStreamPosition The sum of {@link #uriPositionOffset} and {@link #position}.
|
||||
* @param position {@link #position}.
|
||||
* @param length {@link #length}.
|
||||
* @param key {@link #key}.
|
||||
* @param flags {@link #flags}.
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
@Deprecated
|
||||
public DataSpec(
|
||||
Uri uri,
|
||||
@Nullable byte[] postBody,
|
||||
long absoluteStreamPosition,
|
||||
long position,
|
||||
long length,
|
||||
@Nullable String key,
|
||||
@Flags int flags) {
|
||||
this(
|
||||
uri,
|
||||
/* httpMethod= */ postBody != null ? HTTP_METHOD_POST : HTTP_METHOD_GET,
|
||||
/* httpBody= */ postBody,
|
||||
absoluteStreamPosition,
|
||||
position,
|
||||
length,
|
||||
key,
|
||||
flags);
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a instance where {@link #uriPositionOffset} may be non-zero.
|
||||
*
|
||||
* @deprecated Use {@link Builder}.
|
||||
* @param uri {@link #uri}.
|
||||
* @param httpMethod {@link #httpMethod}.
|
||||
* @param httpBody {@link #httpBody}.
|
||||
* @param absoluteStreamPosition The sum of {@link #uriPositionOffset} and {@link #position}.
|
||||
* @param position {@link #position}.
|
||||
* @param length {@link #length}.
|
||||
* @param key {@link #key}.
|
||||
* @param flags {@link #flags}.
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
@Deprecated
|
||||
public DataSpec(
|
||||
Uri uri,
|
||||
@HttpMethod int httpMethod,
|
||||
@Nullable byte[] httpBody,
|
||||
long absoluteStreamPosition,
|
||||
long position,
|
||||
long length,
|
||||
@Nullable String key,
|
||||
@Flags int flags) {
|
||||
this(
|
||||
uri,
|
||||
httpMethod,
|
||||
httpBody,
|
||||
absoluteStreamPosition,
|
||||
position,
|
||||
length,
|
||||
key,
|
||||
flags,
|
||||
/* httpRequestHeaders= */ Collections.emptyMap());
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a instance where {@link #uriPositionOffset} may be non-zero.
|
||||
*
|
||||
* @deprecated Use {@link Builder}.
|
||||
* @param uri {@link #uri}.
|
||||
* @param httpMethod {@link #httpMethod}.
|
||||
* @param httpBody {@link #httpBody}.
|
||||
* @param absoluteStreamPosition The sum of {@link #uriPositionOffset} and {@link #position}.
|
||||
* @param position {@link #position}.
|
||||
* @param length {@link #length}.
|
||||
* @param key {@link #key}.
|
||||
* @param flags {@link #flags}.
|
||||
* @param httpRequestHeaders {@link #httpRequestHeaders}.
|
||||
*/
|
||||
@Deprecated
|
||||
public DataSpec(
|
||||
Uri uri,
|
||||
@HttpMethod int httpMethod,
|
||||
@Nullable byte[] httpBody,
|
||||
long absoluteStreamPosition,
|
||||
long position,
|
||||
long length,
|
||||
@Nullable String key,
|
||||
@Flags int flags,
|
||||
Map<String, String> httpRequestHeaders) {
|
||||
this(
|
||||
uri,
|
||||
/* uriPositionOffset= */ absoluteStreamPosition - position,
|
||||
httpMethod,
|
||||
httpBody,
|
||||
httpRequestHeaders,
|
||||
position,
|
||||
length,
|
||||
key,
|
||||
flags,
|
||||
/* customData= */ null);
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@SuppressWarnings("deprecation") // Setting deprecated absoluteStreamPosition field.
|
||||
private DataSpec(
|
||||
Uri uri,
|
||||
long uriPositionOffset,
|
||||
|
@ -20,7 +20,6 @@ import static com.google.common.truth.Truth.assertThat;
|
||||
import static junit.framework.TestCase.fail;
|
||||
|
||||
import android.net.Uri;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.media3.common.C;
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||
import java.util.HashMap;
|
||||
@ -40,60 +39,8 @@ public class DataSpecTest {
|
||||
DataSpec dataSpec = new DataSpec(uri);
|
||||
assertDefaultDataSpec(dataSpec, uri);
|
||||
|
||||
dataSpec = new DataSpec(uri, /* flags= */ 0);
|
||||
assertDefaultDataSpec(dataSpec, uri);
|
||||
|
||||
dataSpec = new DataSpec(uri, /* position= */ 0, C.LENGTH_UNSET, /* key= */ null);
|
||||
assertDefaultDataSpec(dataSpec, uri);
|
||||
|
||||
dataSpec =
|
||||
new DataSpec(uri, /* position= */ 0, C.LENGTH_UNSET, /* key= */ null, /* flags= */ 0);
|
||||
assertDefaultDataSpec(dataSpec, uri);
|
||||
|
||||
dataSpec =
|
||||
new DataSpec(
|
||||
uri,
|
||||
/* position= */ 0,
|
||||
/* length= */ C.LENGTH_UNSET,
|
||||
/* key= */ null,
|
||||
/* flags= */ 0,
|
||||
new HashMap<>());
|
||||
assertDefaultDataSpec(dataSpec, uri);
|
||||
|
||||
dataSpec =
|
||||
new DataSpec(
|
||||
uri,
|
||||
/* absoluteStreamPosition= */ 0,
|
||||
/* position= */ 0,
|
||||
/* length= */ C.LENGTH_UNSET,
|
||||
null,
|
||||
/* flags= */ 0);
|
||||
assertDefaultDataSpec(dataSpec, uri);
|
||||
|
||||
dataSpec =
|
||||
new DataSpec(
|
||||
uri,
|
||||
DataSpec.HTTP_METHOD_GET,
|
||||
/* httpBody= */ null,
|
||||
/* absoluteStreamPosition= */ 0,
|
||||
/* position= */ 0,
|
||||
/* length= */ C.LENGTH_UNSET,
|
||||
/* key= */ null,
|
||||
/* flags= */ 0);
|
||||
assertDefaultDataSpec(dataSpec, uri);
|
||||
|
||||
dataSpec =
|
||||
new DataSpec(
|
||||
uri,
|
||||
DataSpec.HTTP_METHOD_GET,
|
||||
/* httpBody= */ null,
|
||||
/* absoluteStreamPosition= */ 0,
|
||||
/* position= */ 0,
|
||||
/* length= */ C.LENGTH_UNSET,
|
||||
/* key= */ null,
|
||||
/* flags= */ 0,
|
||||
new HashMap<>());
|
||||
assertDefaultDataSpec(dataSpec, uri);
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -106,34 +53,22 @@ public class DataSpecTest {
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Test
|
||||
public void createDataSpec_setsValues() {
|
||||
public void createDataSpec_deprecatedConstructor_setsSomeValues() {
|
||||
Uri uri = Uri.parse("www.google.com");
|
||||
Map<String, String> httpRequestHeaders = createHttpRequestHeaders(3);
|
||||
byte[] httpBody = new byte[] {0, 1, 2, 3};
|
||||
|
||||
DataSpec dataSpec =
|
||||
new DataSpec(
|
||||
uri,
|
||||
DataSpec.HTTP_METHOD_POST,
|
||||
httpBody,
|
||||
/* absoluteStreamPosition= */ 200,
|
||||
/* position= */ 150,
|
||||
/* length= */ 5,
|
||||
/* key= */ "key",
|
||||
/* flags= */ DataSpec.FLAG_ALLOW_GZIP,
|
||||
httpRequestHeaders);
|
||||
DataSpec dataSpec = new DataSpec(uri, /* position= */ 150, /* length= */ 5, /* key= */ "key");
|
||||
|
||||
assertThat(dataSpec.uri).isEqualTo(uri);
|
||||
// uriPositionOffset = absoluteStreamPosition - position
|
||||
assertThat(dataSpec.uriPositionOffset).isEqualTo(50);
|
||||
assertThat(dataSpec.httpMethod).isEqualTo(DataSpec.HTTP_METHOD_POST);
|
||||
assertThat(dataSpec.httpBody).isEqualTo(httpBody);
|
||||
assertThat(dataSpec.httpRequestHeaders).isEqualTo(httpRequestHeaders);
|
||||
assertThat(dataSpec.absoluteStreamPosition).isEqualTo(200);
|
||||
assertThat(dataSpec.httpMethod).isEqualTo(DataSpec.HTTP_METHOD_GET);
|
||||
assertThat(dataSpec.httpBody).isNull();
|
||||
assertThat(dataSpec.httpRequestHeaders).isEmpty();
|
||||
assertThat(dataSpec.absoluteStreamPosition).isEqualTo(150);
|
||||
assertThat(dataSpec.position).isEqualTo(150);
|
||||
// uriPositionOffset = absoluteStreamPosition - position
|
||||
assertThat(dataSpec.uriPositionOffset).isEqualTo(0);
|
||||
assertThat(dataSpec.length).isEqualTo(5);
|
||||
assertThat(dataSpec.key).isEqualTo("key");
|
||||
assertThat(dataSpec.flags).isEqualTo(DataSpec.FLAG_ALLOW_GZIP);
|
||||
assertThat(dataSpec.flags).isEqualTo(0);
|
||||
assertHttpRequestHeadersReadOnly(dataSpec);
|
||||
}
|
||||
|
||||
@ -214,51 +149,6 @@ public class DataSpecTest {
|
||||
assertHttpRequestHeadersReadOnly(dataSpec);
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Test
|
||||
public void createDataSpec_setsHttpMethodAndPostBody() {
|
||||
Uri uri = Uri.parse("www.google.com");
|
||||
|
||||
@Nullable byte[] postBody = new byte[] {0, 1, 2, 3};
|
||||
DataSpec dataSpec =
|
||||
new DataSpec(
|
||||
uri,
|
||||
postBody,
|
||||
/* absoluteStreamPosition= */ 0,
|
||||
/* position= */ 0,
|
||||
/* length= */ C.LENGTH_UNSET,
|
||||
/* key= */ null,
|
||||
/* flags= */ 0);
|
||||
assertThat(dataSpec.httpMethod).isEqualTo(DataSpec.HTTP_METHOD_POST);
|
||||
assertThat(dataSpec.httpBody).isEqualTo(postBody);
|
||||
|
||||
postBody = new byte[0];
|
||||
dataSpec =
|
||||
new DataSpec(
|
||||
uri,
|
||||
postBody,
|
||||
/* absoluteStreamPosition= */ 0,
|
||||
/* position= */ 0,
|
||||
/* length= */ C.LENGTH_UNSET,
|
||||
/* key= */ null,
|
||||
/* flags= */ 0);
|
||||
assertThat(dataSpec.httpMethod).isEqualTo(DataSpec.HTTP_METHOD_POST);
|
||||
assertThat(dataSpec.httpBody).isNull();
|
||||
|
||||
postBody = null;
|
||||
dataSpec =
|
||||
new DataSpec(
|
||||
uri,
|
||||
postBody,
|
||||
/* absoluteStreamPosition= */ 0,
|
||||
/* position= */ 0,
|
||||
/* length= */ C.LENGTH_UNSET,
|
||||
/* key= */ null,
|
||||
/* flags= */ 0);
|
||||
assertThat(dataSpec.httpMethod).isEqualTo(DataSpec.HTTP_METHOD_GET);
|
||||
assertThat(dataSpec.httpBody).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void withUri_copiesHttpRequestHeaders() {
|
||||
Map<String, String> httpRequestHeaders = createHttpRequestHeaders(5);
|
||||
|
Loading…
x
Reference in New Issue
Block a user