diff --git a/library/core/src/main/java/com/google/android/exoplayer2/upstream/DataSourceInputStream.java b/library/core/src/main/java/com/google/android/exoplayer2/upstream/DataSourceInputStream.java index 6c4e77a90a..c4296bd6f6 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/upstream/DataSourceInputStream.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/upstream/DataSourceInputStream.java @@ -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); diff --git a/library/core/src/main/java/com/google/android/exoplayer2/upstream/DefaultAllocator.java b/library/core/src/main/java/com/google/android/exoplayer2/upstream/DefaultAllocator.java index 71e2d8d19f..ca9cca255d 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/upstream/DefaultAllocator.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/upstream/DefaultAllocator.java @@ -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; diff --git a/library/core/src/main/java/com/google/android/exoplayer2/upstream/DefaultBandwidthMeter.java b/library/core/src/main/java/com/google/android/exoplayer2/upstream/DefaultBandwidthMeter.java index f688bb9447..0309292164 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/upstream/DefaultBandwidthMeter.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/upstream/DefaultBandwidthMeter.java @@ -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; } diff --git a/library/core/src/main/java/com/google/android/exoplayer2/upstream/DefaultHttpDataSource.java b/library/core/src/main/java/com/google/android/exoplayer2/upstream/DefaultHttpDataSource.java index ae115ab58c..f2cf344b9f 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/upstream/DefaultHttpDataSource.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/upstream/DefaultHttpDataSource.java @@ -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"); } diff --git a/library/core/src/main/java/com/google/android/exoplayer2/upstream/FileDataSource.java b/library/core/src/main/java/com/google/android/exoplayer2/upstream/FileDataSource.java index 2661469efd..93c1ce9adf 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/upstream/FileDataSource.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/upstream/FileDataSource.java @@ -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); + } + } } diff --git a/library/core/src/main/java/com/google/android/exoplayer2/upstream/HttpDataSource.java b/library/core/src/main/java/com/google/android/exoplayer2/upstream/HttpDataSource.java index 63cad8786b..9d4f9b6811 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/upstream/HttpDataSource.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/upstream/HttpDataSource.java @@ -89,7 +89,7 @@ public interface HttpDataSource extends DataSource { final class RequestProperties { private final Map requestProperties; - private Map requestPropertiesSnapshot; + @Nullable private Map requestPropertiesSnapshot; public RequestProperties() { requestProperties = new HashMap<>(); diff --git a/library/core/src/main/java/com/google/android/exoplayer2/upstream/Loader.java b/library/core/src/main/java/com/google/android/exoplayer2/upstream/Loader.java index a498f510dd..d9d84bdda1 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/upstream/Loader.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/upstream/Loader.java @@ -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(); } diff --git a/library/core/src/main/java/com/google/android/exoplayer2/upstream/LoaderErrorThrower.java b/library/core/src/main/java/com/google/android/exoplayer2/upstream/LoaderErrorThrower.java index 4f9e9fa5e6..54c3d4cbe5 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/upstream/LoaderErrorThrower.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/upstream/LoaderErrorThrower.java @@ -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. } - } } diff --git a/library/core/src/main/java/com/google/android/exoplayer2/upstream/ParsingLoadable.java b/library/core/src/main/java/com/google/android/exoplayer2/upstream/ParsingLoadable.java index edec849b88..7fceda1700 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/upstream/ParsingLoadable.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/upstream/ParsingLoadable.java @@ -127,7 +127,8 @@ public final class ParsingLoadable 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; } diff --git a/library/core/src/main/java/com/google/android/exoplayer2/upstream/ResolvingDataSource.java b/library/core/src/main/java/com/google/android/exoplayer2/upstream/ResolvingDataSource.java index 412f866e99..7e5a274c81 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/upstream/ResolvingDataSource.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/upstream/ResolvingDataSource.java @@ -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); } diff --git a/library/core/src/main/java/com/google/android/exoplayer2/upstream/package-info.java b/library/core/src/main/java/com/google/android/exoplayer2/upstream/package-info.java new file mode 100644 index 0000000000..1fb49d4b96 --- /dev/null +++ b/library/core/src/main/java/com/google/android/exoplayer2/upstream/package-info.java @@ -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;