Rabbit-R1/switch port/java/sources/androidx/media3/exoplayer/upstream/ParsingLoadable.java

87 lines
3.1 KiB
Java
Raw Normal View History

2024-05-21 21:08:36 +00:00
package androidx.media3.exoplayer.upstream;
import android.net.Uri;
import androidx.media3.common.util.Assertions;
import androidx.media3.common.util.Util;
import androidx.media3.datasource.DataSource;
import androidx.media3.datasource.DataSourceInputStream;
import androidx.media3.datasource.DataSpec;
import androidx.media3.datasource.StatsDataSource;
import androidx.media3.exoplayer.source.LoadEventInfo;
import androidx.media3.exoplayer.upstream.Loader;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;
import java.util.Map;
/* loaded from: classes2.dex */
public final class ParsingLoadable<T> implements Loader.Loadable {
private final StatsDataSource dataSource;
public final DataSpec dataSpec;
public final long loadTaskId;
private final Parser<? extends T> parser;
private volatile T result;
public final int type;
/* loaded from: classes2.dex */
public interface Parser<T> {
T parse(Uri uri, InputStream inputStream) throws IOException;
}
@Override // androidx.media3.exoplayer.upstream.Loader.Loadable
public final void cancelLoad() {
}
public final T getResult() {
return this.result;
}
public static <T> T load(DataSource dataSource, Parser<? extends T> parser, Uri uri, int i) throws IOException {
ParsingLoadable parsingLoadable = new ParsingLoadable(dataSource, uri, i, parser);
parsingLoadable.load();
return (T) Assertions.checkNotNull(parsingLoadable.getResult());
}
public static <T> T load(DataSource dataSource, Parser<? extends T> parser, DataSpec dataSpec, int i) throws IOException {
ParsingLoadable parsingLoadable = new ParsingLoadable(dataSource, dataSpec, i, parser);
parsingLoadable.load();
return (T) Assertions.checkNotNull(parsingLoadable.getResult());
}
public ParsingLoadable(DataSource dataSource, Uri uri, int i, Parser<? extends T> parser) {
this(dataSource, new DataSpec.Builder().setUri(uri).setFlags(1).build(), i, parser);
}
public ParsingLoadable(DataSource dataSource, DataSpec dataSpec, int i, Parser<? extends T> parser) {
this.dataSource = new StatsDataSource(dataSource);
this.dataSpec = dataSpec;
this.type = i;
this.parser = parser;
this.loadTaskId = LoadEventInfo.getNewId();
}
public long bytesLoaded() {
return this.dataSource.getBytesRead();
}
public Uri getUri() {
return this.dataSource.getLastOpenedUri();
}
public Map<String, List<String>> getResponseHeaders() {
return this.dataSource.getLastResponseHeaders();
}
@Override // androidx.media3.exoplayer.upstream.Loader.Loadable
public final void load() throws IOException {
this.dataSource.resetBytesRead();
DataSourceInputStream dataSourceInputStream = new DataSourceInputStream(this.dataSource, this.dataSpec);
try {
dataSourceInputStream.open();
this.result = this.parser.parse((Uri) Assertions.checkNotNull(this.dataSource.getUri()), dataSourceInputStream);
} finally {
Util.closeQuietly(dataSourceInputStream);
}
}
}