what-the-bank/sources/okhttp3/repackaged/internal/http/RetryableSink.java

76 lines
2.0 KiB
Java
Raw Normal View History

2024-07-27 18:17:47 +07:00
package okhttp3.repackaged.internal.http;
import java.io.IOException;
import java.net.ProtocolException;
import o.giM;
import o.giX;
import o.giY;
import okhttp3.repackaged.internal.Util;
/* loaded from: classes6.dex */
public final class RetryableSink implements giX {
private final giM amt;
private boolean closed;
private final int limit;
@Override // o.giX, java.io.Flushable
public final void flush() throws IOException {
}
public RetryableSink(int i) {
this.amt = new giM();
this.limit = i;
}
public RetryableSink() {
this(-1);
}
@Override // o.giX
public final giY timeout() {
return giY.NONE;
}
public final void writeToSocket(giX gix) throws IOException {
giM gim = new giM();
giM gim2 = this.amt;
gim2.d(gim, 0L, gim2.a);
gix.write(gim, gim.a);
}
@Override // o.giX, java.io.Closeable, java.lang.AutoCloseable
public final void close() throws IOException {
if (this.closed) {
return;
}
this.closed = true;
if (this.amt.a >= this.limit) {
return;
}
StringBuilder sb = new StringBuilder("content-length promised ");
sb.append(this.limit);
sb.append(" bytes, but received ");
sb.append(this.amt.a);
throw new ProtocolException(sb.toString());
}
public final long contentLength() throws IOException {
return this.amt.a;
}
@Override // o.giX
public final void write(giM gim, long j) throws IOException {
if (this.closed) {
throw new IllegalStateException("closed");
}
Util.checkOffsetAndCount(gim.a, 0L, j);
if (this.limit != -1 && this.amt.a > this.limit - j) {
StringBuilder sb = new StringBuilder("exceeded content-length limit of ");
sb.append(this.limit);
sb.append(" bytes");
throw new ProtocolException(sb.toString());
}
this.amt.write(gim, j);
}
}