GzipSource.smali 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696
  1. .class public final Lokio/GzipSource;
  2. .super Ljava/lang/Object;
  3. .source ""
  4. # interfaces
  5. .implements Lokio/Source;
  6. # static fields
  7. .field private static final FCOMMENT:B = 0x4t
  8. .field private static final FEXTRA:B = 0x2t
  9. .field private static final FHCRC:B = 0x1t
  10. .field private static final FNAME:B = 0x3t
  11. .field private static final SECTION_BODY:B = 0x1t
  12. .field private static final SECTION_DONE:B = 0x3t
  13. .field private static final SECTION_HEADER:B = 0x0t
  14. .field private static final SECTION_TRAILER:B = 0x2t
  15. # instance fields
  16. .field private final crc:Ljava/util/zip/CRC32;
  17. .field private final inflater:Ljava/util/zip/Inflater;
  18. .field private final inflaterSource:Lokio/InflaterSource;
  19. .field private section:I
  20. .field private final source:Lokio/BufferedSource;
  21. # direct methods
  22. .method public constructor <init>(Lokio/Source;)V
  23. .locals 2
  24. invoke-direct {p0}, Ljava/lang/Object;-><init>()V
  25. const/4 v0, 0x0
  26. iput v0, p0, Lokio/GzipSource;->section:I
  27. new-instance v0, Ljava/util/zip/CRC32;
  28. invoke-direct {v0}, Ljava/util/zip/CRC32;-><init>()V
  29. iput-object v0, p0, Lokio/GzipSource;->crc:Ljava/util/zip/CRC32;
  30. if-eqz p1, :cond_0
  31. new-instance v0, Ljava/util/zip/Inflater;
  32. const/4 v1, 0x1
  33. invoke-direct {v0, v1}, Ljava/util/zip/Inflater;-><init>(Z)V
  34. iput-object v0, p0, Lokio/GzipSource;->inflater:Ljava/util/zip/Inflater;
  35. invoke-static {p1}, Lokio/Okio;->buffer(Lokio/Source;)Lokio/BufferedSource;
  36. move-result-object p1
  37. iput-object p1, p0, Lokio/GzipSource;->source:Lokio/BufferedSource;
  38. new-instance p1, Lokio/InflaterSource;
  39. iget-object v0, p0, Lokio/GzipSource;->source:Lokio/BufferedSource;
  40. iget-object v1, p0, Lokio/GzipSource;->inflater:Ljava/util/zip/Inflater;
  41. invoke-direct {p1, v0, v1}, Lokio/InflaterSource;-><init>(Lokio/BufferedSource;Ljava/util/zip/Inflater;)V
  42. iput-object p1, p0, Lokio/GzipSource;->inflaterSource:Lokio/InflaterSource;
  43. return-void
  44. :cond_0
  45. new-instance p1, Ljava/lang/IllegalArgumentException;
  46. const-string v0, "source == null"
  47. invoke-direct {p1, v0}, Ljava/lang/IllegalArgumentException;-><init>(Ljava/lang/String;)V
  48. throw p1
  49. .end method
  50. .method private checkEqual(Ljava/lang/String;II)V
  51. .locals 3
  52. .annotation system Ldalvik/annotation/Throws;
  53. value = {
  54. Ljava/io/IOException;
  55. }
  56. .end annotation
  57. if-ne p3, p2, :cond_0
  58. return-void
  59. :cond_0
  60. new-instance v0, Ljava/io/IOException;
  61. const/4 v1, 0x3
  62. new-array v1, v1, [Ljava/lang/Object;
  63. const/4 v2, 0x0
  64. aput-object p1, v1, v2
  65. const/4 p1, 0x1
  66. invoke-static {p3}, Ljava/lang/Integer;->valueOf(I)Ljava/lang/Integer;
  67. move-result-object p3
  68. aput-object p3, v1, p1
  69. const/4 p1, 0x2
  70. invoke-static {p2}, Ljava/lang/Integer;->valueOf(I)Ljava/lang/Integer;
  71. move-result-object p2
  72. aput-object p2, v1, p1
  73. const-string p1, "%s: actual 0x%08x != expected 0x%08x"
  74. invoke-static {p1, v1}, Ljava/lang/String;->format(Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/String;
  75. move-result-object p1
  76. invoke-direct {v0, p1}, Ljava/io/IOException;-><init>(Ljava/lang/String;)V
  77. throw v0
  78. .end method
  79. .method private consumeHeader()V
  80. .locals 17
  81. .annotation system Ldalvik/annotation/Throws;
  82. value = {
  83. Ljava/io/IOException;
  84. }
  85. .end annotation
  86. move-object/from16 v6, p0
  87. iget-object v0, v6, Lokio/GzipSource;->source:Lokio/BufferedSource;
  88. const-wide/16 v1, 0xa
  89. invoke-interface {v0, v1, v2}, Lokio/BufferedSource;->require(J)V
  90. iget-object v0, v6, Lokio/GzipSource;->source:Lokio/BufferedSource;
  91. invoke-interface {v0}, Lokio/BufferedSource;->buffer()Lokio/Buffer;
  92. move-result-object v0
  93. const-wide/16 v1, 0x3
  94. invoke-virtual {v0, v1, v2}, Lokio/Buffer;->getByte(J)B
  95. move-result v7
  96. shr-int/lit8 v0, v7, 0x1
  97. const/4 v8, 0x1
  98. and-int/2addr v0, v8
  99. const/4 v9, 0x0
  100. if-ne v0, v8, :cond_0
  101. const/4 v10, 0x1
  102. goto :goto_0
  103. :cond_0
  104. const/4 v10, 0x0
  105. :goto_0
  106. if-eqz v10, :cond_1
  107. iget-object v0, v6, Lokio/GzipSource;->source:Lokio/BufferedSource;
  108. invoke-interface {v0}, Lokio/BufferedSource;->buffer()Lokio/Buffer;
  109. move-result-object v1
  110. const-wide/16 v2, 0x0
  111. const-wide/16 v4, 0xa
  112. move-object/from16 v0, p0
  113. invoke-direct/range {v0 .. v5}, Lokio/GzipSource;->updateCrc(Lokio/Buffer;JJ)V
  114. :cond_1
  115. iget-object v0, v6, Lokio/GzipSource;->source:Lokio/BufferedSource;
  116. invoke-interface {v0}, Lokio/BufferedSource;->readShort()S
  117. move-result v0
  118. const/16 v1, 0x1f8b
  119. const-string v2, "ID1ID2"
  120. invoke-direct {v6, v2, v1, v0}, Lokio/GzipSource;->checkEqual(Ljava/lang/String;II)V
  121. iget-object v0, v6, Lokio/GzipSource;->source:Lokio/BufferedSource;
  122. const-wide/16 v1, 0x8
  123. invoke-interface {v0, v1, v2}, Lokio/BufferedSource;->skip(J)V
  124. shr-int/lit8 v0, v7, 0x2
  125. and-int/2addr v0, v8
  126. if-ne v0, v8, :cond_4
  127. iget-object v0, v6, Lokio/GzipSource;->source:Lokio/BufferedSource;
  128. const-wide/16 v1, 0x2
  129. invoke-interface {v0, v1, v2}, Lokio/BufferedSource;->require(J)V
  130. if-eqz v10, :cond_2
  131. iget-object v0, v6, Lokio/GzipSource;->source:Lokio/BufferedSource;
  132. invoke-interface {v0}, Lokio/BufferedSource;->buffer()Lokio/Buffer;
  133. move-result-object v1
  134. const-wide/16 v2, 0x0
  135. const-wide/16 v4, 0x2
  136. move-object/from16 v0, p0
  137. invoke-direct/range {v0 .. v5}, Lokio/GzipSource;->updateCrc(Lokio/Buffer;JJ)V
  138. :cond_2
  139. iget-object v0, v6, Lokio/GzipSource;->source:Lokio/BufferedSource;
  140. invoke-interface {v0}, Lokio/BufferedSource;->buffer()Lokio/Buffer;
  141. move-result-object v0
  142. invoke-virtual {v0}, Lokio/Buffer;->readShortLe()S
  143. move-result v0
  144. iget-object v1, v6, Lokio/GzipSource;->source:Lokio/BufferedSource;
  145. int-to-long v11, v0
  146. invoke-interface {v1, v11, v12}, Lokio/BufferedSource;->require(J)V
  147. if-eqz v10, :cond_3
  148. iget-object v0, v6, Lokio/GzipSource;->source:Lokio/BufferedSource;
  149. invoke-interface {v0}, Lokio/BufferedSource;->buffer()Lokio/Buffer;
  150. move-result-object v1
  151. const-wide/16 v2, 0x0
  152. move-object/from16 v0, p0
  153. move-wide v4, v11
  154. invoke-direct/range {v0 .. v5}, Lokio/GzipSource;->updateCrc(Lokio/Buffer;JJ)V
  155. :cond_3
  156. iget-object v0, v6, Lokio/GzipSource;->source:Lokio/BufferedSource;
  157. invoke-interface {v0, v11, v12}, Lokio/BufferedSource;->skip(J)V
  158. :cond_4
  159. shr-int/lit8 v0, v7, 0x3
  160. and-int/2addr v0, v8
  161. const-wide/16 v11, -0x1
  162. const-wide/16 v13, 0x1
  163. if-ne v0, v8, :cond_7
  164. iget-object v0, v6, Lokio/GzipSource;->source:Lokio/BufferedSource;
  165. invoke-interface {v0, v9}, Lokio/BufferedSource;->indexOf(B)J
  166. move-result-wide v15
  167. cmp-long v0, v15, v11
  168. if-eqz v0, :cond_6
  169. if-eqz v10, :cond_5
  170. iget-object v0, v6, Lokio/GzipSource;->source:Lokio/BufferedSource;
  171. invoke-interface {v0}, Lokio/BufferedSource;->buffer()Lokio/Buffer;
  172. move-result-object v1
  173. const-wide/16 v2, 0x0
  174. add-long v4, v15, v13
  175. move-object/from16 v0, p0
  176. invoke-direct/range {v0 .. v5}, Lokio/GzipSource;->updateCrc(Lokio/Buffer;JJ)V
  177. :cond_5
  178. iget-object v0, v6, Lokio/GzipSource;->source:Lokio/BufferedSource;
  179. add-long v1, v15, v13
  180. invoke-interface {v0, v1, v2}, Lokio/BufferedSource;->skip(J)V
  181. goto :goto_1
  182. :cond_6
  183. new-instance v0, Ljava/io/EOFException;
  184. invoke-direct {v0}, Ljava/io/EOFException;-><init>()V
  185. throw v0
  186. :cond_7
  187. :goto_1
  188. shr-int/lit8 v0, v7, 0x4
  189. and-int/2addr v0, v8
  190. if-ne v0, v8, :cond_a
  191. iget-object v0, v6, Lokio/GzipSource;->source:Lokio/BufferedSource;
  192. invoke-interface {v0, v9}, Lokio/BufferedSource;->indexOf(B)J
  193. move-result-wide v7
  194. cmp-long v0, v7, v11
  195. if-eqz v0, :cond_9
  196. if-eqz v10, :cond_8
  197. iget-object v0, v6, Lokio/GzipSource;->source:Lokio/BufferedSource;
  198. invoke-interface {v0}, Lokio/BufferedSource;->buffer()Lokio/Buffer;
  199. move-result-object v1
  200. const-wide/16 v2, 0x0
  201. add-long v4, v7, v13
  202. move-object/from16 v0, p0
  203. invoke-direct/range {v0 .. v5}, Lokio/GzipSource;->updateCrc(Lokio/Buffer;JJ)V
  204. :cond_8
  205. iget-object v0, v6, Lokio/GzipSource;->source:Lokio/BufferedSource;
  206. add-long/2addr v7, v13
  207. invoke-interface {v0, v7, v8}, Lokio/BufferedSource;->skip(J)V
  208. goto :goto_2
  209. :cond_9
  210. new-instance v0, Ljava/io/EOFException;
  211. invoke-direct {v0}, Ljava/io/EOFException;-><init>()V
  212. throw v0
  213. :cond_a
  214. :goto_2
  215. if-eqz v10, :cond_b
  216. iget-object v0, v6, Lokio/GzipSource;->source:Lokio/BufferedSource;
  217. invoke-interface {v0}, Lokio/BufferedSource;->readShortLe()S
  218. move-result v0
  219. iget-object v1, v6, Lokio/GzipSource;->crc:Ljava/util/zip/CRC32;
  220. invoke-virtual {v1}, Ljava/util/zip/CRC32;->getValue()J
  221. move-result-wide v1
  222. long-to-int v2, v1
  223. int-to-short v1, v2
  224. const-string v2, "FHCRC"
  225. invoke-direct {v6, v2, v0, v1}, Lokio/GzipSource;->checkEqual(Ljava/lang/String;II)V
  226. iget-object v0, v6, Lokio/GzipSource;->crc:Ljava/util/zip/CRC32;
  227. invoke-virtual {v0}, Ljava/util/zip/CRC32;->reset()V
  228. :cond_b
  229. return-void
  230. .end method
  231. .method private consumeTrailer()V
  232. .locals 3
  233. .annotation system Ldalvik/annotation/Throws;
  234. value = {
  235. Ljava/io/IOException;
  236. }
  237. .end annotation
  238. iget-object v0, p0, Lokio/GzipSource;->source:Lokio/BufferedSource;
  239. invoke-interface {v0}, Lokio/BufferedSource;->readIntLe()I
  240. move-result v0
  241. iget-object v1, p0, Lokio/GzipSource;->crc:Ljava/util/zip/CRC32;
  242. invoke-virtual {v1}, Ljava/util/zip/CRC32;->getValue()J
  243. move-result-wide v1
  244. long-to-int v2, v1
  245. const-string v1, "CRC"
  246. invoke-direct {p0, v1, v0, v2}, Lokio/GzipSource;->checkEqual(Ljava/lang/String;II)V
  247. iget-object v0, p0, Lokio/GzipSource;->source:Lokio/BufferedSource;
  248. invoke-interface {v0}, Lokio/BufferedSource;->readIntLe()I
  249. move-result v0
  250. iget-object v1, p0, Lokio/GzipSource;->inflater:Ljava/util/zip/Inflater;
  251. invoke-virtual {v1}, Ljava/util/zip/Inflater;->getBytesWritten()J
  252. move-result-wide v1
  253. long-to-int v2, v1
  254. const-string v1, "ISIZE"
  255. invoke-direct {p0, v1, v0, v2}, Lokio/GzipSource;->checkEqual(Ljava/lang/String;II)V
  256. return-void
  257. .end method
  258. .method private updateCrc(Lokio/Buffer;JJ)V
  259. .locals 5
  260. iget-object p1, p1, Lokio/Buffer;->head:Lokio/Segment;
  261. :goto_0
  262. iget v0, p1, Lokio/Segment;->limit:I
  263. iget v1, p1, Lokio/Segment;->pos:I
  264. sub-int v2, v0, v1
  265. int-to-long v2, v2
  266. cmp-long v4, p2, v2
  267. if-ltz v4, :cond_0
  268. sub-int/2addr v0, v1
  269. int-to-long v0, v0
  270. sub-long/2addr p2, v0
  271. iget-object p1, p1, Lokio/Segment;->next:Lokio/Segment;
  272. goto :goto_0
  273. :cond_0
  274. const-wide/16 v0, 0x0
  275. :goto_1
  276. cmp-long v2, p4, v0
  277. if-lez v2, :cond_1
  278. iget v2, p1, Lokio/Segment;->pos:I
  279. int-to-long v2, v2
  280. add-long/2addr v2, p2
  281. long-to-int p2, v2
  282. iget p3, p1, Lokio/Segment;->limit:I
  283. sub-int/2addr p3, p2
  284. int-to-long v2, p3
  285. invoke-static {v2, v3, p4, p5}, Ljava/lang/Math;->min(JJ)J
  286. move-result-wide v2
  287. long-to-int p3, v2
  288. iget-object v2, p0, Lokio/GzipSource;->crc:Ljava/util/zip/CRC32;
  289. iget-object v3, p1, Lokio/Segment;->data:[B
  290. invoke-virtual {v2, v3, p2, p3}, Ljava/util/zip/CRC32;->update([BII)V
  291. int-to-long p2, p3
  292. sub-long/2addr p4, p2
  293. iget-object p1, p1, Lokio/Segment;->next:Lokio/Segment;
  294. move-wide p2, v0
  295. goto :goto_1
  296. :cond_1
  297. return-void
  298. .end method
  299. # virtual methods
  300. .method public close()V
  301. .locals 1
  302. .annotation system Ldalvik/annotation/Throws;
  303. value = {
  304. Ljava/io/IOException;
  305. }
  306. .end annotation
  307. iget-object v0, p0, Lokio/GzipSource;->inflaterSource:Lokio/InflaterSource;
  308. invoke-virtual {v0}, Lokio/InflaterSource;->close()V
  309. return-void
  310. .end method
  311. .method public read(Lokio/Buffer;J)J
  312. .locals 11
  313. .annotation system Ldalvik/annotation/Throws;
  314. value = {
  315. Ljava/io/IOException;
  316. }
  317. .end annotation
  318. const-wide/16 v0, 0x0
  319. cmp-long v2, p2, v0
  320. if-ltz v2, :cond_6
  321. cmp-long v2, p2, v0
  322. if-nez v2, :cond_0
  323. return-wide v0
  324. :cond_0
  325. iget v0, p0, Lokio/GzipSource;->section:I
  326. const/4 v1, 0x1
  327. if-nez v0, :cond_1
  328. invoke-direct {p0}, Lokio/GzipSource;->consumeHeader()V
  329. iput v1, p0, Lokio/GzipSource;->section:I
  330. :cond_1
  331. iget v0, p0, Lokio/GzipSource;->section:I
  332. const-wide/16 v2, -0x1
  333. const/4 v4, 0x2
  334. if-ne v0, v1, :cond_3
  335. iget-wide v7, p1, Lokio/Buffer;->size:J
  336. iget-object v0, p0, Lokio/GzipSource;->inflaterSource:Lokio/InflaterSource;
  337. invoke-virtual {v0, p1, p2, p3}, Lokio/InflaterSource;->read(Lokio/Buffer;J)J
  338. move-result-wide p2
  339. cmp-long v0, p2, v2
  340. if-eqz v0, :cond_2
  341. move-object v5, p0
  342. move-object v6, p1
  343. move-wide v9, p2
  344. invoke-direct/range {v5 .. v10}, Lokio/GzipSource;->updateCrc(Lokio/Buffer;JJ)V
  345. return-wide p2
  346. :cond_2
  347. iput v4, p0, Lokio/GzipSource;->section:I
  348. :cond_3
  349. iget p1, p0, Lokio/GzipSource;->section:I
  350. if-ne p1, v4, :cond_5
  351. invoke-direct {p0}, Lokio/GzipSource;->consumeTrailer()V
  352. const/4 p1, 0x3
  353. iput p1, p0, Lokio/GzipSource;->section:I
  354. iget-object p1, p0, Lokio/GzipSource;->source:Lokio/BufferedSource;
  355. invoke-interface {p1}, Lokio/BufferedSource;->exhausted()Z
  356. move-result p1
  357. if-eqz p1, :cond_4
  358. goto :goto_0
  359. :cond_4
  360. new-instance p1, Ljava/io/IOException;
  361. const-string p2, "gzip finished without exhausting source"
  362. invoke-direct {p1, p2}, Ljava/io/IOException;-><init>(Ljava/lang/String;)V
  363. throw p1
  364. :cond_5
  365. :goto_0
  366. return-wide v2
  367. :cond_6
  368. new-instance p1, Ljava/lang/IllegalArgumentException;
  369. new-instance v0, Ljava/lang/StringBuilder;
  370. invoke-direct {v0}, Ljava/lang/StringBuilder;-><init>()V
  371. const-string v1, "byteCount < 0: "
  372. invoke-virtual {v0, v1}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;
  373. invoke-virtual {v0, p2, p3}, Ljava/lang/StringBuilder;->append(J)Ljava/lang/StringBuilder;
  374. invoke-virtual {v0}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;
  375. move-result-object p2
  376. invoke-direct {p1, p2}, Ljava/lang/IllegalArgumentException;-><init>(Ljava/lang/String;)V
  377. throw p1
  378. .end method
  379. .method public timeout()Lokio/Timeout;
  380. .locals 1
  381. iget-object v0, p0, Lokio/GzipSource;->source:Lokio/BufferedSource;
  382. invoke-interface {v0}, Lokio/Source;->timeout()Lokio/Timeout;
  383. move-result-object v0
  384. return-object v0
  385. .end method