mirror of
https://github.com/samsonjs/media.git
synced 2026-03-27 09:45:47 +00:00
Add NonNull annotations to upstream
PiperOrigin-RevId: 284771928
This commit is contained in:
parent
5da510cf00
commit
5cee5cba30
11 changed files with 54 additions and 37 deletions
|
|
@ -15,7 +15,6 @@
|
|||
*/
|
||||
package com.google.android.exoplayer2.upstream;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import com.google.android.exoplayer2.C;
|
||||
import com.google.android.exoplayer2.util.Assertions;
|
||||
import java.io.IOException;
|
||||
|
|
@ -72,12 +71,12 @@ public final class DataSourceInputStream extends InputStream {
|
|||
}
|
||||
|
||||
@Override
|
||||
public int read(@NonNull byte[] buffer) throws IOException {
|
||||
public int read(byte[] buffer) throws IOException {
|
||||
return read(buffer, 0, buffer.length);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int read(@NonNull byte[] buffer, int offset, int length) throws IOException {
|
||||
public int read(byte[] buffer, int offset, int length) throws IOException {
|
||||
Assertions.checkState(!closed);
|
||||
checkOpened();
|
||||
int bytesRead = dataSource.read(buffer, offset, length);
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@
|
|||
*/
|
||||
package com.google.android.exoplayer2.upstream;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import com.google.android.exoplayer2.util.Assertions;
|
||||
import com.google.android.exoplayer2.util.Util;
|
||||
import java.util.Arrays;
|
||||
|
|
@ -28,7 +29,7 @@ public final class DefaultAllocator implements Allocator {
|
|||
|
||||
private final boolean trimOnReset;
|
||||
private final int individualAllocationSize;
|
||||
private final byte[] initialAllocationBlock;
|
||||
@Nullable private final byte[] initialAllocationBlock;
|
||||
private final Allocation[] singleAllocationReleaseHolder;
|
||||
|
||||
private int targetBufferSize;
|
||||
|
|
|
|||
|
|
@ -210,7 +210,7 @@ public final class DefaultBandwidthMeter implements BandwidthMeter, TransferList
|
|||
}
|
||||
|
||||
private static int[] getCountryGroupIndices(String countryCode) {
|
||||
int[] groupIndices = DEFAULT_INITIAL_BITRATE_COUNTRY_GROUPS.get(countryCode);
|
||||
@Nullable int[] groupIndices = DEFAULT_INITIAL_BITRATE_COUNTRY_GROUPS.get(countryCode);
|
||||
// Assume median group if not found.
|
||||
return groupIndices == null ? new int[] {2, 2, 2, 2} : groupIndices;
|
||||
}
|
||||
|
|
@ -304,7 +304,6 @@ public final class DefaultBandwidthMeter implements BandwidthMeter, TransferList
|
|||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public TransferListener getTransferListener() {
|
||||
return this;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -386,7 +386,8 @@ public class DefaultHttpDataSource extends BaseDataSource implements HttpDataSou
|
|||
*
|
||||
* @return The current open connection, or null.
|
||||
*/
|
||||
protected final @Nullable HttpURLConnection getConnection() {
|
||||
@Nullable
|
||||
protected final HttpURLConnection getConnection() {
|
||||
return connection;
|
||||
}
|
||||
|
||||
|
|
@ -428,7 +429,7 @@ public class DefaultHttpDataSource extends BaseDataSource implements HttpDataSou
|
|||
private HttpURLConnection makeConnection(DataSpec dataSpec) throws IOException {
|
||||
URL url = new URL(dataSpec.uri.toString());
|
||||
@HttpMethod int httpMethod = dataSpec.httpMethod;
|
||||
byte[] httpBody = dataSpec.httpBody;
|
||||
@Nullable byte[] httpBody = dataSpec.httpBody;
|
||||
long position = dataSpec.position;
|
||||
long length = dataSpec.length;
|
||||
boolean allowGzip = dataSpec.isFlagSet(DataSpec.FLAG_ALLOW_GZIP);
|
||||
|
|
@ -495,7 +496,7 @@ public class DefaultHttpDataSource extends BaseDataSource implements HttpDataSou
|
|||
*
|
||||
* @param url The url to connect to.
|
||||
* @param httpMethod The http method.
|
||||
* @param httpBody The body data.
|
||||
* @param httpBody The body data, or {@code null} if not required.
|
||||
* @param position The byte offset of the requested data.
|
||||
* @param length The length of the requested data, or {@link C#LENGTH_UNSET}.
|
||||
* @param allowGzip Whether to allow the use of gzip.
|
||||
|
|
@ -505,7 +506,7 @@ public class DefaultHttpDataSource extends BaseDataSource implements HttpDataSou
|
|||
private HttpURLConnection makeConnection(
|
||||
URL url,
|
||||
@HttpMethod int httpMethod,
|
||||
byte[] httpBody,
|
||||
@Nullable byte[] httpBody,
|
||||
long position,
|
||||
long length,
|
||||
boolean allowGzip,
|
||||
|
|
@ -562,11 +563,11 @@ public class DefaultHttpDataSource extends BaseDataSource implements HttpDataSou
|
|||
* Handles a redirect.
|
||||
*
|
||||
* @param originalUrl The original URL.
|
||||
* @param location The Location header in the response.
|
||||
* @param location The Location header in the response. May be {@code null}.
|
||||
* @return The next URL.
|
||||
* @throws IOException If redirection isn't possible.
|
||||
*/
|
||||
private static URL handleRedirect(URL originalUrl, String location) throws IOException {
|
||||
private static URL handleRedirect(URL originalUrl, @Nullable String location) throws IOException {
|
||||
if (location == null) {
|
||||
throw new ProtocolException("Null location redirect");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -86,7 +86,6 @@ public final class FileDataSource extends BaseDataSource {
|
|||
transferInitializing(dataSpec);
|
||||
|
||||
this.file = openLocalFile(uri);
|
||||
|
||||
file.seek(dataSpec.position);
|
||||
bytesRemaining = dataSpec.length == C.LENGTH_UNSET ? file.length() - dataSpec.position
|
||||
: dataSpec.length;
|
||||
|
|
@ -103,23 +102,6 @@ public final class FileDataSource extends BaseDataSource {
|
|||
return bytesRemaining;
|
||||
}
|
||||
|
||||
private static RandomAccessFile openLocalFile(Uri uri) throws FileDataSourceException {
|
||||
try {
|
||||
return new RandomAccessFile(Assertions.checkNotNull(uri.getPath()), "r");
|
||||
} catch (FileNotFoundException e) {
|
||||
if (!TextUtils.isEmpty(uri.getQuery()) || !TextUtils.isEmpty(uri.getFragment())) {
|
||||
throw new FileDataSourceException(
|
||||
String.format(
|
||||
"uri has query and/or fragment, which are not supported. Did you call Uri.parse()"
|
||||
+ " on a string containing '?' or '#'? Use Uri.fromFile(new File(path)) to"
|
||||
+ " avoid this. path=%s,query=%s,fragment=%s",
|
||||
uri.getPath(), uri.getQuery(), uri.getFragment()),
|
||||
e);
|
||||
}
|
||||
throw new FileDataSourceException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int read(byte[] buffer, int offset, int readLength) throws FileDataSourceException {
|
||||
if (readLength == 0) {
|
||||
|
|
@ -168,4 +150,20 @@ public final class FileDataSource extends BaseDataSource {
|
|||
}
|
||||
}
|
||||
|
||||
private static RandomAccessFile openLocalFile(Uri uri) throws FileDataSourceException {
|
||||
try {
|
||||
return new RandomAccessFile(Assertions.checkNotNull(uri.getPath()), "r");
|
||||
} catch (FileNotFoundException e) {
|
||||
if (!TextUtils.isEmpty(uri.getQuery()) || !TextUtils.isEmpty(uri.getFragment())) {
|
||||
throw new FileDataSourceException(
|
||||
String.format(
|
||||
"uri has query and/or fragment, which are not supported. Did you call Uri.parse()"
|
||||
+ " on a string containing '?' or '#'? Use Uri.fromFile(new File(path)) to"
|
||||
+ " avoid this. path=%s,query=%s,fragment=%s",
|
||||
uri.getPath(), uri.getQuery(), uri.getFragment()),
|
||||
e);
|
||||
}
|
||||
throw new FileDataSourceException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -89,7 +89,7 @@ public interface HttpDataSource extends DataSource {
|
|||
final class RequestProperties {
|
||||
|
||||
private final Map<String, String> requestProperties;
|
||||
private Map<String, String> requestPropertiesSnapshot;
|
||||
@Nullable private Map<String, String> requestPropertiesSnapshot;
|
||||
|
||||
public RequestProperties() {
|
||||
requestProperties = new HashMap<>();
|
||||
|
|
|
|||
|
|
@ -363,7 +363,7 @@ public final class Loader implements LoaderErrorThrower {
|
|||
} else {
|
||||
canceled = true;
|
||||
loadable.cancelLoad();
|
||||
Thread executorThread = this.executorThread;
|
||||
@Nullable Thread executorThread = this.executorThread;
|
||||
if (executorThread != null) {
|
||||
executorThread.interrupt();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -49,15 +49,14 @@ public interface LoaderErrorThrower {
|
|||
final class Dummy implements LoaderErrorThrower {
|
||||
|
||||
@Override
|
||||
public void maybeThrowError() throws IOException {
|
||||
public void maybeThrowError() {
|
||||
// Do nothing.
|
||||
}
|
||||
|
||||
@Override
|
||||
public void maybeThrowError(int minRetryCount) throws IOException {
|
||||
public void maybeThrowError(int minRetryCount) {
|
||||
// Do nothing.
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -127,7 +127,8 @@ public final class ParsingLoadable<T> implements Loadable {
|
|||
}
|
||||
|
||||
/** Returns the loaded object, or null if an object has not been loaded. */
|
||||
public final @Nullable T getResult() {
|
||||
@Nullable
|
||||
public final T getResult() {
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -113,7 +113,7 @@ public final class ResolvingDataSource implements DataSource {
|
|||
@Nullable
|
||||
@Override
|
||||
public Uri getUri() {
|
||||
Uri reportedUri = upstreamDataSource.getUri();
|
||||
@Nullable Uri reportedUri = upstreamDataSource.getUri();
|
||||
return reportedUri == null ? null : resolver.resolveReportedUri(reportedUri);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,19 @@
|
|||
/*
|
||||
* Copyright (C) 2019 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
@NonNullApi
|
||||
package com.google.android.exoplayer2.upstream;
|
||||
|
||||
import com.google.android.exoplayer2.util.NonNullApi;
|
||||
Loading…
Reference in a new issue