Relay.smali
.class final Lokhttp3/internal/cache2/Relay;
.super Ljava/lang/Object;
.source "Relay.java"
# annotations
.annotation system Ldalvik/annotation/MemberClasses;
value = {
Lokhttp3/internal/cache2/Relay$RelaySource;
}
.end annotation
# static fields
.field private static final FILE_HEADER_SIZE:J = 0x20L
.field static final PREFIX_CLEAN:Lokio/ByteString;
.field static final PREFIX_DIRTY:Lokio/ByteString;
.field private static final SOURCE_FILE:I = 0x2
.field private static final SOURCE_UPSTREAM:I = 0x1
# instance fields
.field final buffer:Lokio/Buffer;
.field final bufferMaxSize:J
.field complete:Z
.field file:Ljava/io/RandomAccessFile;
.field private final metadata:Lokio/ByteString;
.field sourceCount:I
.field upstream:Lokio/Source;
.field final upstreamBuffer:Lokio/Buffer;
.field upstreamPos:J
.field upstreamReader:Ljava/lang/Thread;
# direct methods
.method static constructor <clinit>()V
.registers 1
const-string v0, "OkHttp cache v1\n"
.line 45
invoke-static {v0}, Lokio/ByteString;->encodeUtf8(Ljava/lang/String;)Lokio/ByteString;
move-result-object v0
sput-object v0, Lokhttp3/internal/cache2/Relay;->PREFIX_CLEAN:Lokio/ByteString;
const-string v0, "OkHttp DIRTY :(\n"
.line 46
invoke-static {v0}, Lokio/ByteString;->encodeUtf8(Ljava/lang/String;)Lokio/ByteString;
move-result-object v0
sput-object v0, Lokhttp3/internal/cache2/Relay;->PREFIX_DIRTY:Lokio/ByteString;
return-void
.end method
.method private constructor <init>(Ljava/io/RandomAccessFile;Lokio/Source;JLokio/ByteString;J)V
.registers 9
.line 107
invoke-direct {p0}, Ljava/lang/Object;-><init>()V
.line 79
new-instance v0, Lokio/Buffer;
invoke-direct {v0}, Lokio/Buffer;-><init>()V
iput-object v0, p0, Lokhttp3/internal/cache2/Relay;->upstreamBuffer:Lokio/Buffer;
.line 94
new-instance v0, Lokio/Buffer;
invoke-direct {v0}, Lokio/Buffer;-><init>()V
iput-object v0, p0, Lokhttp3/internal/cache2/Relay;->buffer:Lokio/Buffer;
.line 108
iput-object p1, p0, Lokhttp3/internal/cache2/Relay;->file:Ljava/io/RandomAccessFile;
.line 109
iput-object p2, p0, Lokhttp3/internal/cache2/Relay;->upstream:Lokio/Source;
if-nez p2, :cond_19
const/4 p1, 0x1
goto :goto_1a
:cond_19
const/4 p1, 0x0
.line 110
:goto_1a
iput-boolean p1, p0, Lokhttp3/internal/cache2/Relay;->complete:Z
.line 111
iput-wide p3, p0, Lokhttp3/internal/cache2/Relay;->upstreamPos:J
.line 112
iput-object p5, p0, Lokhttp3/internal/cache2/Relay;->metadata:Lokio/ByteString;
.line 113
iput-wide p6, p0, Lokhttp3/internal/cache2/Relay;->bufferMaxSize:J
return-void
.end method
.method public static edit(Ljava/io/File;Lokio/Source;Lokio/ByteString;J)Lokhttp3/internal/cache2/Relay;
.registers 14
.annotation system Ldalvik/annotation/Throws;
value = {
Ljava/io/IOException;
}
.end annotation
.line 126
new-instance v8, Ljava/io/RandomAccessFile;
const-string v0, "rw"
invoke-direct {v8, p0, v0}, Ljava/io/RandomAccessFile;-><init>(Ljava/io/File;Ljava/lang/String;)V
.line 127
new-instance p0, Lokhttp3/internal/cache2/Relay;
const-wide/16 v3, 0x0
move-object v0, p0
move-object v1, v8
move-object v2, p1
move-object v5, p2
move-wide v6, p3
invoke-direct/range {v0 .. v7}, Lokhttp3/internal/cache2/Relay;-><init>(Ljava/io/RandomAccessFile;Lokio/Source;JLokio/ByteString;J)V
const-wide/16 p1, 0x0
.line 130
invoke-virtual {v8, p1, p2}, Ljava/io/RandomAccessFile;->setLength(J)V
.line 131
sget-object v2, Lokhttp3/internal/cache2/Relay;->PREFIX_DIRTY:Lokio/ByteString;
const-wide/16 v3, -0x1
const-wide/16 v5, -0x1
move-object v1, p0
invoke-direct/range {v1 .. v6}, Lokhttp3/internal/cache2/Relay;->writeHeader(Lokio/ByteString;JJ)V
return-object p0
.end method
.method public static read(Ljava/io/File;)Lokhttp3/internal/cache2/Relay;
.registers 11
.annotation system Ldalvik/annotation/Throws;
value = {
Ljava/io/IOException;
}
.end annotation
.line 144
new-instance v1, Ljava/io/RandomAccessFile;
const-string v0, "rw"
invoke-direct {v1, p0, v0}, Ljava/io/RandomAccessFile;-><init>(Ljava/io/File;Ljava/lang/String;)V
.line 145
new-instance p0, Lokhttp3/internal/cache2/FileOperator;
invoke-virtual {v1}, Ljava/io/RandomAccessFile;->getChannel()Ljava/nio/channels/FileChannel;
move-result-object v0
invoke-direct {p0, v0}, Lokhttp3/internal/cache2/FileOperator;-><init>(Ljava/nio/channels/FileChannel;)V
.line 148
new-instance v0, Lokio/Buffer;
invoke-direct {v0}, Lokio/Buffer;-><init>()V
const-wide/16 v3, 0x0
const-wide/16 v6, 0x20
move-object v2, p0
move-object v5, v0
.line 149
invoke-virtual/range {v2 .. v7}, Lokhttp3/internal/cache2/FileOperator;->read(JLokio/Buffer;J)V
.line 150
sget-object v2, Lokhttp3/internal/cache2/Relay;->PREFIX_CLEAN:Lokio/ByteString;
invoke-virtual {v2}, Lokio/ByteString;->size()I
move-result v3
int-to-long v3, v3
invoke-virtual {v0, v3, v4}, Lokio/Buffer;->readByteString(J)Lokio/ByteString;
move-result-object v3
.line 151
invoke-virtual {v3, v2}, Lokio/ByteString;->equals(Ljava/lang/Object;)Z
move-result v2
if-eqz v2, :cond_55
.line 152
invoke-virtual {v0}, Lokio/Buffer;->readLong()J
move-result-wide v8
.line 153
invoke-virtual {v0}, Lokio/Buffer;->readLong()J
move-result-wide v6
.line 156
new-instance v0, Lokio/Buffer;
invoke-direct {v0}, Lokio/Buffer;-><init>()V
const-wide/16 v2, 0x20
add-long v4, v8, v2
move-object v2, p0
move-wide v3, v4
move-object v5, v0
.line 157
invoke-virtual/range {v2 .. v7}, Lokhttp3/internal/cache2/FileOperator;->read(JLokio/Buffer;J)V
.line 158
invoke-virtual {v0}, Lokio/Buffer;->readByteString()Lokio/ByteString;
move-result-object v5
.line 161
new-instance p0, Lokhttp3/internal/cache2/Relay;
const/4 v2, 0x0
const-wide/16 v6, 0x0
move-object v0, p0
move-wide v3, v8
invoke-direct/range {v0 .. v7}, Lokhttp3/internal/cache2/Relay;-><init>(Ljava/io/RandomAccessFile;Lokio/Source;JLokio/ByteString;J)V
return-object p0
.line 151
:cond_55
new-instance p0, Ljava/io/IOException;
const-string v0, "unreadable cache file"
invoke-direct {p0, v0}, Ljava/io/IOException;-><init>(Ljava/lang/String;)V
throw p0
.end method
.method private writeHeader(Lokio/ByteString;JJ)V
.registers 12
.annotation system Ldalvik/annotation/Throws;
value = {
Ljava/io/IOException;
}
.end annotation
.line 166
new-instance v3, Lokio/Buffer;
invoke-direct {v3}, Lokio/Buffer;-><init>()V
.line 167
invoke-virtual {v3, p1}, Lokio/Buffer;->write(Lokio/ByteString;)Lokio/Buffer;
.line 168
invoke-virtual {v3, p2, p3}, Lokio/Buffer;->writeLong(J)Lokio/Buffer;
.line 169
invoke-virtual {v3, p4, p5}, Lokio/Buffer;->writeLong(J)Lokio/Buffer;
.line 170
invoke-virtual {v3}, Lokio/Buffer;->size()J
move-result-wide p1
const-wide/16 p3, 0x20
cmp-long p5, p1, p3
if-nez p5, :cond_2b
.line 172
new-instance v0, Lokhttp3/internal/cache2/FileOperator;
iget-object p1, p0, Lokhttp3/internal/cache2/Relay;->file:Ljava/io/RandomAccessFile;
invoke-virtual {p1}, Ljava/io/RandomAccessFile;->getChannel()Ljava/nio/channels/FileChannel;
move-result-object p1
invoke-direct {v0, p1}, Lokhttp3/internal/cache2/FileOperator;-><init>(Ljava/nio/channels/FileChannel;)V
const-wide/16 v1, 0x0
const-wide/16 v4, 0x20
.line 173
invoke-virtual/range {v0 .. v5}, Lokhttp3/internal/cache2/FileOperator;->write(JLokio/Buffer;J)V
return-void
.line 170
:cond_2b
new-instance p1, Ljava/lang/IllegalArgumentException;
invoke-direct {p1}, Ljava/lang/IllegalArgumentException;-><init>()V
throw p1
.end method
.method private writeMetadata(J)V
.registers 9
.annotation system Ldalvik/annotation/Throws;
value = {
Ljava/io/IOException;
}
.end annotation
.line 177
new-instance v3, Lokio/Buffer;
invoke-direct {v3}, Lokio/Buffer;-><init>()V
.line 178
iget-object v0, p0, Lokhttp3/internal/cache2/Relay;->metadata:Lokio/ByteString;
invoke-virtual {v3, v0}, Lokio/Buffer;->write(Lokio/ByteString;)Lokio/Buffer;
.line 180
new-instance v0, Lokhttp3/internal/cache2/FileOperator;
iget-object v1, p0, Lokhttp3/internal/cache2/Relay;->file:Ljava/io/RandomAccessFile;
invoke-virtual {v1}, Ljava/io/RandomAccessFile;->getChannel()Ljava/nio/channels/FileChannel;
move-result-object v1
invoke-direct {v0, v1}, Lokhttp3/internal/cache2/FileOperator;-><init>(Ljava/nio/channels/FileChannel;)V
const-wide/16 v1, 0x20
add-long/2addr v1, p1
.line 181
iget-object p1, p0, Lokhttp3/internal/cache2/Relay;->metadata:Lokio/ByteString;
invoke-virtual {p1}, Lokio/ByteString;->size()I
move-result p1
int-to-long v4, p1
invoke-virtual/range {v0 .. v5}, Lokhttp3/internal/cache2/FileOperator;->write(JLokio/Buffer;J)V
return-void
.end method
# virtual methods
.method commit(J)V
.registers 11
.annotation system Ldalvik/annotation/Throws;
value = {
Ljava/io/IOException;
}
.end annotation
.line 186
invoke-direct {p0, p1, p2}, Lokhttp3/internal/cache2/Relay;->writeMetadata(J)V
.line 187
iget-object v0, p0, Lokhttp3/internal/cache2/Relay;->file:Ljava/io/RandomAccessFile;
invoke-virtual {v0}, Ljava/io/RandomAccessFile;->getChannel()Ljava/nio/channels/FileChannel;
move-result-object v0
const/4 v1, 0x0
invoke-virtual {v0, v1}, Ljava/nio/channels/FileChannel;->force(Z)V
.line 190
sget-object v3, Lokhttp3/internal/cache2/Relay;->PREFIX_CLEAN:Lokio/ByteString;
iget-object v0, p0, Lokhttp3/internal/cache2/Relay;->metadata:Lokio/ByteString;
invoke-virtual {v0}, Lokio/ByteString;->size()I
move-result v0
int-to-long v6, v0
move-object v2, p0
move-wide v4, p1
invoke-direct/range {v2 .. v7}, Lokhttp3/internal/cache2/Relay;->writeHeader(Lokio/ByteString;JJ)V
.line 191
iget-object p1, p0, Lokhttp3/internal/cache2/Relay;->file:Ljava/io/RandomAccessFile;
invoke-virtual {p1}, Ljava/io/RandomAccessFile;->getChannel()Ljava/nio/channels/FileChannel;
move-result-object p1
invoke-virtual {p1, v1}, Ljava/nio/channels/FileChannel;->force(Z)V
.line 194
monitor-enter p0
const/4 p1, 0x1
.line 195
:try_start_26
iput-boolean p1, p0, Lokhttp3/internal/cache2/Relay;->complete:Z
.line 196
monitor-exit p0
:try_end_29
.catchall {:try_start_26 .. :try_end_29} :catchall_32
.line 198
iget-object p1, p0, Lokhttp3/internal/cache2/Relay;->upstream:Lokio/Source;
invoke-static {p1}, Lokhttp3/internal/Util;->closeQuietly(Ljava/io/Closeable;)V
const/4 p1, 0x0
.line 199
iput-object p1, p0, Lokhttp3/internal/cache2/Relay;->upstream:Lokio/Source;
return-void
:catchall_32
move-exception p1
.line 196
:try_start_33
monitor-exit p0
:try_end_34
.catchall {:try_start_33 .. :try_end_34} :catchall_32
throw p1
.end method
.method isClosed()Z
.registers 2
.line 203
iget-object v0, p0, Lokhttp3/internal/cache2/Relay;->file:Ljava/io/RandomAccessFile;
if-nez v0, :cond_6
const/4 v0, 0x1
goto :goto_7
:cond_6
const/4 v0, 0x0
:goto_7
return v0
.end method
.method public metadata()Lokio/ByteString;
.registers 2
.line 207
iget-object v0, p0, Lokhttp3/internal/cache2/Relay;->metadata:Lokio/ByteString;
return-object v0
.end method
.method public newSource()Lokio/Source;
.registers 2
.line 216
monitor-enter p0
.line 217
:try_start_1
iget-object v0, p0, Lokhttp3/internal/cache2/Relay;->file:Ljava/io/RandomAccessFile;
if-nez v0, :cond_8
const/4 v0, 0x0
monitor-exit p0
return-object v0
.line 218
:cond_8
iget v0, p0, Lokhttp3/internal/cache2/Relay;->sourceCount:I
add-int/lit8 v0, v0, 0x1
iput v0, p0, Lokhttp3/internal/cache2/Relay;->sourceCount:I
.line 219
monitor-exit p0
:try_end_f
.catchall {:try_start_1 .. :try_end_f} :catchall_15
.line 221
new-instance v0, Lokhttp3/internal/cache2/Relay$RelaySource;
invoke-direct {v0, p0}, Lokhttp3/internal/cache2/Relay$RelaySource;-><init>(Lokhttp3/internal/cache2/Relay;)V
return-object v0
:catchall_15
move-exception v0
.line 219
:try_start_16
monitor-exit p0
:try_end_17
.catchall {:try_start_16 .. :try_end_17} :catchall_15
throw v0
.end method