ResponseBody.smali 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365
  1. .class public abstract Lokhttp3/ResponseBody;
  2. .super Ljava/lang/Object;
  3. .source ""
  4. # interfaces
  5. .implements Ljava/io/Closeable;
  6. # annotations
  7. .annotation system Ldalvik/annotation/MemberClasses;
  8. value = {
  9. Lokhttp3/ResponseBody$BomAwareReader;
  10. }
  11. .end annotation
  12. # instance fields
  13. .field private reader:Ljava/io/Reader;
  14. # direct methods
  15. .method public constructor <init>()V
  16. .locals 0
  17. invoke-direct {p0}, Ljava/lang/Object;-><init>()V
  18. return-void
  19. .end method
  20. .method private charset()Ljava/nio/charset/Charset;
  21. .locals 2
  22. invoke-virtual {p0}, Lokhttp3/ResponseBody;->contentType()Lokhttp3/MediaType;
  23. move-result-object v0
  24. if-eqz v0, :cond_0
  25. sget-object v1, Lokhttp3/internal/Util;->UTF_8:Ljava/nio/charset/Charset;
  26. invoke-virtual {v0, v1}, Lokhttp3/MediaType;->charset(Ljava/nio/charset/Charset;)Ljava/nio/charset/Charset;
  27. move-result-object v0
  28. goto :goto_0
  29. :cond_0
  30. sget-object v0, Lokhttp3/internal/Util;->UTF_8:Ljava/nio/charset/Charset;
  31. :goto_0
  32. return-object v0
  33. .end method
  34. .method public static create(Lokhttp3/MediaType;JLokio/BufferedSource;)Lokhttp3/ResponseBody;
  35. .locals 1
  36. if-eqz p3, :cond_0
  37. new-instance v0, Lokhttp3/ResponseBody$1;
  38. invoke-direct {v0, p0, p1, p2, p3}, Lokhttp3/ResponseBody$1;-><init>(Lokhttp3/MediaType;JLokio/BufferedSource;)V
  39. return-object v0
  40. :cond_0
  41. new-instance p0, Ljava/lang/NullPointerException;
  42. const-string p1, "source == null"
  43. invoke-direct {p0, p1}, Ljava/lang/NullPointerException;-><init>(Ljava/lang/String;)V
  44. throw p0
  45. .end method
  46. .method public static create(Lokhttp3/MediaType;Ljava/lang/String;)Lokhttp3/ResponseBody;
  47. .locals 2
  48. sget-object v0, Lokhttp3/internal/Util;->UTF_8:Ljava/nio/charset/Charset;
  49. if-eqz p0, :cond_0
  50. invoke-virtual {p0}, Lokhttp3/MediaType;->charset()Ljava/nio/charset/Charset;
  51. move-result-object v0
  52. if-nez v0, :cond_0
  53. sget-object v0, Lokhttp3/internal/Util;->UTF_8:Ljava/nio/charset/Charset;
  54. new-instance v1, Ljava/lang/StringBuilder;
  55. invoke-direct {v1}, Ljava/lang/StringBuilder;-><init>()V
  56. invoke-virtual {v1, p0}, Ljava/lang/StringBuilder;->append(Ljava/lang/Object;)Ljava/lang/StringBuilder;
  57. const-string p0, "; charset=utf-8"
  58. invoke-virtual {v1, p0}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;
  59. invoke-virtual {v1}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;
  60. move-result-object p0
  61. invoke-static {p0}, Lokhttp3/MediaType;->parse(Ljava/lang/String;)Lokhttp3/MediaType;
  62. move-result-object p0
  63. :cond_0
  64. new-instance v1, Lokio/Buffer;
  65. invoke-direct {v1}, Lokio/Buffer;-><init>()V
  66. invoke-virtual {v1, p1, v0}, Lokio/Buffer;->writeString(Ljava/lang/String;Ljava/nio/charset/Charset;)Lokio/Buffer;
  67. move-result-object p1
  68. invoke-virtual {p1}, Lokio/Buffer;->size()J
  69. move-result-wide v0
  70. invoke-static {p0, v0, v1, p1}, Lokhttp3/ResponseBody;->create(Lokhttp3/MediaType;JLokio/BufferedSource;)Lokhttp3/ResponseBody;
  71. move-result-object p0
  72. return-object p0
  73. .end method
  74. .method public static create(Lokhttp3/MediaType;[B)Lokhttp3/ResponseBody;
  75. .locals 3
  76. new-instance v0, Lokio/Buffer;
  77. invoke-direct {v0}, Lokio/Buffer;-><init>()V
  78. invoke-virtual {v0, p1}, Lokio/Buffer;->write([B)Lokio/Buffer;
  79. move-result-object v0
  80. array-length p1, p1
  81. int-to-long v1, p1
  82. invoke-static {p0, v1, v2, v0}, Lokhttp3/ResponseBody;->create(Lokhttp3/MediaType;JLokio/BufferedSource;)Lokhttp3/ResponseBody;
  83. move-result-object p0
  84. return-object p0
  85. .end method
  86. # virtual methods
  87. .method public final byteStream()Ljava/io/InputStream;
  88. .locals 1
  89. invoke-virtual {p0}, Lokhttp3/ResponseBody;->source()Lokio/BufferedSource;
  90. move-result-object v0
  91. invoke-interface {v0}, Lokio/BufferedSource;->inputStream()Ljava/io/InputStream;
  92. move-result-object v0
  93. return-object v0
  94. .end method
  95. .method public final bytes()[B
  96. .locals 6
  97. .annotation system Ldalvik/annotation/Throws;
  98. value = {
  99. Ljava/io/IOException;
  100. }
  101. .end annotation
  102. invoke-virtual {p0}, Lokhttp3/ResponseBody;->contentLength()J
  103. move-result-wide v0
  104. const-wide/32 v2, 0x7fffffff
  105. cmp-long v4, v0, v2
  106. if-gtz v4, :cond_2
  107. invoke-virtual {p0}, Lokhttp3/ResponseBody;->source()Lokio/BufferedSource;
  108. move-result-object v2
  109. :try_start_0
  110. invoke-interface {v2}, Lokio/BufferedSource;->readByteArray()[B
  111. move-result-object v3
  112. :try_end_0
  113. .catchall {:try_start_0 .. :try_end_0} :catchall_0
  114. invoke-static {v2}, Lokhttp3/internal/Util;->closeQuietly(Ljava/io/Closeable;)V
  115. const-wide/16 v4, -0x1
  116. cmp-long v2, v0, v4
  117. if-eqz v2, :cond_1
  118. array-length v2, v3
  119. int-to-long v4, v2
  120. cmp-long v2, v0, v4
  121. if-nez v2, :cond_0
  122. goto :goto_0
  123. :cond_0
  124. new-instance v2, Ljava/io/IOException;
  125. new-instance v4, Ljava/lang/StringBuilder;
  126. invoke-direct {v4}, Ljava/lang/StringBuilder;-><init>()V
  127. const-string v5, "Content-Length ("
  128. invoke-virtual {v4, v5}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;
  129. invoke-virtual {v4, v0, v1}, Ljava/lang/StringBuilder;->append(J)Ljava/lang/StringBuilder;
  130. const-string v0, ") and stream length ("
  131. invoke-virtual {v4, v0}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;
  132. array-length v0, v3
  133. invoke-virtual {v4, v0}, Ljava/lang/StringBuilder;->append(I)Ljava/lang/StringBuilder;
  134. const-string v0, ") disagree"
  135. invoke-virtual {v4, v0}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;
  136. invoke-virtual {v4}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;
  137. move-result-object v0
  138. invoke-direct {v2, v0}, Ljava/io/IOException;-><init>(Ljava/lang/String;)V
  139. throw v2
  140. :cond_1
  141. :goto_0
  142. return-object v3
  143. :catchall_0
  144. move-exception v0
  145. invoke-static {v2}, Lokhttp3/internal/Util;->closeQuietly(Ljava/io/Closeable;)V
  146. throw v0
  147. :cond_2
  148. new-instance v2, Ljava/io/IOException;
  149. new-instance v3, Ljava/lang/StringBuilder;
  150. invoke-direct {v3}, Ljava/lang/StringBuilder;-><init>()V
  151. const-string v4, "Cannot buffer entire body for content length: "
  152. invoke-virtual {v3, v4}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;
  153. invoke-virtual {v3, v0, v1}, Ljava/lang/StringBuilder;->append(J)Ljava/lang/StringBuilder;
  154. invoke-virtual {v3}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;
  155. move-result-object v0
  156. invoke-direct {v2, v0}, Ljava/io/IOException;-><init>(Ljava/lang/String;)V
  157. throw v2
  158. .end method
  159. .method public final charStream()Ljava/io/Reader;
  160. .locals 3
  161. iget-object v0, p0, Lokhttp3/ResponseBody;->reader:Ljava/io/Reader;
  162. if-eqz v0, :cond_0
  163. goto :goto_0
  164. :cond_0
  165. new-instance v0, Lokhttp3/ResponseBody$BomAwareReader;
  166. invoke-virtual {p0}, Lokhttp3/ResponseBody;->source()Lokio/BufferedSource;
  167. move-result-object v1
  168. invoke-direct {p0}, Lokhttp3/ResponseBody;->charset()Ljava/nio/charset/Charset;
  169. move-result-object v2
  170. invoke-direct {v0, v1, v2}, Lokhttp3/ResponseBody$BomAwareReader;-><init>(Lokio/BufferedSource;Ljava/nio/charset/Charset;)V
  171. iput-object v0, p0, Lokhttp3/ResponseBody;->reader:Ljava/io/Reader;
  172. :goto_0
  173. return-object v0
  174. .end method
  175. .method public close()V
  176. .locals 1
  177. invoke-virtual {p0}, Lokhttp3/ResponseBody;->source()Lokio/BufferedSource;
  178. move-result-object v0
  179. invoke-static {v0}, Lokhttp3/internal/Util;->closeQuietly(Ljava/io/Closeable;)V
  180. return-void
  181. .end method
  182. .method public abstract contentLength()J
  183. .end method
  184. .method public abstract contentType()Lokhttp3/MediaType;
  185. .end method
  186. .method public abstract source()Lokio/BufferedSource;
  187. .end method
  188. .method public final string()Ljava/lang/String;
  189. .locals 2
  190. .annotation system Ldalvik/annotation/Throws;
  191. value = {
  192. Ljava/io/IOException;
  193. }
  194. .end annotation
  195. invoke-virtual {p0}, Lokhttp3/ResponseBody;->source()Lokio/BufferedSource;
  196. move-result-object v0
  197. :try_start_0
  198. invoke-direct {p0}, Lokhttp3/ResponseBody;->charset()Ljava/nio/charset/Charset;
  199. move-result-object v1
  200. invoke-static {v0, v1}, Lokhttp3/internal/Util;->bomAwareCharset(Lokio/BufferedSource;Ljava/nio/charset/Charset;)Ljava/nio/charset/Charset;
  201. move-result-object v1
  202. invoke-interface {v0, v1}, Lokio/BufferedSource;->readString(Ljava/nio/charset/Charset;)Ljava/lang/String;
  203. move-result-object v1
  204. :try_end_0
  205. .catchall {:try_start_0 .. :try_end_0} :catchall_0
  206. invoke-static {v0}, Lokhttp3/internal/Util;->closeQuietly(Ljava/io/Closeable;)V
  207. return-object v1
  208. :catchall_0
  209. move-exception v1
  210. invoke-static {v0}, Lokhttp3/internal/Util;->closeQuietly(Ljava/io/Closeable;)V
  211. throw v1
  212. .end method