package okio; import java.io.InterruptedIOException; import java.util.concurrent.TimeUnit; /* loaded from: classes5.dex */ public class Timeout { public static final Timeout NONE = new Timeout() { // from class: okio.Timeout.1 @Override // okio.Timeout public Timeout deadlineNanoTime(long j) { return this; } @Override // okio.Timeout public void throwIfReached() { } @Override // okio.Timeout public Timeout timeout(long j, TimeUnit timeUnit) { return this; } }; public long deadlineNanoTime; public boolean hasDeadline; public long timeoutNanos; public Timeout clearDeadline() { this.hasDeadline = false; return this; } public Timeout clearTimeout() { this.timeoutNanos = 0L; return this; } public Timeout deadlineNanoTime(long j) { this.hasDeadline = true; this.deadlineNanoTime = j; return this; } public boolean hasDeadline() { return this.hasDeadline; } public long timeoutNanos() { return this.timeoutNanos; } public Timeout timeout(long j, TimeUnit timeUnit) { if (j >= 0) { if (timeUnit == null) { throw new IllegalArgumentException("unit == null"); } this.timeoutNanos = timeUnit.toNanos(j); return this; } throw new IllegalArgumentException("timeout < 0: " + j); } public long deadlineNanoTime() { if (this.hasDeadline) { return this.deadlineNanoTime; } throw new IllegalStateException("No deadline"); } public void throwIfReached() { if (Thread.interrupted()) { Thread.currentThread().interrupt(); throw new InterruptedIOException("interrupted"); } if (this.hasDeadline && this.deadlineNanoTime - System.nanoTime() <= 0) { throw new InterruptedIOException("deadline reached"); } } }