Commit 5cee5cba by olly Committed by Oliver Woodman

Add NonNull annotations to upstream

PiperOrigin-RevId: 284771928
parent 5da510cf
...@@ -15,7 +15,6 @@ ...@@ -15,7 +15,6 @@
*/ */
package com.google.android.exoplayer2.upstream; package com.google.android.exoplayer2.upstream;
import androidx.annotation.NonNull;
import com.google.android.exoplayer2.C; import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.util.Assertions; import com.google.android.exoplayer2.util.Assertions;
import java.io.IOException; import java.io.IOException;
...@@ -72,12 +71,12 @@ public final class DataSourceInputStream extends InputStream { ...@@ -72,12 +71,12 @@ public final class DataSourceInputStream extends InputStream {
} }
@Override @Override
public int read(@NonNull byte[] buffer) throws IOException { public int read(byte[] buffer) throws IOException {
return read(buffer, 0, buffer.length); return read(buffer, 0, buffer.length);
} }
@Override @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); Assertions.checkState(!closed);
checkOpened(); checkOpened();
int bytesRead = dataSource.read(buffer, offset, length); int bytesRead = dataSource.read(buffer, offset, length);
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
*/ */
package com.google.android.exoplayer2.upstream; package com.google.android.exoplayer2.upstream;
import androidx.annotation.Nullable;
import com.google.android.exoplayer2.util.Assertions; import com.google.android.exoplayer2.util.Assertions;
import com.google.android.exoplayer2.util.Util; import com.google.android.exoplayer2.util.Util;
import java.util.Arrays; import java.util.Arrays;
...@@ -28,7 +29,7 @@ public final class DefaultAllocator implements Allocator { ...@@ -28,7 +29,7 @@ public final class DefaultAllocator implements Allocator {
private final boolean trimOnReset; private final boolean trimOnReset;
private final int individualAllocationSize; private final int individualAllocationSize;
private final byte[] initialAllocationBlock; @Nullable private final byte[] initialAllocationBlock;
private final Allocation[] singleAllocationReleaseHolder; private final Allocation[] singleAllocationReleaseHolder;
private int targetBufferSize; private int targetBufferSize;
......
...@@ -210,7 +210,7 @@ public final class DefaultBandwidthMeter implements BandwidthMeter, TransferList ...@@ -210,7 +210,7 @@ public final class DefaultBandwidthMeter implements BandwidthMeter, TransferList
} }
private static int[] getCountryGroupIndices(String countryCode) { 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. // Assume median group if not found.
return groupIndices == null ? new int[] {2, 2, 2, 2} : groupIndices; return groupIndices == null ? new int[] {2, 2, 2, 2} : groupIndices;
} }
...@@ -304,7 +304,6 @@ public final class DefaultBandwidthMeter implements BandwidthMeter, TransferList ...@@ -304,7 +304,6 @@ public final class DefaultBandwidthMeter implements BandwidthMeter, TransferList
} }
@Override @Override
@Nullable
public TransferListener getTransferListener() { public TransferListener getTransferListener() {
return this; return this;
} }
......
...@@ -386,7 +386,8 @@ public class DefaultHttpDataSource extends BaseDataSource implements HttpDataSou ...@@ -386,7 +386,8 @@ public class DefaultHttpDataSource extends BaseDataSource implements HttpDataSou
* *
* @return The current open connection, or null. * @return The current open connection, or null.
*/ */
protected final @Nullable HttpURLConnection getConnection() { @Nullable
protected final HttpURLConnection getConnection() {
return connection; return connection;
} }
...@@ -428,7 +429,7 @@ public class DefaultHttpDataSource extends BaseDataSource implements HttpDataSou ...@@ -428,7 +429,7 @@ public class DefaultHttpDataSource extends BaseDataSource implements HttpDataSou
private HttpURLConnection makeConnection(DataSpec dataSpec) throws IOException { private HttpURLConnection makeConnection(DataSpec dataSpec) throws IOException {
URL url = new URL(dataSpec.uri.toString()); URL url = new URL(dataSpec.uri.toString());
@HttpMethod int httpMethod = dataSpec.httpMethod; @HttpMethod int httpMethod = dataSpec.httpMethod;
byte[] httpBody = dataSpec.httpBody; @Nullable byte[] httpBody = dataSpec.httpBody;
long position = dataSpec.position; long position = dataSpec.position;
long length = dataSpec.length; long length = dataSpec.length;
boolean allowGzip = dataSpec.isFlagSet(DataSpec.FLAG_ALLOW_GZIP); boolean allowGzip = dataSpec.isFlagSet(DataSpec.FLAG_ALLOW_GZIP);
...@@ -495,7 +496,7 @@ public class DefaultHttpDataSource extends BaseDataSource implements HttpDataSou ...@@ -495,7 +496,7 @@ public class DefaultHttpDataSource extends BaseDataSource implements HttpDataSou
* *
* @param url The url to connect to. * @param url The url to connect to.
* @param httpMethod The http method. * @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 position The byte offset of the requested data.
* @param length The length of the requested data, or {@link C#LENGTH_UNSET}. * @param length The length of the requested data, or {@link C#LENGTH_UNSET}.
* @param allowGzip Whether to allow the use of gzip. * @param allowGzip Whether to allow the use of gzip.
...@@ -505,7 +506,7 @@ public class DefaultHttpDataSource extends BaseDataSource implements HttpDataSou ...@@ -505,7 +506,7 @@ public class DefaultHttpDataSource extends BaseDataSource implements HttpDataSou
private HttpURLConnection makeConnection( private HttpURLConnection makeConnection(
URL url, URL url,
@HttpMethod int httpMethod, @HttpMethod int httpMethod,
byte[] httpBody, @Nullable byte[] httpBody,
long position, long position,
long length, long length,
boolean allowGzip, boolean allowGzip,
...@@ -562,11 +563,11 @@ public class DefaultHttpDataSource extends BaseDataSource implements HttpDataSou ...@@ -562,11 +563,11 @@ public class DefaultHttpDataSource extends BaseDataSource implements HttpDataSou
* Handles a redirect. * Handles a redirect.
* *
* @param originalUrl The original URL. * @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. * @return The next URL.
* @throws IOException If redirection isn't possible. * @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) { if (location == null) {
throw new ProtocolException("Null location redirect"); throw new ProtocolException("Null location redirect");
} }
......
...@@ -86,7 +86,6 @@ public final class FileDataSource extends BaseDataSource { ...@@ -86,7 +86,6 @@ public final class FileDataSource extends BaseDataSource {
transferInitializing(dataSpec); transferInitializing(dataSpec);
this.file = openLocalFile(uri); this.file = openLocalFile(uri);
file.seek(dataSpec.position); file.seek(dataSpec.position);
bytesRemaining = dataSpec.length == C.LENGTH_UNSET ? file.length() - dataSpec.position bytesRemaining = dataSpec.length == C.LENGTH_UNSET ? file.length() - dataSpec.position
: dataSpec.length; : dataSpec.length;
...@@ -103,23 +102,6 @@ public final class FileDataSource extends BaseDataSource { ...@@ -103,23 +102,6 @@ public final class FileDataSource extends BaseDataSource {
return bytesRemaining; 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 @Override
public int read(byte[] buffer, int offset, int readLength) throws FileDataSourceException { public int read(byte[] buffer, int offset, int readLength) throws FileDataSourceException {
if (readLength == 0) { if (readLength == 0) {
...@@ -168,4 +150,20 @@ public final class FileDataSource extends BaseDataSource { ...@@ -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 { ...@@ -89,7 +89,7 @@ public interface HttpDataSource extends DataSource {
final class RequestProperties { final class RequestProperties {
private final Map<String, String> requestProperties; private final Map<String, String> requestProperties;
private Map<String, String> requestPropertiesSnapshot; @Nullable private Map<String, String> requestPropertiesSnapshot;
public RequestProperties() { public RequestProperties() {
requestProperties = new HashMap<>(); requestProperties = new HashMap<>();
......
...@@ -363,7 +363,7 @@ public final class Loader implements LoaderErrorThrower { ...@@ -363,7 +363,7 @@ public final class Loader implements LoaderErrorThrower {
} else { } else {
canceled = true; canceled = true;
loadable.cancelLoad(); loadable.cancelLoad();
Thread executorThread = this.executorThread; @Nullable Thread executorThread = this.executorThread;
if (executorThread != null) { if (executorThread != null) {
executorThread.interrupt(); executorThread.interrupt();
} }
......
...@@ -49,15 +49,14 @@ public interface LoaderErrorThrower { ...@@ -49,15 +49,14 @@ public interface LoaderErrorThrower {
final class Dummy implements LoaderErrorThrower { final class Dummy implements LoaderErrorThrower {
@Override @Override
public void maybeThrowError() throws IOException { public void maybeThrowError() {
// Do nothing. // Do nothing.
} }
@Override @Override
public void maybeThrowError(int minRetryCount) throws IOException { public void maybeThrowError(int minRetryCount) {
// Do nothing. // Do nothing.
} }
} }
} }
...@@ -127,7 +127,8 @@ public final class ParsingLoadable<T> implements Loadable { ...@@ -127,7 +127,8 @@ public final class ParsingLoadable<T> implements Loadable {
} }
/** Returns the loaded object, or null if an object has not been loaded. */ /** 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; return result;
} }
......
...@@ -113,7 +113,7 @@ public final class ResolvingDataSource implements DataSource { ...@@ -113,7 +113,7 @@ public final class ResolvingDataSource implements DataSource {
@Nullable @Nullable
@Override @Override
public Uri getUri() { public Uri getUri() {
Uri reportedUri = upstreamDataSource.getUri(); @Nullable Uri reportedUri = upstreamDataSource.getUri();
return reportedUri == null ? null : resolver.resolveReportedUri(reportedUri); return reportedUri == null ? null : resolver.resolveReportedUri(reportedUri);
} }
......
/*
* 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;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment