package com.google.android.gms.internal.ads; import android.net.Uri; import android.system.ErrnoException; import android.system.OsConstants; import android.text.TextUtils; import androidx.annotation.Nullable; import java.io.FileNotFoundException; import java.io.IOException; import java.io.RandomAccessFile; /* loaded from: classes3.dex */ public final class zzgn extends zzfr { @Nullable private RandomAccessFile zza; @Nullable private Uri zzb; private long zzc; private boolean zzd; public zzgn() { super(false); } @Override // com.google.android.gms.internal.ads.zzl public final int zza(byte[] bArr, int i, int i2) throws zzgm { if (i2 == 0) { return 0; } long j = this.zzc; if (j == 0) { return -1; } try { RandomAccessFile randomAccessFile = this.zza; int i3 = zzei.zza; int read = randomAccessFile.read(bArr, i, (int) Math.min(j, i2)); if (read > 0) { this.zzc -= read; zzg(read); } return read; } catch (IOException e) { throw new zzgm(e, 2000); } } @Override // com.google.android.gms.internal.ads.zzfy public final long zzb(zzgd zzgdVar) throws zzgm { Uri uri = zzgdVar.zza; this.zzb = uri; zzi(zzgdVar); try { String path = uri.getPath(); path.getClass(); RandomAccessFile randomAccessFile = new RandomAccessFile(path, "r"); this.zza = randomAccessFile; try { randomAccessFile.seek(zzgdVar.zze); long j = zzgdVar.zzf; if (j == -1) { j = this.zza.length() - zzgdVar.zze; } this.zzc = j; if (j < 0) { throw new zzgm(null, null, 2008); } this.zzd = true; zzj(zzgdVar); return this.zzc; } catch (IOException e) { throw new zzgm(e, 2000); } } catch (FileNotFoundException e2) { if (TextUtils.isEmpty(uri.getQuery()) && TextUtils.isEmpty(uri.getFragment())) { throw new zzgm(e2, ((e2.getCause() instanceof ErrnoException) && ((ErrnoException) e2.getCause()).errno == OsConstants.EACCES) ? 2006 : 2005); } throw new zzgm(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()), e2, 1004); } catch (SecurityException e3) { throw new zzgm(e3, 2006); } catch (RuntimeException e4) { throw new zzgm(e4, 2000); } } @Override // com.google.android.gms.internal.ads.zzfy @Nullable public final Uri zzc() { return this.zzb; } @Override // com.google.android.gms.internal.ads.zzfy public final void zzd() throws zzgm { this.zzb = null; try { try { RandomAccessFile randomAccessFile = this.zza; if (randomAccessFile != null) { randomAccessFile.close(); } this.zza = null; if (this.zzd) { this.zzd = false; zzh(); } } catch (IOException e) { throw new zzgm(e, 2000); } } catch (Throwable th) { this.zza = null; if (this.zzd) { this.zzd = false; zzh(); } throw th; } } }