Rabbit-R1/switch port/java/sources/okhttp3/internal/cache2/Relay.java
2024-05-21 17:08:36 -04:00

446 lines
22 KiB
Java

package okhttp3.internal.cache2;
import io.sentry.ProfilingTraceData;
import java.io.File;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.channels.FileChannel;
import kotlin.Metadata;
import kotlin.Unit;
import kotlin.jvm.internal.DefaultConstructorMarker;
import kotlin.jvm.internal.Intrinsics;
import okhttp3.internal.Util;
import okio.Buffer;
import okio.ByteString;
import okio.Source;
import okio.Timeout;
/* compiled from: Relay.kt */
@Metadata(bv = {1, 0, 3}, d1 = {"\u0000L\n\u0002\u0018\u0002\n\u0002\u0010\u0000\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0010\t\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0003\n\u0002\u0018\u0002\n\u0002\b\u0005\n\u0002\u0010\u000b\n\u0002\b\n\n\u0002\u0010\b\n\u0002\b\u000e\n\u0002\u0018\u0002\n\u0002\b\u0005\n\u0002\u0010\u0002\n\u0002\b\t\u0018\u0000 :2\u00020\u0001:\u0002:;B3\b\u0002\u0012\b\u0010\u0002\u001a\u0004\u0018\u00010\u0003\u0012\b\u0010\u0004\u001a\u0004\u0018\u00010\u0005\u0012\u0006\u0010\u0006\u001a\u00020\u0007\u0012\u0006\u0010\b\u001a\u00020\t\u0012\u0006\u0010\n\u001a\u00020\u0007¢\u0006\u0002\u0010\u000bJ\u000e\u00102\u001a\u0002032\u0006\u00104\u001a\u00020\u0007J\u0006\u0010\b\u001a\u00020\tJ\b\u00105\u001a\u0004\u0018\u00010\u0005J \u00106\u001a\u0002032\u0006\u00107\u001a\u00020\t2\u0006\u00104\u001a\u00020\u00072\u0006\u00108\u001a\u00020\u0007H\u0002J\u0010\u00109\u001a\u0002032\u0006\u00104\u001a\u00020\u0007H\u0002R\u0011\u0010\f\u001a\u00020\\u0006\b\n\u0000\u001a\u0004\b\u000e\u0010\u000fR\u0011\u0010\n\u001a\u00020\u0007¢\u0006\b\n\u0000\u001a\u0004\b\u0010\u0010\u0011R\u001a\u0010\u0012\u001a\u00020\u0013X\u0086\u000e¢\u0006\u000e\n\u0000\u001a\u0004\b\u0014\u0010\u0015\"\u0004\b\u0016\u0010\u0017R\u001c\u0010\u0002\u001a\u0004\u0018\u00010\u0003X\u0086\u000e¢\u0006\u000e\n\u0000\u001a\u0004\b\u0018\u0010\u0019\"\u0004\b\u001a\u0010\u001bR\u0011\u0010\u001c\u001a\u00020\u00138F¢\u0006\u0006\u001a\u0004\b\u001c\u0010\u0015R\u000e\u0010\b\u001a\u00020\tX\u0082\u0004¢\u0006\u0002\n\u0000R\u001a\u0010\u001d\u001a\u00020\u001eX\u0086\u000e¢\u0006\u000e\n\u0000\u001a\u0004\b\u001f\u0010 \"\u0004\b!\u0010\"R\u001c\u0010\u0004\u001a\u0004\u0018\u00010\u0005X\u0086\u000e¢\u0006\u000e\n\u0000\u001a\u0004\b#\u0010$\"\u0004\b%\u0010&R\u0011\u0010'\u001a\u00020\\u0006\b\n\u0000\u001a\u0004\b(\u0010\u000fR\u001a\u0010\u0006\u001a\u00020\u0007X\u0086\u000e¢\u0006\u000e\n\u0000\u001a\u0004\b)\u0010\u0011\"\u0004\b*\u0010+R\u001c\u0010,\u001a\u0004\u0018\u00010-X\u0086\u000e¢\u0006\u000e\n\u0000\u001a\u0004\b.\u0010/\"\u0004\b0\u00101¨\u0006<"}, d2 = {"Lokhttp3/internal/cache2/Relay;", "", "file", "Ljava/io/RandomAccessFile;", "upstream", "Lokio/Source;", "upstreamPos", "", "metadata", "Lokio/ByteString;", "bufferMaxSize", "(Ljava/io/RandomAccessFile;Lokio/Source;JLokio/ByteString;J)V", "buffer", "Lokio/Buffer;", "getBuffer", "()Lokio/Buffer;", "getBufferMaxSize", "()J", "complete", "", "getComplete", "()Z", "setComplete", "(Z)V", "getFile", "()Ljava/io/RandomAccessFile;", "setFile", "(Ljava/io/RandomAccessFile;)V", "isClosed", "sourceCount", "", "getSourceCount", "()I", "setSourceCount", "(I)V", "getUpstream", "()Lokio/Source;", "setUpstream", "(Lokio/Source;)V", "upstreamBuffer", "getUpstreamBuffer", "getUpstreamPos", "setUpstreamPos", "(J)V", "upstreamReader", "Ljava/lang/Thread;", "getUpstreamReader", "()Ljava/lang/Thread;", "setUpstreamReader", "(Ljava/lang/Thread;)V", "commit", "", "upstreamSize", "newSource", "writeHeader", "prefix", "metadataSize", "writeMetadata", "Companion", "RelaySource", "okhttp"}, k = 1, mv = {1, 4, 0})
/* loaded from: classes3.dex */
public final class Relay {
private static final long FILE_HEADER_SIZE = 32;
private static final int SOURCE_FILE = 2;
private static final int SOURCE_UPSTREAM = 1;
private final Buffer buffer;
private final long bufferMaxSize;
private boolean complete;
private RandomAccessFile file;
private final ByteString metadata;
private int sourceCount;
private Source upstream;
private final Buffer upstreamBuffer;
private long upstreamPos;
private Thread upstreamReader;
/* renamed from: Companion, reason: from kotlin metadata */
public static final Companion INSTANCE = new Companion(null);
public static final ByteString PREFIX_CLEAN = ByteString.INSTANCE.encodeUtf8("OkHttp cache v1\n");
public static final ByteString PREFIX_DIRTY = ByteString.INSTANCE.encodeUtf8("OkHttp DIRTY :(\n");
public final Buffer getBuffer() {
return this.buffer;
}
public final long getBufferMaxSize() {
return this.bufferMaxSize;
}
public final boolean getComplete() {
return this.complete;
}
public final RandomAccessFile getFile() {
return this.file;
}
public final int getSourceCount() {
return this.sourceCount;
}
public final Source getUpstream() {
return this.upstream;
}
public final Buffer getUpstreamBuffer() {
return this.upstreamBuffer;
}
public final long getUpstreamPos() {
return this.upstreamPos;
}
public final Thread getUpstreamReader() {
return this.upstreamReader;
}
public final boolean isClosed() {
return this.file == null;
}
/* renamed from: metadata, reason: from getter */
public final ByteString getMetadata() {
return this.metadata;
}
public final void setComplete(boolean z) {
this.complete = z;
}
public final void setFile(RandomAccessFile randomAccessFile) {
this.file = randomAccessFile;
}
public final void setSourceCount(int i) {
this.sourceCount = i;
}
public final void setUpstream(Source source) {
this.upstream = source;
}
public final void setUpstreamPos(long j) {
this.upstreamPos = j;
}
public final void setUpstreamReader(Thread thread) {
this.upstreamReader = thread;
}
private Relay(RandomAccessFile randomAccessFile, Source source, long j, ByteString byteString, long j2) {
this.file = randomAccessFile;
this.upstream = source;
this.upstreamPos = j;
this.metadata = byteString;
this.bufferMaxSize = j2;
this.upstreamBuffer = new Buffer();
this.complete = this.upstream == null;
this.buffer = new Buffer();
}
public /* synthetic */ Relay(RandomAccessFile randomAccessFile, Source source, long j, ByteString byteString, long j2, DefaultConstructorMarker defaultConstructorMarker) {
this(randomAccessFile, source, j, byteString, j2);
}
/* JADX INFO: Access modifiers changed from: private */
public final void writeHeader(ByteString prefix, long upstreamSize, long metadataSize) throws IOException {
Buffer buffer = new Buffer();
buffer.write(prefix);
buffer.writeLong(upstreamSize);
buffer.writeLong(metadataSize);
if (!(buffer.size() == FILE_HEADER_SIZE)) {
throw new IllegalArgumentException("Failed requirement.".toString());
}
RandomAccessFile randomAccessFile = this.file;
Intrinsics.checkNotNull(randomAccessFile);
FileChannel channel = randomAccessFile.getChannel();
Intrinsics.checkNotNullExpressionValue(channel, "file!!.channel");
new FileOperator(channel).write(0L, buffer, FILE_HEADER_SIZE);
}
private final void writeMetadata(long upstreamSize) throws IOException {
Buffer buffer = new Buffer();
buffer.write(this.metadata);
RandomAccessFile randomAccessFile = this.file;
Intrinsics.checkNotNull(randomAccessFile);
FileChannel channel = randomAccessFile.getChannel();
Intrinsics.checkNotNullExpressionValue(channel, "file!!.channel");
new FileOperator(channel).write(FILE_HEADER_SIZE + upstreamSize, buffer, this.metadata.size());
}
public final void commit(long upstreamSize) throws IOException {
writeMetadata(upstreamSize);
RandomAccessFile randomAccessFile = this.file;
Intrinsics.checkNotNull(randomAccessFile);
randomAccessFile.getChannel().force(false);
writeHeader(PREFIX_CLEAN, upstreamSize, this.metadata.size());
RandomAccessFile randomAccessFile2 = this.file;
Intrinsics.checkNotNull(randomAccessFile2);
randomAccessFile2.getChannel().force(false);
synchronized (this) {
this.complete = true;
Unit unit = Unit.INSTANCE;
}
Source source = this.upstream;
if (source != null) {
Util.closeQuietly(source);
}
this.upstream = null;
}
public final Source newSource() {
synchronized (this) {
if (this.file == null) {
return null;
}
this.sourceCount++;
return new RelaySource();
}
}
/* compiled from: Relay.kt */
@Metadata(bv = {1, 0, 3}, d1 = {"\u0000.\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0000\n\u0002\u0010\t\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0010\u0002\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0002\b\u0002\b\u0080\u0004\u0018\u00002\u00020\u0001B\u0005¢\u0006\u0002\u0010\u0002J\b\u0010\t\u001a\u00020\nH\u0016J\u0018\u0010\u000b\u001a\u00020\u00062\u0006\u0010\f\u001a\u00020\r2\u0006\u0010\u000e\u001a\u00020\u0006H\u0016J\b\u0010\u0007\u001a\u00020\bH\u0016R\u0010\u0010\u0003\u001a\u0004\u0018\u00010\u0004X\u0082\u000e¢\u0006\u0002\n\u0000R\u000e\u0010\u0005\u001a\u00020\u0006X\u0082\u000e¢\u0006\u0002\n\u0000R\u000e\u0010\u0007\u001a\u00020\bX\u0082\u0004¢\u0006\u0002\n\u0000¨\u0006\u000f"}, d2 = {"Lokhttp3/internal/cache2/Relay$RelaySource;", "Lokio/Source;", "(Lokhttp3/internal/cache2/Relay;)V", "fileOperator", "Lokhttp3/internal/cache2/FileOperator;", "sourcePos", "", ProfilingTraceData.TRUNCATION_REASON_TIMEOUT, "Lokio/Timeout;", "close", "", "read", "sink", "Lokio/Buffer;", "byteCount", "okhttp"}, k = 1, mv = {1, 4, 0})
/* loaded from: classes3.dex */
public final class RelaySource implements Source {
private FileOperator fileOperator;
private long sourcePos;
private final Timeout timeout = new Timeout();
@Override // okio.Source
/* renamed from: timeout, reason: from getter */
public Timeout getTimeout() {
return this.timeout;
}
public RelaySource() {
RandomAccessFile file = Relay.this.getFile();
Intrinsics.checkNotNull(file);
FileChannel channel = file.getChannel();
Intrinsics.checkNotNullExpressionValue(channel, "file!!.channel");
this.fileOperator = new FileOperator(channel);
}
/* JADX WARN: Code restructure failed: missing block: B:19:0x008b, code lost:
if (r4 != 2) goto L30;
*/
/* JADX WARN: Code restructure failed: missing block: B:20:0x008d, code lost:
r8 = java.lang.Math.min(r21, r19.this$0.getUpstreamPos() - r19.sourcePos);
r2 = r19.fileOperator;
kotlin.jvm.internal.Intrinsics.checkNotNull(r2);
r2.read(r19.sourcePos + okhttp3.internal.cache2.Relay.FILE_HEADER_SIZE, r20, r8);
r19.sourcePos += r8;
*/
/* JADX WARN: Code restructure failed: missing block: B:21:0x00ad, code lost:
return r8;
*/
/* JADX WARN: Code restructure failed: missing block: B:25:0x00af, code lost:
r0 = r19.this$0.getUpstream();
kotlin.jvm.internal.Intrinsics.checkNotNull(r0);
r14 = r0.read(r19.this$0.getUpstreamBuffer(), r19.this$0.getBufferMaxSize());
*/
/* JADX WARN: Code restructure failed: missing block: B:26:0x00ca, code lost:
if (r14 != (-1)) goto L46;
*/
/* JADX WARN: Code restructure failed: missing block: B:27:0x00cc, code lost:
r0 = r19.this$0;
r0.commit(r0.getUpstreamPos());
*/
/* JADX WARN: Code restructure failed: missing block: B:28:0x00d5, code lost:
r2 = r19.this$0;
*/
/* JADX WARN: Code restructure failed: missing block: B:29:0x00d7, code lost:
monitor-enter(r2);
*/
/* JADX WARN: Code restructure failed: missing block: B:31:0x00d8, code lost:
r3 = (java.lang.Thread) null;
r19.this$0.setUpstreamReader(null);
r0 = r19.this$0;
*/
/* JADX WARN: Code restructure failed: missing block: B:32:0x00e2, code lost:
if (r0 == null) goto L41;
*/
/* JADX WARN: Code restructure failed: missing block: B:33:0x00e4, code lost:
r0.notifyAll();
r0 = kotlin.Unit.INSTANCE;
*/
/* JADX WARN: Code restructure failed: missing block: B:34:0x00eb, code lost:
monitor-exit(r2);
*/
/* JADX WARN: Code restructure failed: missing block: B:35:0x00ec, code lost:
return -1;
*/
/* JADX WARN: Code restructure failed: missing block: B:37:0x00f4, code lost:
throw new java.lang.NullPointerException("null cannot be cast to non-null type java.lang.Object");
*/
/* JADX WARN: Code restructure failed: missing block: B:40:0x00f8, code lost:
r9 = java.lang.Math.min(r14, r21);
r19.this$0.getUpstreamBuffer().copyTo(r20, 0, r9);
r19.sourcePos += r9;
r13 = r19.fileOperator;
kotlin.jvm.internal.Intrinsics.checkNotNull(r13);
r13.write(r19.this$0.getUpstreamPos() + okhttp3.internal.cache2.Relay.FILE_HEADER_SIZE, r19.this$0.getUpstreamBuffer().clone(), r14);
r2 = r19.this$0;
*/
/* JADX WARN: Code restructure failed: missing block: B:41:0x012f, code lost:
monitor-enter(r2);
*/
/* JADX WARN: Code restructure failed: missing block: B:43:0x0130, code lost:
r19.this$0.getBuffer().write(r19.this$0.getUpstreamBuffer(), r14);
*/
/* JADX WARN: Code restructure failed: missing block: B:44:0x0151, code lost:
if (r19.this$0.getBuffer().size() <= r19.this$0.getBufferMaxSize()) goto L51;
*/
/* JADX WARN: Code restructure failed: missing block: B:45:0x0153, code lost:
r19.this$0.getBuffer().skip(r19.this$0.getBuffer().size() - r19.this$0.getBufferMaxSize());
*/
/* JADX WARN: Code restructure failed: missing block: B:46:0x016d, code lost:
r0 = r19.this$0;
r0.setUpstreamPos(r0.getUpstreamPos() + r14);
r0 = kotlin.Unit.INSTANCE;
*/
/* JADX WARN: Code restructure failed: missing block: B:47:0x0179, code lost:
monitor-exit(r2);
*/
/* JADX WARN: Code restructure failed: missing block: B:48:0x017a, code lost:
r2 = r19.this$0;
*/
/* JADX WARN: Code restructure failed: missing block: B:49:0x017c, code lost:
monitor-enter(r2);
*/
/* JADX WARN: Code restructure failed: missing block: B:51:0x017d, code lost:
r3 = (java.lang.Thread) null;
r19.this$0.setUpstreamReader(null);
r0 = r19.this$0;
*/
/* JADX WARN: Code restructure failed: missing block: B:52:0x0187, code lost:
if (r0 == null) goto L60;
*/
/* JADX WARN: Code restructure failed: missing block: B:53:0x0189, code lost:
r0.notifyAll();
r0 = kotlin.Unit.INSTANCE;
*/
/* JADX WARN: Code restructure failed: missing block: B:54:0x0190, code lost:
monitor-exit(r2);
*/
/* JADX WARN: Code restructure failed: missing block: B:55:0x0191, code lost:
return r9;
*/
/* JADX WARN: Code restructure failed: missing block: B:57:0x0199, code lost:
throw new java.lang.NullPointerException("null cannot be cast to non-null type java.lang.Object");
*/
/* JADX WARN: Code restructure failed: missing block: B:64:0x01a0, code lost:
r0 = move-exception;
*/
/* JADX WARN: Code restructure failed: missing block: B:66:0x01a3, code lost:
monitor-enter(r19.this$0);
*/
/* JADX WARN: Code restructure failed: missing block: B:68:0x01a4, code lost:
r4 = (java.lang.Thread) null;
r19.this$0.setUpstreamReader(null);
r1 = r19.this$0;
*/
/* JADX WARN: Code restructure failed: missing block: B:69:0x01ae, code lost:
if (r1 == null) goto L73;
*/
/* JADX WARN: Code restructure failed: missing block: B:71:0x01b7, code lost:
throw new java.lang.NullPointerException("null cannot be cast to non-null type java.lang.Object");
*/
/* JADX WARN: Code restructure failed: missing block: B:72:0x01b8, code lost:
r1.notifyAll();
r1 = kotlin.Unit.INSTANCE;
*/
/* JADX WARN: Code restructure failed: missing block: B:73:0x01c0, code lost:
throw r0;
*/
@Override // okio.Source
/*
Code decompiled incorrectly, please refer to instructions dump.
To view partially-correct add '--show-bad-code' argument
*/
public long read(okio.Buffer r20, long r21) throws java.io.IOException {
/*
Method dump skipped, instructions count: 469
To view this dump add '--comments-level debug' option
*/
throw new UnsupportedOperationException("Method not decompiled: okhttp3.internal.cache2.Relay.RelaySource.read(okio.Buffer, long):long");
}
@Override // okio.Source, java.io.Closeable, java.lang.AutoCloseable
public void close() throws IOException {
if (this.fileOperator == null) {
return;
}
RandomAccessFile randomAccessFile = null;
this.fileOperator = null;
synchronized (Relay.this) {
Relay.this.setSourceCount(r2.getSourceCount() - 1);
if (Relay.this.getSourceCount() == 0) {
RandomAccessFile file = Relay.this.getFile();
Relay.this.setFile(null);
randomAccessFile = file;
}
Unit unit = Unit.INSTANCE;
}
if (randomAccessFile != null) {
Util.closeQuietly(randomAccessFile);
}
}
}
/* compiled from: Relay.kt */
@Metadata(bv = {1, 0, 3}, d1 = {"\u00006\n\u0002\u0018\u0002\n\u0002\u0010\u0000\n\u0002\b\u0002\n\u0002\u0010\t\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0010\b\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0004\b\u0086\u0003\u0018\u00002\u00020\u0001B\u0007\b\u0002¢\u0006\u0002\u0010\u0002J&\u0010\u000b\u001a\u00020\f2\u0006\u0010\r\u001a\u00020\u000e2\u0006\u0010\u000f\u001a\u00020\u00102\u0006\u0010\u0011\u001a\u00020\u00062\u0006\u0010\u0012\u001a\u00020\u0004J\u000e\u0010\u0013\u001a\u00020\f2\u0006\u0010\r\u001a\u00020\u000eR\u000e\u0010\u0003\u001a\u00020\u0004X\u0082T¢\u0006\u0002\n\u0000R\u0010\u0010\u0005\u001a\u00020\u00068\u0006X\u0087\u0004¢\u0006\u0002\n\u0000R\u0010\u0010\u0007\u001a\u00020\u00068\u0006X\u0087\u0004¢\u0006\u0002\n\u0000R\u000e\u0010\b\u001a\u00020\tX\u0082T¢\u0006\u0002\n\u0000R\u000e\u0010\n\u001a\u00020\tX\u0082T¢\u0006\u0002\n\u0000¨\u0006\u0014"}, d2 = {"Lokhttp3/internal/cache2/Relay$Companion;", "", "()V", "FILE_HEADER_SIZE", "", "PREFIX_CLEAN", "Lokio/ByteString;", "PREFIX_DIRTY", "SOURCE_FILE", "", "SOURCE_UPSTREAM", "edit", "Lokhttp3/internal/cache2/Relay;", "file", "Ljava/io/File;", "upstream", "Lokio/Source;", "metadata", "bufferMaxSize", "read", "okhttp"}, k = 1, mv = {1, 4, 0})
/* loaded from: classes3.dex */
public static final class Companion {
private Companion() {
}
public /* synthetic */ Companion(DefaultConstructorMarker defaultConstructorMarker) {
this();
}
public final Relay edit(File file, Source upstream, ByteString metadata, long bufferMaxSize) throws IOException {
Intrinsics.checkNotNullParameter(file, "file");
Intrinsics.checkNotNullParameter(upstream, "upstream");
Intrinsics.checkNotNullParameter(metadata, "metadata");
RandomAccessFile randomAccessFile = new RandomAccessFile(file, "rw");
Relay relay = new Relay(randomAccessFile, upstream, 0L, metadata, bufferMaxSize, null);
randomAccessFile.setLength(0L);
relay.writeHeader(Relay.PREFIX_DIRTY, -1L, -1L);
return relay;
}
public final Relay read(File file) throws IOException {
Intrinsics.checkNotNullParameter(file, "file");
RandomAccessFile randomAccessFile = new RandomAccessFile(file, "rw");
FileChannel channel = randomAccessFile.getChannel();
Intrinsics.checkNotNullExpressionValue(channel, "randomAccessFile.channel");
FileOperator fileOperator = new FileOperator(channel);
Buffer buffer = new Buffer();
fileOperator.read(0L, buffer, Relay.FILE_HEADER_SIZE);
if (!Intrinsics.areEqual(buffer.readByteString(Relay.PREFIX_CLEAN.size()), Relay.PREFIX_CLEAN)) {
throw new IOException("unreadable cache file");
}
long readLong = buffer.readLong();
long readLong2 = buffer.readLong();
Buffer buffer2 = new Buffer();
fileOperator.read(readLong + Relay.FILE_HEADER_SIZE, buffer2, readLong2);
return new Relay(randomAccessFile, null, readLong, buffer2.readByteString(), 0L, null);
}
}
}