GzipSink.smali 7.6 KB

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