package g0; import d0.z.d.m; import java.io.EOFException; import java.io.IOException; import java.io.InputStream; import java.nio.ByteBuffer; import java.nio.charset.Charset; import okio.ByteString; /* compiled from: RealBufferedSource.kt */ public final class r implements g { public final e i = new e(); public boolean j; public final x k; /* compiled from: RealBufferedSource.kt */ public static final class a extends InputStream { public final /* synthetic */ r i; public a(r rVar) { this.i = rVar; } @Override // java.io.InputStream public int available() { r rVar = this.i; if (!rVar.j) { return (int) Math.min(rVar.i.j, (long) Integer.MAX_VALUE); } throw new IOException("closed"); } @Override // java.io.InputStream, java.io.Closeable, java.lang.AutoCloseable public void close() { this.i.close(); } @Override // java.io.InputStream public int read() { r rVar = this.i; if (!rVar.j) { e eVar = rVar.i; if (eVar.j == 0 && rVar.k.h0(eVar, (long) 8192) == -1) { return -1; } return this.i.i.readByte() & 255; } throw new IOException("closed"); } @Override // java.io.InputStream public int read(byte[] bArr, int i, int i2) { m.checkParameterIsNotNull(bArr, "data"); if (!this.i.j) { c.q.a.k.a.l((long) bArr.length, (long) i, (long) i2); r rVar = this.i; e eVar = rVar.i; if (eVar.j == 0 && rVar.k.h0(eVar, (long) 8192) == -1) { return -1; } return this.i.i.read(bArr, i, i2); } throw new IOException("closed"); } @Override // java.lang.Object public String toString() { return this.i + ".inputStream()"; } } public r(x xVar) { m.checkParameterIsNotNull(xVar, "source"); this.k = xVar; } @Override // g0.g public void A(e eVar, long j) { m.checkParameterIsNotNull(eVar, "sink"); try { if (j(j)) { this.i.A(eVar, j); return; } throw new EOFException(); } catch (EOFException e) { eVar.O(this.i); throw e; } } @Override // g0.g public long D(ByteString byteString) { m.checkParameterIsNotNull(byteString, "targetBytes"); m.checkParameterIsNotNull(byteString, "targetBytes"); if (!this.j) { long j = 0; while (true) { long t = this.i.t(byteString, j); if (t != -1) { return t; } e eVar = this.i; long j2 = eVar.j; if (this.k.h0(eVar, (long) 8192) == -1) { return -1; } j = Math.max(j, j2); } } else { throw new IllegalStateException("closed".toString()); } } @Override // g0.g public String F(long j) { if (j >= 0) { long j2 = j == Long.MAX_VALUE ? Long.MAX_VALUE : j + 1; byte b = (byte) 10; long a2 = a(b, 0, j2); if (a2 != -1) { return g0.z.a.a(this.i, a2); } if (j2 < Long.MAX_VALUE && j(j2) && this.i.r(j2 - 1) == ((byte) 13) && j(1 + j2) && this.i.r(j2) == b) { return g0.z.a.a(this.i, j2); } e eVar = new e(); e eVar2 = this.i; eVar2.p(eVar, 0, Math.min((long) 32, eVar2.j)); throw new EOFException("\\n not found: limit=" + Math.min(this.i.j, j) + " content=" + eVar.x().k() + "…"); } throw new IllegalArgumentException(c.d.b.a.a.q("limit < 0: ", j).toString()); } @Override // g0.g public String L(Charset charset) { m.checkParameterIsNotNull(charset, "charset"); this.i.O(this.k); return this.i.L(charset); } @Override // g0.g public String X() { return F(Long.MAX_VALUE); } @Override // g0.g public byte[] Y(long j) { if (j(j)) { return this.i.Y(j); } throw new EOFException(); } public long a(byte b, long j, long j2) { boolean z2 = true; if (!this.j) { if (0 > j || j2 < j) { z2 = false; } if (z2) { while (j < j2) { long s2 = this.i.s(b, j, j2); if (s2 != -1) { return s2; } e eVar = this.i; long j3 = eVar.j; if (j3 >= j2 || this.k.h0(eVar, (long) 8192) == -1) { return -1; } j = Math.max(j, j3); } return -1; } StringBuilder O = c.d.b.a.a.O("fromIndex=", j, " toIndex="); O.append(j2); throw new IllegalArgumentException(O.toString().toString()); } throw new IllegalStateException("closed".toString()); } public int b() { o0(4); int readInt = this.i.readInt(); return ((readInt & 255) << 24) | ((-16777216 & readInt) >>> 24) | ((16711680 & readInt) >>> 8) | ((65280 & readInt) << 8); } @Override // g0.x, java.io.Closeable, java.lang.AutoCloseable public void close() { if (!this.j) { this.j = true; this.k.close(); e eVar = this.i; eVar.skip(eVar.j); } } @Override // g0.g, okio.BufferedSink public e g() { return this.i; } @Override // g0.x public long h0(e eVar, long j) { m.checkParameterIsNotNull(eVar, "sink"); if (!(j >= 0)) { throw new IllegalArgumentException(c.d.b.a.a.q("byteCount < 0: ", j).toString()); } else if (!this.j) { e eVar2 = this.i; if (eVar2.j == 0 && this.k.h0(eVar2, (long) 8192) == -1) { return -1; } return this.i.h0(eVar, Math.min(j, this.i.j)); } else { throw new IllegalStateException("closed".toString()); } } @Override // java.nio.channels.Channel public boolean isOpen() { return !this.j; } @Override // g0.g public boolean j(long j) { e eVar; if (!(j >= 0)) { throw new IllegalArgumentException(c.d.b.a.a.q("byteCount < 0: ", j).toString()); } else if (!this.j) { do { eVar = this.i; if (eVar.j >= j) { return true; } } while (this.k.h0(eVar, (long) 8192) != -1); return false; } else { throw new IllegalStateException("closed".toString()); } } @Override // g0.g public long j0(v vVar) { m.checkParameterIsNotNull(vVar, "sink"); long j = 0; while (this.k.h0(this.i, (long) 8192) != -1) { long f = this.i.f(); if (f > 0) { j += f; vVar.write(this.i, f); } } e eVar = this.i; long j2 = eVar.j; if (j2 <= 0) { return j; } long j3 = j + j2; vVar.write(eVar, j2); return j3; } @Override // g0.g public ByteString n(long j) { if (j(j)) { return this.i.n(j); } throw new EOFException(); } @Override // g0.g public void o0(long j) { if (!j(j)) { throw new EOFException(); } } @Override // g0.g public long r0() { byte r; o0(1); int i = 0; while (true) { int i2 = i + 1; if (!j((long) i2)) { break; } r = this.i.r((long) i); if ((r < ((byte) 48) || r > ((byte) 57)) && ((r < ((byte) 97) || r > ((byte) 102)) && (r < ((byte) 65) || r > ((byte) 70)))) { break; } i = i2; } if (i == 0) { StringBuilder L = c.d.b.a.a.L("Expected leading [0-9a-fA-F] character but was 0x"); String num = Integer.toString(r, d0.g0.a.checkRadix(d0.g0.a.checkRadix(16))); m.checkExpressionValueIsNotNull(num, "java.lang.Integer.toStri…(this, checkRadix(radix))"); L.append(num); throw new NumberFormatException(L.toString()); } return this.i.r0(); } @Override // java.nio.channels.ReadableByteChannel public int read(ByteBuffer byteBuffer) { m.checkParameterIsNotNull(byteBuffer, "sink"); e eVar = this.i; if (eVar.j == 0 && this.k.h0(eVar, (long) 8192) == -1) { return -1; } return this.i.read(byteBuffer); } @Override // g0.g public byte readByte() { o0(1); return this.i.readByte(); } @Override // g0.g public void readFully(byte[] bArr) { m.checkParameterIsNotNull(bArr, "sink"); try { o0((long) bArr.length); this.i.readFully(bArr); } catch (EOFException e) { int i = 0; while (true) { e eVar = this.i; long j = eVar.j; if (j > 0) { int read = eVar.read(bArr, i, (int) j); if (read != -1) { i += read; } else { throw new AssertionError(); } } else { throw e; } } } } @Override // g0.g public int readInt() { o0(4); return this.i.readInt(); } @Override // g0.g public long readLong() { o0(8); return this.i.readLong(); } @Override // g0.g public short readShort() { o0(2); return this.i.readShort(); } @Override // g0.g public void skip(long j) { if (!this.j) { while (j > 0) { e eVar = this.i; if (eVar.j == 0 && this.k.h0(eVar, (long) 8192) == -1) { throw new EOFException(); } long min = Math.min(j, this.i.j); this.i.skip(min); j -= min; } return; } throw new IllegalStateException("closed".toString()); } @Override // g0.g public InputStream t0() { return new a(this); } @Override // g0.x public y timeout() { return this.k.timeout(); } @Override // java.lang.Object public String toString() { StringBuilder L = c.d.b.a.a.L("buffer("); L.append(this.k); L.append(')'); return L.toString(); } @Override // g0.g public int u0(o oVar) { m.checkParameterIsNotNull(oVar, "options"); if (!this.j) { while (true) { int b = g0.z.a.b(this.i, oVar, true); if (b == -2) { if (this.k.h0(this.i, (long) 8192) == -1) { break; } } else if (b != -1) { this.i.skip((long) oVar.k[b].j()); return b; } } return -1; } throw new IllegalStateException("closed".toString()); } @Override // g0.g public boolean v() { if (!this.j) { return this.i.v() && this.k.h0(this.i, (long) 8192) == -1; } throw new IllegalStateException("closed".toString()); } }