InflaterSource.smali 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399
  1. .class public final Lokio/InflaterSource;
  2. .super Ljava/lang/Object;
  3. .source ""
  4. # interfaces
  5. .implements Lokio/Source;
  6. # instance fields
  7. .field private bufferBytesHeldByInflater:I
  8. .field private closed:Z
  9. .field private final inflater:Ljava/util/zip/Inflater;
  10. .field private final source:Lokio/BufferedSource;
  11. # direct methods
  12. .method constructor <init>(Lokio/BufferedSource;Ljava/util/zip/Inflater;)V
  13. .locals 0
  14. invoke-direct {p0}, Ljava/lang/Object;-><init>()V
  15. if-eqz p1, :cond_1
  16. if-eqz p2, :cond_0
  17. iput-object p1, p0, Lokio/InflaterSource;->source:Lokio/BufferedSource;
  18. iput-object p2, p0, Lokio/InflaterSource;->inflater:Ljava/util/zip/Inflater;
  19. return-void
  20. :cond_0
  21. new-instance p1, Ljava/lang/IllegalArgumentException;
  22. const-string p2, "inflater == null"
  23. invoke-direct {p1, p2}, Ljava/lang/IllegalArgumentException;-><init>(Ljava/lang/String;)V
  24. throw p1
  25. :cond_1
  26. new-instance p1, Ljava/lang/IllegalArgumentException;
  27. const-string p2, "source == null"
  28. invoke-direct {p1, p2}, Ljava/lang/IllegalArgumentException;-><init>(Ljava/lang/String;)V
  29. throw p1
  30. .end method
  31. .method public constructor <init>(Lokio/Source;Ljava/util/zip/Inflater;)V
  32. .locals 0
  33. invoke-static {p1}, Lokio/Okio;->buffer(Lokio/Source;)Lokio/BufferedSource;
  34. move-result-object p1
  35. invoke-direct {p0, p1, p2}, Lokio/InflaterSource;-><init>(Lokio/BufferedSource;Ljava/util/zip/Inflater;)V
  36. return-void
  37. .end method
  38. .method private releaseInflatedBytes()V
  39. .locals 4
  40. .annotation system Ldalvik/annotation/Throws;
  41. value = {
  42. Ljava/io/IOException;
  43. }
  44. .end annotation
  45. iget v0, p0, Lokio/InflaterSource;->bufferBytesHeldByInflater:I
  46. if-nez v0, :cond_0
  47. return-void
  48. :cond_0
  49. iget-object v1, p0, Lokio/InflaterSource;->inflater:Ljava/util/zip/Inflater;
  50. invoke-virtual {v1}, Ljava/util/zip/Inflater;->getRemaining()I
  51. move-result v1
  52. sub-int/2addr v0, v1
  53. iget v1, p0, Lokio/InflaterSource;->bufferBytesHeldByInflater:I
  54. sub-int/2addr v1, v0
  55. iput v1, p0, Lokio/InflaterSource;->bufferBytesHeldByInflater:I
  56. iget-object v1, p0, Lokio/InflaterSource;->source:Lokio/BufferedSource;
  57. int-to-long v2, v0
  58. invoke-interface {v1, v2, v3}, Lokio/BufferedSource;->skip(J)V
  59. return-void
  60. .end method
  61. # virtual methods
  62. .method public close()V
  63. .locals 1
  64. .annotation system Ldalvik/annotation/Throws;
  65. value = {
  66. Ljava/io/IOException;
  67. }
  68. .end annotation
  69. iget-boolean v0, p0, Lokio/InflaterSource;->closed:Z
  70. if-eqz v0, :cond_0
  71. return-void
  72. :cond_0
  73. iget-object v0, p0, Lokio/InflaterSource;->inflater:Ljava/util/zip/Inflater;
  74. invoke-virtual {v0}, Ljava/util/zip/Inflater;->end()V
  75. const/4 v0, 0x1
  76. iput-boolean v0, p0, Lokio/InflaterSource;->closed:Z
  77. iget-object v0, p0, Lokio/InflaterSource;->source:Lokio/BufferedSource;
  78. invoke-interface {v0}, Lokio/Source;->close()V
  79. return-void
  80. .end method
  81. .method public read(Lokio/Buffer;J)J
  82. .locals 4
  83. .annotation system Ldalvik/annotation/Throws;
  84. value = {
  85. Ljava/io/IOException;
  86. }
  87. .end annotation
  88. const-wide/16 v0, 0x0
  89. cmp-long v2, p2, v0
  90. if-ltz v2, :cond_7
  91. iget-boolean v2, p0, Lokio/InflaterSource;->closed:Z
  92. if-nez v2, :cond_6
  93. cmp-long v2, p2, v0
  94. if-nez v2, :cond_0
  95. return-wide v0
  96. :cond_0
  97. :goto_0
  98. invoke-virtual {p0}, Lokio/InflaterSource;->refill()Z
  99. move-result p2
  100. const/4 p3, 0x1
  101. :try_start_0
  102. invoke-virtual {p1, p3}, Lokio/Buffer;->writableSegment(I)Lokio/Segment;
  103. move-result-object p3
  104. iget-object v0, p0, Lokio/InflaterSource;->inflater:Ljava/util/zip/Inflater;
  105. iget-object v1, p3, Lokio/Segment;->data:[B
  106. iget v2, p3, Lokio/Segment;->limit:I
  107. iget v3, p3, Lokio/Segment;->limit:I
  108. rsub-int v3, v3, 0x2000
  109. invoke-virtual {v0, v1, v2, v3}, Ljava/util/zip/Inflater;->inflate([BII)I
  110. move-result v0
  111. if-lez v0, :cond_1
  112. iget p2, p3, Lokio/Segment;->limit:I
  113. add-int/2addr p2, v0
  114. iput p2, p3, Lokio/Segment;->limit:I
  115. iget-wide p2, p1, Lokio/Buffer;->size:J
  116. int-to-long v0, v0
  117. add-long/2addr p2, v0
  118. iput-wide p2, p1, Lokio/Buffer;->size:J
  119. return-wide v0
  120. :cond_1
  121. iget-object v0, p0, Lokio/InflaterSource;->inflater:Ljava/util/zip/Inflater;
  122. invoke-virtual {v0}, Ljava/util/zip/Inflater;->finished()Z
  123. move-result v0
  124. if-nez v0, :cond_4
  125. iget-object v0, p0, Lokio/InflaterSource;->inflater:Ljava/util/zip/Inflater;
  126. invoke-virtual {v0}, Ljava/util/zip/Inflater;->needsDictionary()Z
  127. move-result v0
  128. if-eqz v0, :cond_2
  129. goto :goto_1
  130. :cond_2
  131. if-nez p2, :cond_3
  132. goto :goto_0
  133. :cond_3
  134. new-instance p1, Ljava/io/EOFException;
  135. const-string p2, "source exhausted prematurely"
  136. invoke-direct {p1, p2}, Ljava/io/EOFException;-><init>(Ljava/lang/String;)V
  137. throw p1
  138. :cond_4
  139. :goto_1
  140. invoke-direct {p0}, Lokio/InflaterSource;->releaseInflatedBytes()V
  141. iget p2, p3, Lokio/Segment;->pos:I
  142. iget v0, p3, Lokio/Segment;->limit:I
  143. if-ne p2, v0, :cond_5
  144. invoke-virtual {p3}, Lokio/Segment;->pop()Lokio/Segment;
  145. move-result-object p2
  146. iput-object p2, p1, Lokio/Buffer;->head:Lokio/Segment;
  147. invoke-static {p3}, Lokio/SegmentPool;->recycle(Lokio/Segment;)V
  148. :try_end_0
  149. .catch Ljava/util/zip/DataFormatException; {:try_start_0 .. :try_end_0} :catch_0
  150. :cond_5
  151. const-wide/16 p1, -0x1
  152. return-wide p1
  153. :catch_0
  154. move-exception p1
  155. new-instance p2, Ljava/io/IOException;
  156. invoke-direct {p2, p1}, Ljava/io/IOException;-><init>(Ljava/lang/Throwable;)V
  157. throw p2
  158. :cond_6
  159. new-instance p1, Ljava/lang/IllegalStateException;
  160. const-string p2, "closed"
  161. invoke-direct {p1, p2}, Ljava/lang/IllegalStateException;-><init>(Ljava/lang/String;)V
  162. throw p1
  163. :cond_7
  164. new-instance p1, Ljava/lang/IllegalArgumentException;
  165. new-instance v0, Ljava/lang/StringBuilder;
  166. invoke-direct {v0}, Ljava/lang/StringBuilder;-><init>()V
  167. const-string v1, "byteCount < 0: "
  168. invoke-virtual {v0, v1}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;
  169. invoke-virtual {v0, p2, p3}, Ljava/lang/StringBuilder;->append(J)Ljava/lang/StringBuilder;
  170. invoke-virtual {v0}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;
  171. move-result-object p2
  172. invoke-direct {p1, p2}, Ljava/lang/IllegalArgumentException;-><init>(Ljava/lang/String;)V
  173. goto :goto_3
  174. :goto_2
  175. throw p1
  176. :goto_3
  177. goto :goto_2
  178. .end method
  179. .method public refill()Z
  180. .locals 5
  181. .annotation system Ldalvik/annotation/Throws;
  182. value = {
  183. Ljava/io/IOException;
  184. }
  185. .end annotation
  186. iget-object v0, p0, Lokio/InflaterSource;->inflater:Ljava/util/zip/Inflater;
  187. invoke-virtual {v0}, Ljava/util/zip/Inflater;->needsInput()Z
  188. move-result v0
  189. const/4 v1, 0x0
  190. if-nez v0, :cond_0
  191. return v1
  192. :cond_0
  193. invoke-direct {p0}, Lokio/InflaterSource;->releaseInflatedBytes()V
  194. iget-object v0, p0, Lokio/InflaterSource;->inflater:Ljava/util/zip/Inflater;
  195. invoke-virtual {v0}, Ljava/util/zip/Inflater;->getRemaining()I
  196. move-result v0
  197. if-nez v0, :cond_2
  198. iget-object v0, p0, Lokio/InflaterSource;->source:Lokio/BufferedSource;
  199. invoke-interface {v0}, Lokio/BufferedSource;->exhausted()Z
  200. move-result v0
  201. if-eqz v0, :cond_1
  202. const/4 v0, 0x1
  203. return v0
  204. :cond_1
  205. iget-object v0, p0, Lokio/InflaterSource;->source:Lokio/BufferedSource;
  206. invoke-interface {v0}, Lokio/BufferedSource;->buffer()Lokio/Buffer;
  207. move-result-object v0
  208. iget-object v0, v0, Lokio/Buffer;->head:Lokio/Segment;
  209. iget v2, v0, Lokio/Segment;->limit:I
  210. iget v3, v0, Lokio/Segment;->pos:I
  211. sub-int/2addr v2, v3
  212. iput v2, p0, Lokio/InflaterSource;->bufferBytesHeldByInflater:I
  213. iget-object v2, p0, Lokio/InflaterSource;->inflater:Ljava/util/zip/Inflater;
  214. iget-object v0, v0, Lokio/Segment;->data:[B
  215. iget v4, p0, Lokio/InflaterSource;->bufferBytesHeldByInflater:I
  216. invoke-virtual {v2, v0, v3, v4}, Ljava/util/zip/Inflater;->setInput([BII)V
  217. return v1
  218. :cond_2
  219. new-instance v0, Ljava/lang/IllegalStateException;
  220. const-string v1, "?"
  221. invoke-direct {v0, v1}, Ljava/lang/IllegalStateException;-><init>(Ljava/lang/String;)V
  222. throw v0
  223. .end method
  224. .method public timeout()Lokio/Timeout;
  225. .locals 1
  226. iget-object v0, p0, Lokio/InflaterSource;->source:Lokio/BufferedSource;
  227. invoke-interface {v0}, Lokio/Source;->timeout()Lokio/Timeout;
  228. move-result-object v0
  229. return-object v0
  230. .end method