FileOperator.smali 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. .class final Lokhttp3/internal/cache2/FileOperator;
  2. .super Ljava/lang/Object;
  3. .source ""
  4. # static fields
  5. .field private static final BUFFER_SIZE:I = 0x2000
  6. # instance fields
  7. .field private final byteArray:[B
  8. .field private final byteBuffer:Ljava/nio/ByteBuffer;
  9. .field private final fileChannel:Ljava/nio/channels/FileChannel;
  10. # direct methods
  11. .method constructor <init>(Ljava/nio/channels/FileChannel;)V
  12. .locals 1
  13. invoke-direct {p0}, Ljava/lang/Object;-><init>()V
  14. const/16 v0, 0x2000
  15. new-array v0, v0, [B
  16. iput-object v0, p0, Lokhttp3/internal/cache2/FileOperator;->byteArray:[B
  17. iget-object v0, p0, Lokhttp3/internal/cache2/FileOperator;->byteArray:[B
  18. invoke-static {v0}, Ljava/nio/ByteBuffer;->wrap([B)Ljava/nio/ByteBuffer;
  19. move-result-object v0
  20. iput-object v0, p0, Lokhttp3/internal/cache2/FileOperator;->byteBuffer:Ljava/nio/ByteBuffer;
  21. iput-object p1, p0, Lokhttp3/internal/cache2/FileOperator;->fileChannel:Ljava/nio/channels/FileChannel;
  22. return-void
  23. .end method
  24. # virtual methods
  25. .method public read(JLokio/Buffer;J)V
  26. .locals 5
  27. .annotation system Ldalvik/annotation/Throws;
  28. value = {
  29. Ljava/io/IOException;
  30. }
  31. .end annotation
  32. const-wide/16 v0, 0x0
  33. cmp-long v2, p4, v0
  34. if-ltz v2, :cond_2
  35. :goto_0
  36. cmp-long v2, p4, v0
  37. if-lez v2, :cond_1
  38. :try_start_0
  39. iget-object v2, p0, Lokhttp3/internal/cache2/FileOperator;->byteBuffer:Ljava/nio/ByteBuffer;
  40. const-wide/16 v3, 0x2000
  41. invoke-static {v3, v4, p4, p5}, Ljava/lang/Math;->min(JJ)J
  42. move-result-wide v3
  43. long-to-int v4, v3
  44. invoke-virtual {v2, v4}, Ljava/nio/ByteBuffer;->limit(I)Ljava/nio/Buffer;
  45. iget-object v2, p0, Lokhttp3/internal/cache2/FileOperator;->fileChannel:Ljava/nio/channels/FileChannel;
  46. iget-object v3, p0, Lokhttp3/internal/cache2/FileOperator;->byteBuffer:Ljava/nio/ByteBuffer;
  47. invoke-virtual {v2, v3, p1, p2}, Ljava/nio/channels/FileChannel;->read(Ljava/nio/ByteBuffer;J)I
  48. move-result v2
  49. const/4 v3, -0x1
  50. if-eq v2, v3, :cond_0
  51. iget-object v2, p0, Lokhttp3/internal/cache2/FileOperator;->byteBuffer:Ljava/nio/ByteBuffer;
  52. invoke-virtual {v2}, Ljava/nio/ByteBuffer;->position()I
  53. move-result v2
  54. iget-object v3, p0, Lokhttp3/internal/cache2/FileOperator;->byteArray:[B
  55. const/4 v4, 0x0
  56. invoke-virtual {p3, v3, v4, v2}, Lokio/Buffer;->write([BII)Lokio/Buffer;
  57. :try_end_0
  58. .catchall {:try_start_0 .. :try_end_0} :catchall_0
  59. int-to-long v2, v2
  60. add-long/2addr p1, v2
  61. sub-long/2addr p4, v2
  62. iget-object v2, p0, Lokhttp3/internal/cache2/FileOperator;->byteBuffer:Ljava/nio/ByteBuffer;
  63. invoke-virtual {v2}, Ljava/nio/ByteBuffer;->clear()Ljava/nio/Buffer;
  64. goto :goto_0
  65. :cond_0
  66. :try_start_1
  67. new-instance p1, Ljava/io/EOFException;
  68. invoke-direct {p1}, Ljava/io/EOFException;-><init>()V
  69. throw p1
  70. :try_end_1
  71. .catchall {:try_start_1 .. :try_end_1} :catchall_0
  72. :catchall_0
  73. move-exception p1
  74. iget-object p2, p0, Lokhttp3/internal/cache2/FileOperator;->byteBuffer:Ljava/nio/ByteBuffer;
  75. invoke-virtual {p2}, Ljava/nio/ByteBuffer;->clear()Ljava/nio/Buffer;
  76. throw p1
  77. :cond_1
  78. return-void
  79. :cond_2
  80. new-instance p1, Ljava/lang/IndexOutOfBoundsException;
  81. invoke-direct {p1}, Ljava/lang/IndexOutOfBoundsException;-><init>()V
  82. goto :goto_2
  83. :goto_1
  84. throw p1
  85. :goto_2
  86. goto :goto_1
  87. .end method
  88. .method public write(JLokio/Buffer;J)V
  89. .locals 6
  90. .annotation system Ldalvik/annotation/Throws;
  91. value = {
  92. Ljava/io/IOException;
  93. }
  94. .end annotation
  95. const-wide/16 v0, 0x0
  96. cmp-long v2, p4, v0
  97. if-ltz v2, :cond_2
  98. invoke-virtual {p3}, Lokio/Buffer;->size()J
  99. move-result-wide v2
  100. cmp-long v4, p4, v2
  101. if-gtz v4, :cond_2
  102. :goto_0
  103. cmp-long v2, p4, v0
  104. if-lez v2, :cond_1
  105. const-wide/16 v2, 0x2000
  106. :try_start_0
  107. invoke-static {v2, v3, p4, p5}, Ljava/lang/Math;->min(JJ)J
  108. move-result-wide v2
  109. long-to-int v3, v2
  110. iget-object v2, p0, Lokhttp3/internal/cache2/FileOperator;->byteArray:[B
  111. const/4 v4, 0x0
  112. invoke-virtual {p3, v2, v4, v3}, Lokio/Buffer;->read([BII)I
  113. iget-object v2, p0, Lokhttp3/internal/cache2/FileOperator;->byteBuffer:Ljava/nio/ByteBuffer;
  114. invoke-virtual {v2, v3}, Ljava/nio/ByteBuffer;->limit(I)Ljava/nio/Buffer;
  115. :cond_0
  116. iget-object v2, p0, Lokhttp3/internal/cache2/FileOperator;->fileChannel:Ljava/nio/channels/FileChannel;
  117. iget-object v4, p0, Lokhttp3/internal/cache2/FileOperator;->byteBuffer:Ljava/nio/ByteBuffer;
  118. invoke-virtual {v2, v4, p1, p2}, Ljava/nio/channels/FileChannel;->write(Ljava/nio/ByteBuffer;J)I
  119. move-result v2
  120. int-to-long v4, v2
  121. add-long/2addr p1, v4
  122. iget-object v2, p0, Lokhttp3/internal/cache2/FileOperator;->byteBuffer:Ljava/nio/ByteBuffer;
  123. invoke-virtual {v2}, Ljava/nio/ByteBuffer;->hasRemaining()Z
  124. move-result v2
  125. :try_end_0
  126. .catchall {:try_start_0 .. :try_end_0} :catchall_0
  127. if-nez v2, :cond_0
  128. int-to-long v2, v3
  129. sub-long/2addr p4, v2
  130. iget-object v2, p0, Lokhttp3/internal/cache2/FileOperator;->byteBuffer:Ljava/nio/ByteBuffer;
  131. invoke-virtual {v2}, Ljava/nio/ByteBuffer;->clear()Ljava/nio/Buffer;
  132. goto :goto_0
  133. :catchall_0
  134. move-exception p1
  135. iget-object p2, p0, Lokhttp3/internal/cache2/FileOperator;->byteBuffer:Ljava/nio/ByteBuffer;
  136. invoke-virtual {p2}, Ljava/nio/ByteBuffer;->clear()Ljava/nio/Buffer;
  137. throw p1
  138. :cond_1
  139. return-void
  140. :cond_2
  141. new-instance p1, Ljava/lang/IndexOutOfBoundsException;
  142. invoke-direct {p1}, Ljava/lang/IndexOutOfBoundsException;-><init>()V
  143. goto :goto_2
  144. :goto_1
  145. throw p1
  146. :goto_2
  147. goto :goto_1
  148. .end method