Relay.smali 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511
  1. .class final Lokhttp3/internal/cache2/Relay;
  2. .super Ljava/lang/Object;
  3. .source ""
  4. # annotations
  5. .annotation system Ldalvik/annotation/MemberClasses;
  6. value = {
  7. Lokhttp3/internal/cache2/Relay$RelaySource;
  8. }
  9. .end annotation
  10. # static fields
  11. .field private static final FILE_HEADER_SIZE:J = 0x20L
  12. .field static final PREFIX_CLEAN:Lokio/ByteString;
  13. .field static final PREFIX_DIRTY:Lokio/ByteString;
  14. .field private static final SOURCE_FILE:I = 0x2
  15. .field private static final SOURCE_UPSTREAM:I = 0x1
  16. # instance fields
  17. .field final buffer:Lokio/Buffer;
  18. .field final bufferMaxSize:J
  19. .field complete:Z
  20. .field file:Ljava/io/RandomAccessFile;
  21. .field private final metadata:Lokio/ByteString;
  22. .field sourceCount:I
  23. .field upstream:Lokio/Source;
  24. .field final upstreamBuffer:Lokio/Buffer;
  25. .field upstreamPos:J
  26. .field upstreamReader:Ljava/lang/Thread;
  27. # direct methods
  28. .method static constructor <clinit>()V
  29. .locals 1
  30. const-string v0, "OkHttp cache v1\n"
  31. invoke-static {v0}, Lokio/ByteString;->encodeUtf8(Ljava/lang/String;)Lokio/ByteString;
  32. move-result-object v0
  33. sput-object v0, Lokhttp3/internal/cache2/Relay;->PREFIX_CLEAN:Lokio/ByteString;
  34. const-string v0, "OkHttp DIRTY :(\n"
  35. invoke-static {v0}, Lokio/ByteString;->encodeUtf8(Ljava/lang/String;)Lokio/ByteString;
  36. move-result-object v0
  37. sput-object v0, Lokhttp3/internal/cache2/Relay;->PREFIX_DIRTY:Lokio/ByteString;
  38. return-void
  39. .end method
  40. .method private constructor <init>(Ljava/io/RandomAccessFile;Lokio/Source;JLokio/ByteString;J)V
  41. .locals 1
  42. invoke-direct {p0}, Ljava/lang/Object;-><init>()V
  43. new-instance v0, Lokio/Buffer;
  44. invoke-direct {v0}, Lokio/Buffer;-><init>()V
  45. iput-object v0, p0, Lokhttp3/internal/cache2/Relay;->upstreamBuffer:Lokio/Buffer;
  46. new-instance v0, Lokio/Buffer;
  47. invoke-direct {v0}, Lokio/Buffer;-><init>()V
  48. iput-object v0, p0, Lokhttp3/internal/cache2/Relay;->buffer:Lokio/Buffer;
  49. iput-object p1, p0, Lokhttp3/internal/cache2/Relay;->file:Ljava/io/RandomAccessFile;
  50. iput-object p2, p0, Lokhttp3/internal/cache2/Relay;->upstream:Lokio/Source;
  51. if-nez p2, :cond_0
  52. const/4 p1, 0x1
  53. goto :goto_0
  54. :cond_0
  55. const/4 p1, 0x0
  56. :goto_0
  57. iput-boolean p1, p0, Lokhttp3/internal/cache2/Relay;->complete:Z
  58. iput-wide p3, p0, Lokhttp3/internal/cache2/Relay;->upstreamPos:J
  59. iput-object p5, p0, Lokhttp3/internal/cache2/Relay;->metadata:Lokio/ByteString;
  60. iput-wide p6, p0, Lokhttp3/internal/cache2/Relay;->bufferMaxSize:J
  61. return-void
  62. .end method
  63. .method public static edit(Ljava/io/File;Lokio/Source;Lokio/ByteString;J)Lokhttp3/internal/cache2/Relay;
  64. .locals 9
  65. .annotation system Ldalvik/annotation/Throws;
  66. value = {
  67. Ljava/io/IOException;
  68. }
  69. .end annotation
  70. new-instance v8, Ljava/io/RandomAccessFile;
  71. const-string v0, "rw"
  72. invoke-direct {v8, p0, v0}, Ljava/io/RandomAccessFile;-><init>(Ljava/io/File;Ljava/lang/String;)V
  73. new-instance p0, Lokhttp3/internal/cache2/Relay;
  74. const-wide/16 v3, 0x0
  75. move-object v0, p0
  76. move-object v1, v8
  77. move-object v2, p1
  78. move-object v5, p2
  79. move-wide v6, p3
  80. invoke-direct/range {v0 .. v7}, Lokhttp3/internal/cache2/Relay;-><init>(Ljava/io/RandomAccessFile;Lokio/Source;JLokio/ByteString;J)V
  81. const-wide/16 p1, 0x0
  82. invoke-virtual {v8, p1, p2}, Ljava/io/RandomAccessFile;->setLength(J)V
  83. sget-object v2, Lokhttp3/internal/cache2/Relay;->PREFIX_DIRTY:Lokio/ByteString;
  84. const-wide/16 v3, -0x1
  85. const-wide/16 v5, -0x1
  86. move-object v1, p0
  87. invoke-direct/range {v1 .. v6}, Lokhttp3/internal/cache2/Relay;->writeHeader(Lokio/ByteString;JJ)V
  88. return-object p0
  89. .end method
  90. .method public static read(Ljava/io/File;)Lokhttp3/internal/cache2/Relay;
  91. .locals 10
  92. .annotation system Ldalvik/annotation/Throws;
  93. value = {
  94. Ljava/io/IOException;
  95. }
  96. .end annotation
  97. new-instance v1, Ljava/io/RandomAccessFile;
  98. const-string v0, "rw"
  99. invoke-direct {v1, p0, v0}, Ljava/io/RandomAccessFile;-><init>(Ljava/io/File;Ljava/lang/String;)V
  100. new-instance p0, Lokhttp3/internal/cache2/FileOperator;
  101. invoke-virtual {v1}, Ljava/io/RandomAccessFile;->getChannel()Ljava/nio/channels/FileChannel;
  102. move-result-object v0
  103. invoke-direct {p0, v0}, Lokhttp3/internal/cache2/FileOperator;-><init>(Ljava/nio/channels/FileChannel;)V
  104. new-instance v0, Lokio/Buffer;
  105. invoke-direct {v0}, Lokio/Buffer;-><init>()V
  106. const-wide/16 v3, 0x0
  107. const-wide/16 v6, 0x20
  108. move-object v2, p0
  109. move-object v5, v0
  110. invoke-virtual/range {v2 .. v7}, Lokhttp3/internal/cache2/FileOperator;->read(JLokio/Buffer;J)V
  111. sget-object v2, Lokhttp3/internal/cache2/Relay;->PREFIX_CLEAN:Lokio/ByteString;
  112. invoke-virtual {v2}, Lokio/ByteString;->size()I
  113. move-result v2
  114. int-to-long v2, v2
  115. invoke-virtual {v0, v2, v3}, Lokio/Buffer;->readByteString(J)Lokio/ByteString;
  116. move-result-object v2
  117. sget-object v3, Lokhttp3/internal/cache2/Relay;->PREFIX_CLEAN:Lokio/ByteString;
  118. invoke-virtual {v2, v3}, Lokio/ByteString;->equals(Ljava/lang/Object;)Z
  119. move-result v2
  120. if-eqz v2, :cond_0
  121. invoke-virtual {v0}, Lokio/Buffer;->readLong()J
  122. move-result-wide v8
  123. invoke-virtual {v0}, Lokio/Buffer;->readLong()J
  124. move-result-wide v6
  125. new-instance v0, Lokio/Buffer;
  126. invoke-direct {v0}, Lokio/Buffer;-><init>()V
  127. const-wide/16 v2, 0x20
  128. add-long v4, v8, v2
  129. move-object v2, p0
  130. move-wide v3, v4
  131. move-object v5, v0
  132. invoke-virtual/range {v2 .. v7}, Lokhttp3/internal/cache2/FileOperator;->read(JLokio/Buffer;J)V
  133. invoke-virtual {v0}, Lokio/Buffer;->readByteString()Lokio/ByteString;
  134. move-result-object v5
  135. new-instance p0, Lokhttp3/internal/cache2/Relay;
  136. const/4 v2, 0x0
  137. const-wide/16 v6, 0x0
  138. move-object v0, p0
  139. move-wide v3, v8
  140. invoke-direct/range {v0 .. v7}, Lokhttp3/internal/cache2/Relay;-><init>(Ljava/io/RandomAccessFile;Lokio/Source;JLokio/ByteString;J)V
  141. return-object p0
  142. :cond_0
  143. new-instance p0, Ljava/io/IOException;
  144. const-string v0, "unreadable cache file"
  145. invoke-direct {p0, v0}, Ljava/io/IOException;-><init>(Ljava/lang/String;)V
  146. throw p0
  147. .end method
  148. .method private writeHeader(Lokio/ByteString;JJ)V
  149. .locals 6
  150. .annotation system Ldalvik/annotation/Throws;
  151. value = {
  152. Ljava/io/IOException;
  153. }
  154. .end annotation
  155. new-instance v3, Lokio/Buffer;
  156. invoke-direct {v3}, Lokio/Buffer;-><init>()V
  157. invoke-virtual {v3, p1}, Lokio/Buffer;->write(Lokio/ByteString;)Lokio/Buffer;
  158. invoke-virtual {v3, p2, p3}, Lokio/Buffer;->writeLong(J)Lokio/Buffer;
  159. invoke-virtual {v3, p4, p5}, Lokio/Buffer;->writeLong(J)Lokio/Buffer;
  160. invoke-virtual {v3}, Lokio/Buffer;->size()J
  161. move-result-wide p1
  162. const-wide/16 p3, 0x20
  163. cmp-long p5, p1, p3
  164. if-nez p5, :cond_0
  165. new-instance v0, Lokhttp3/internal/cache2/FileOperator;
  166. iget-object p1, p0, Lokhttp3/internal/cache2/Relay;->file:Ljava/io/RandomAccessFile;
  167. invoke-virtual {p1}, Ljava/io/RandomAccessFile;->getChannel()Ljava/nio/channels/FileChannel;
  168. move-result-object p1
  169. invoke-direct {v0, p1}, Lokhttp3/internal/cache2/FileOperator;-><init>(Ljava/nio/channels/FileChannel;)V
  170. const-wide/16 v1, 0x0
  171. const-wide/16 v4, 0x20
  172. invoke-virtual/range {v0 .. v5}, Lokhttp3/internal/cache2/FileOperator;->write(JLokio/Buffer;J)V
  173. return-void
  174. :cond_0
  175. new-instance p1, Ljava/lang/IllegalArgumentException;
  176. invoke-direct {p1}, Ljava/lang/IllegalArgumentException;-><init>()V
  177. throw p1
  178. .end method
  179. .method private writeMetadata(J)V
  180. .locals 6
  181. .annotation system Ldalvik/annotation/Throws;
  182. value = {
  183. Ljava/io/IOException;
  184. }
  185. .end annotation
  186. new-instance v3, Lokio/Buffer;
  187. invoke-direct {v3}, Lokio/Buffer;-><init>()V
  188. iget-object v0, p0, Lokhttp3/internal/cache2/Relay;->metadata:Lokio/ByteString;
  189. invoke-virtual {v3, v0}, Lokio/Buffer;->write(Lokio/ByteString;)Lokio/Buffer;
  190. new-instance v0, Lokhttp3/internal/cache2/FileOperator;
  191. iget-object v1, p0, Lokhttp3/internal/cache2/Relay;->file:Ljava/io/RandomAccessFile;
  192. invoke-virtual {v1}, Ljava/io/RandomAccessFile;->getChannel()Ljava/nio/channels/FileChannel;
  193. move-result-object v1
  194. invoke-direct {v0, v1}, Lokhttp3/internal/cache2/FileOperator;-><init>(Ljava/nio/channels/FileChannel;)V
  195. const-wide/16 v1, 0x20
  196. add-long/2addr v1, p1
  197. iget-object p1, p0, Lokhttp3/internal/cache2/Relay;->metadata:Lokio/ByteString;
  198. invoke-virtual {p1}, Lokio/ByteString;->size()I
  199. move-result p1
  200. int-to-long v4, p1
  201. invoke-virtual/range {v0 .. v5}, Lokhttp3/internal/cache2/FileOperator;->write(JLokio/Buffer;J)V
  202. return-void
  203. .end method
  204. # virtual methods
  205. .method commit(J)V
  206. .locals 8
  207. .annotation system Ldalvik/annotation/Throws;
  208. value = {
  209. Ljava/io/IOException;
  210. }
  211. .end annotation
  212. invoke-direct {p0, p1, p2}, Lokhttp3/internal/cache2/Relay;->writeMetadata(J)V
  213. iget-object v0, p0, Lokhttp3/internal/cache2/Relay;->file:Ljava/io/RandomAccessFile;
  214. invoke-virtual {v0}, Ljava/io/RandomAccessFile;->getChannel()Ljava/nio/channels/FileChannel;
  215. move-result-object v0
  216. const/4 v1, 0x0
  217. invoke-virtual {v0, v1}, Ljava/nio/channels/FileChannel;->force(Z)V
  218. sget-object v3, Lokhttp3/internal/cache2/Relay;->PREFIX_CLEAN:Lokio/ByteString;
  219. iget-object v0, p0, Lokhttp3/internal/cache2/Relay;->metadata:Lokio/ByteString;
  220. invoke-virtual {v0}, Lokio/ByteString;->size()I
  221. move-result v0
  222. int-to-long v6, v0
  223. move-object v2, p0
  224. move-wide v4, p1
  225. invoke-direct/range {v2 .. v7}, Lokhttp3/internal/cache2/Relay;->writeHeader(Lokio/ByteString;JJ)V
  226. iget-object p1, p0, Lokhttp3/internal/cache2/Relay;->file:Ljava/io/RandomAccessFile;
  227. invoke-virtual {p1}, Ljava/io/RandomAccessFile;->getChannel()Ljava/nio/channels/FileChannel;
  228. move-result-object p1
  229. invoke-virtual {p1, v1}, Ljava/nio/channels/FileChannel;->force(Z)V
  230. monitor-enter p0
  231. const/4 p1, 0x1
  232. :try_start_0
  233. iput-boolean p1, p0, Lokhttp3/internal/cache2/Relay;->complete:Z
  234. monitor-exit p0
  235. :try_end_0
  236. .catchall {:try_start_0 .. :try_end_0} :catchall_0
  237. iget-object p1, p0, Lokhttp3/internal/cache2/Relay;->upstream:Lokio/Source;
  238. invoke-static {p1}, Lokhttp3/internal/Util;->closeQuietly(Ljava/io/Closeable;)V
  239. const/4 p1, 0x0
  240. iput-object p1, p0, Lokhttp3/internal/cache2/Relay;->upstream:Lokio/Source;
  241. return-void
  242. :catchall_0
  243. move-exception p1
  244. :try_start_1
  245. monitor-exit p0
  246. :try_end_1
  247. .catchall {:try_start_1 .. :try_end_1} :catchall_0
  248. throw p1
  249. .end method
  250. .method isClosed()Z
  251. .locals 1
  252. iget-object v0, p0, Lokhttp3/internal/cache2/Relay;->file:Ljava/io/RandomAccessFile;
  253. if-nez v0, :cond_0
  254. const/4 v0, 0x1
  255. goto :goto_0
  256. :cond_0
  257. const/4 v0, 0x0
  258. :goto_0
  259. return v0
  260. .end method
  261. .method public metadata()Lokio/ByteString;
  262. .locals 1
  263. iget-object v0, p0, Lokhttp3/internal/cache2/Relay;->metadata:Lokio/ByteString;
  264. return-object v0
  265. .end method
  266. .method public newSource()Lokio/Source;
  267. .locals 1
  268. monitor-enter p0
  269. :try_start_0
  270. iget-object v0, p0, Lokhttp3/internal/cache2/Relay;->file:Ljava/io/RandomAccessFile;
  271. if-nez v0, :cond_0
  272. const/4 v0, 0x0
  273. monitor-exit p0
  274. return-object v0
  275. :cond_0
  276. iget v0, p0, Lokhttp3/internal/cache2/Relay;->sourceCount:I
  277. add-int/lit8 v0, v0, 0x1
  278. iput v0, p0, Lokhttp3/internal/cache2/Relay;->sourceCount:I
  279. monitor-exit p0
  280. :try_end_0
  281. .catchall {:try_start_0 .. :try_end_0} :catchall_0
  282. new-instance v0, Lokhttp3/internal/cache2/Relay$RelaySource;
  283. invoke-direct {v0, p0}, Lokhttp3/internal/cache2/Relay$RelaySource;-><init>(Lokhttp3/internal/cache2/Relay;)V
  284. return-object v0
  285. :catchall_0
  286. move-exception v0
  287. :try_start_1
  288. monitor-exit p0
  289. :try_end_1
  290. .catchall {:try_start_1 .. :try_end_1} :catchall_0
  291. throw v0
  292. .end method