package com.google.android.play.core.assetpacks; import java.io.File; import java.io.FileInputStream; import java.io.InputStream; import java.io.SequenceInputStream; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.List; import java.util.Map; import java.util.NavigableMap; import java.util.TreeMap; /* loaded from: classes2.dex */ final class h0 extends r3.l { /* renamed from: a, reason: collision with root package name */ private final File f4904a; /* renamed from: b, reason: collision with root package name */ private final File f4905b; /* renamed from: c, reason: collision with root package name */ private final NavigableMap f4906c = new TreeMap(); h0(File file, File file2) { this.f4904a = file; this.f4905b = file2; List a10 = d3.a(file, file2); if (a10.isEmpty()) { throw new d1(String.format("Virtualized slice archive empty for %s, %s", file, file2)); } long j10 = 0; for (File file3 : a10) { this.f4906c.put(Long.valueOf(j10), file3); j10 += file3.length(); } } private final InputStream I(long j10, Long l10) { FileInputStream fileInputStream = new FileInputStream((File) this.f4906c.get(l10)); if (fileInputStream.skip(j10 - l10.longValue()) == j10 - l10.longValue()) { return fileInputStream; } throw new d1(String.format("Virtualized slice archive corrupt, could not skip in file with key %s", l10)); } @Override // r3.l public final long c() { Map.Entry lastEntry = this.f4906c.lastEntry(); return ((Long) lastEntry.getKey()).longValue() + ((File) lastEntry.getValue()).length(); } @Override // java.io.Closeable, java.lang.AutoCloseable public final void close() { } @Override // r3.l protected final InputStream z(long j10, long j11) { if (j10 < 0 || j11 < 0) { throw new d1(String.format("Invalid input parameters %s, %s", Long.valueOf(j10), Long.valueOf(j11))); } long j12 = j10 + j11; if (j12 > c()) { throw new d1(String.format("Trying to access archive out of bounds. Archive ends at: %s. Tried accessing: %s", Long.valueOf(c()), Long.valueOf(j12))); } Long l10 = (Long) this.f4906c.floorKey(Long.valueOf(j10)); Long l11 = (Long) this.f4906c.floorKey(Long.valueOf(j12)); if (l10.equals(l11)) { return new g0(I(j10, l10), j11); } ArrayList arrayList = new ArrayList(); arrayList.add(I(j10, l10)); Collection values = this.f4906c.subMap(l10, false, l11, false).values(); if (!values.isEmpty()) { arrayList.add(new q3.g(Collections.enumeration(values))); } arrayList.add(new g0(new FileInputStream((File) this.f4906c.get(l11)), j11 - (l11.longValue() - j10))); return new SequenceInputStream(Collections.enumeration(arrayList)); } }