DeflaterSink.smali 8.3 KB

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