123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352 |
- .class public final Lokio/GzipSink;
- .super Ljava/lang/Object;
- .source ""
- # interfaces
- .implements Lokio/Sink;
- # instance fields
- .field private closed:Z
- .field private final crc:Ljava/util/zip/CRC32;
- .field private final deflater:Ljava/util/zip/Deflater;
- .field private final deflaterSink:Lokio/DeflaterSink;
- .field private final sink:Lokio/BufferedSink;
- # direct methods
- .method public constructor <init>(Lokio/Sink;)V
- .locals 3
- invoke-direct {p0}, Ljava/lang/Object;-><init>()V
- new-instance v0, Ljava/util/zip/CRC32;
- invoke-direct {v0}, Ljava/util/zip/CRC32;-><init>()V
- iput-object v0, p0, Lokio/GzipSink;->crc:Ljava/util/zip/CRC32;
- if-eqz p1, :cond_0
- new-instance v0, Ljava/util/zip/Deflater;
- const/4 v1, -0x1
- const/4 v2, 0x1
- invoke-direct {v0, v1, v2}, Ljava/util/zip/Deflater;-><init>(IZ)V
- iput-object v0, p0, Lokio/GzipSink;->deflater:Ljava/util/zip/Deflater;
- invoke-static {p1}, Lokio/Okio;->buffer(Lokio/Sink;)Lokio/BufferedSink;
- move-result-object p1
- iput-object p1, p0, Lokio/GzipSink;->sink:Lokio/BufferedSink;
- new-instance p1, Lokio/DeflaterSink;
- iget-object v0, p0, Lokio/GzipSink;->sink:Lokio/BufferedSink;
- iget-object v1, p0, Lokio/GzipSink;->deflater:Ljava/util/zip/Deflater;
- invoke-direct {p1, v0, v1}, Lokio/DeflaterSink;-><init>(Lokio/BufferedSink;Ljava/util/zip/Deflater;)V
- iput-object p1, p0, Lokio/GzipSink;->deflaterSink:Lokio/DeflaterSink;
- invoke-direct {p0}, Lokio/GzipSink;->writeHeader()V
- return-void
- :cond_0
- new-instance p1, Ljava/lang/IllegalArgumentException;
- const-string v0, "sink == null"
- invoke-direct {p1, v0}, Ljava/lang/IllegalArgumentException;-><init>(Ljava/lang/String;)V
- throw p1
- .end method
- .method private updateCrc(Lokio/Buffer;J)V
- .locals 4
- iget-object p1, p1, Lokio/Buffer;->head:Lokio/Segment;
- :goto_0
- const-wide/16 v0, 0x0
- cmp-long v2, p2, v0
- if-lez v2, :cond_0
- iget v0, p1, Lokio/Segment;->limit:I
- iget v1, p1, Lokio/Segment;->pos:I
- sub-int/2addr v0, v1
- int-to-long v0, v0
- invoke-static {p2, p3, v0, v1}, Ljava/lang/Math;->min(JJ)J
- move-result-wide v0
- long-to-int v1, v0
- iget-object v0, p0, Lokio/GzipSink;->crc:Ljava/util/zip/CRC32;
- iget-object v2, p1, Lokio/Segment;->data:[B
- iget v3, p1, Lokio/Segment;->pos:I
- invoke-virtual {v0, v2, v3, v1}, Ljava/util/zip/CRC32;->update([BII)V
- int-to-long v0, v1
- sub-long/2addr p2, v0
- iget-object p1, p1, Lokio/Segment;->next:Lokio/Segment;
- goto :goto_0
- :cond_0
- return-void
- .end method
- .method private writeFooter()V
- .locals 3
- .annotation system Ldalvik/annotation/Throws;
- value = {
- Ljava/io/IOException;
- }
- .end annotation
- iget-object v0, p0, Lokio/GzipSink;->sink:Lokio/BufferedSink;
- iget-object v1, p0, Lokio/GzipSink;->crc:Ljava/util/zip/CRC32;
- invoke-virtual {v1}, Ljava/util/zip/CRC32;->getValue()J
- move-result-wide v1
- long-to-int v2, v1
- invoke-interface {v0, v2}, Lokio/BufferedSink;->writeIntLe(I)Lokio/BufferedSink;
- iget-object v0, p0, Lokio/GzipSink;->sink:Lokio/BufferedSink;
- iget-object v1, p0, Lokio/GzipSink;->deflater:Ljava/util/zip/Deflater;
- invoke-virtual {v1}, Ljava/util/zip/Deflater;->getBytesRead()J
- move-result-wide v1
- long-to-int v2, v1
- invoke-interface {v0, v2}, Lokio/BufferedSink;->writeIntLe(I)Lokio/BufferedSink;
- return-void
- .end method
- .method private writeHeader()V
- .locals 2
- iget-object v0, p0, Lokio/GzipSink;->sink:Lokio/BufferedSink;
- invoke-interface {v0}, Lokio/BufferedSink;->buffer()Lokio/Buffer;
- move-result-object v0
- const/16 v1, 0x1f8b
- invoke-virtual {v0, v1}, Lokio/Buffer;->writeShort(I)Lokio/Buffer;
- const/16 v1, 0x8
- invoke-virtual {v0, v1}, Lokio/Buffer;->writeByte(I)Lokio/Buffer;
- const/4 v1, 0x0
- invoke-virtual {v0, v1}, Lokio/Buffer;->writeByte(I)Lokio/Buffer;
- invoke-virtual {v0, v1}, Lokio/Buffer;->writeInt(I)Lokio/Buffer;
- invoke-virtual {v0, v1}, Lokio/Buffer;->writeByte(I)Lokio/Buffer;
- invoke-virtual {v0, v1}, Lokio/Buffer;->writeByte(I)Lokio/Buffer;
- return-void
- .end method
- # virtual methods
- .method public close()V
- .locals 2
- .annotation system Ldalvik/annotation/Throws;
- value = {
- Ljava/io/IOException;
- }
- .end annotation
- iget-boolean v0, p0, Lokio/GzipSink;->closed:Z
- if-eqz v0, :cond_0
- return-void
- :cond_0
- const/4 v0, 0x0
- :try_start_0
- iget-object v1, p0, Lokio/GzipSink;->deflaterSink:Lokio/DeflaterSink;
- invoke-virtual {v1}, Lokio/DeflaterSink;->finishDeflate()V
- invoke-direct {p0}, Lokio/GzipSink;->writeFooter()V
- :try_end_0
- .catchall {:try_start_0 .. :try_end_0} :catchall_0
- goto :goto_0
- :catchall_0
- move-exception v0
- :goto_0
- :try_start_1
- iget-object v1, p0, Lokio/GzipSink;->deflater:Ljava/util/zip/Deflater;
- invoke-virtual {v1}, Ljava/util/zip/Deflater;->end()V
- :try_end_1
- .catchall {:try_start_1 .. :try_end_1} :catchall_1
- goto :goto_1
- :catchall_1
- move-exception v1
- if-nez v0, :cond_1
- move-object v0, v1
- :cond_1
- :goto_1
- :try_start_2
- iget-object v1, p0, Lokio/GzipSink;->sink:Lokio/BufferedSink;
- invoke-interface {v1}, Lokio/Sink;->close()V
- :try_end_2
- .catchall {:try_start_2 .. :try_end_2} :catchall_2
- goto :goto_2
- :catchall_2
- move-exception v1
- if-nez v0, :cond_2
- move-object v0, v1
- :cond_2
- :goto_2
- const/4 v1, 0x1
- iput-boolean v1, p0, Lokio/GzipSink;->closed:Z
- if-eqz v0, :cond_3
- invoke-static {v0}, Lokio/Util;->sneakyRethrow(Ljava/lang/Throwable;)V
- :cond_3
- return-void
- .end method
- .method public deflater()Ljava/util/zip/Deflater;
- .locals 1
- iget-object v0, p0, Lokio/GzipSink;->deflater:Ljava/util/zip/Deflater;
- return-object v0
- .end method
- .method public flush()V
- .locals 1
- .annotation system Ldalvik/annotation/Throws;
- value = {
- Ljava/io/IOException;
- }
- .end annotation
- iget-object v0, p0, Lokio/GzipSink;->deflaterSink:Lokio/DeflaterSink;
- invoke-virtual {v0}, Lokio/DeflaterSink;->flush()V
- return-void
- .end method
- .method public timeout()Lokio/Timeout;
- .locals 1
- iget-object v0, p0, Lokio/GzipSink;->sink:Lokio/BufferedSink;
- invoke-interface {v0}, Lokio/Sink;->timeout()Lokio/Timeout;
- move-result-object v0
- return-object v0
- .end method
- .method public write(Lokio/Buffer;J)V
- .locals 3
- .annotation system Ldalvik/annotation/Throws;
- value = {
- Ljava/io/IOException;
- }
- .end annotation
- const-wide/16 v0, 0x0
- cmp-long v2, p2, v0
- if-ltz v2, :cond_1
- cmp-long v2, p2, v0
- if-nez v2, :cond_0
- return-void
- :cond_0
- invoke-direct {p0, p1, p2, p3}, Lokio/GzipSink;->updateCrc(Lokio/Buffer;J)V
- iget-object v0, p0, Lokio/GzipSink;->deflaterSink:Lokio/DeflaterSink;
- invoke-virtual {v0, p1, p2, p3}, Lokio/DeflaterSink;->write(Lokio/Buffer;J)V
- return-void
- :cond_1
- new-instance p1, Ljava/lang/IllegalArgumentException;
- new-instance v0, Ljava/lang/StringBuilder;
- invoke-direct {v0}, Ljava/lang/StringBuilder;-><init>()V
- const-string v1, "byteCount < 0: "
- invoke-virtual {v0, v1}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;
- invoke-virtual {v0, p2, p3}, Ljava/lang/StringBuilder;->append(J)Ljava/lang/StringBuilder;
- invoke-virtual {v0}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;
- move-result-object p2
- invoke-direct {p1, p2}, Ljava/lang/IllegalArgumentException;-><init>(Ljava/lang/String;)V
- throw p1
- .end method
|