123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537 |
- .class final Lokhttp3/internal/ws/WebSocketWriter;
- .super Ljava/lang/Object;
- .source ""
- # annotations
- .annotation system Ldalvik/annotation/MemberClasses;
- value = {
- Lokhttp3/internal/ws/WebSocketWriter$FrameSink;
- }
- .end annotation
- # instance fields
- .field activeWriter:Z
- .field final buffer:Lokio/Buffer;
- .field final frameSink:Lokhttp3/internal/ws/WebSocketWriter$FrameSink;
- .field final isClient:Z
- .field final maskBuffer:[B
- .field final maskKey:[B
- .field final random:Ljava/util/Random;
- .field final sink:Lokio/BufferedSink;
- .field writerClosed:Z
- # direct methods
- .method constructor <init>(ZLokio/BufferedSink;Ljava/util/Random;)V
- .locals 1
- invoke-direct {p0}, Ljava/lang/Object;-><init>()V
- new-instance v0, Lokio/Buffer;
- invoke-direct {v0}, Lokio/Buffer;-><init>()V
- iput-object v0, p0, Lokhttp3/internal/ws/WebSocketWriter;->buffer:Lokio/Buffer;
- new-instance v0, Lokhttp3/internal/ws/WebSocketWriter$FrameSink;
- invoke-direct {v0, p0}, Lokhttp3/internal/ws/WebSocketWriter$FrameSink;-><init>(Lokhttp3/internal/ws/WebSocketWriter;)V
- iput-object v0, p0, Lokhttp3/internal/ws/WebSocketWriter;->frameSink:Lokhttp3/internal/ws/WebSocketWriter$FrameSink;
- if-eqz p2, :cond_3
- if-eqz p3, :cond_2
- iput-boolean p1, p0, Lokhttp3/internal/ws/WebSocketWriter;->isClient:Z
- iput-object p2, p0, Lokhttp3/internal/ws/WebSocketWriter;->sink:Lokio/BufferedSink;
- iput-object p3, p0, Lokhttp3/internal/ws/WebSocketWriter;->random:Ljava/util/Random;
- const/4 p2, 0x0
- if-eqz p1, :cond_0
- const/4 p3, 0x4
- new-array p3, p3, [B
- goto :goto_0
- :cond_0
- move-object p3, p2
- :goto_0
- iput-object p3, p0, Lokhttp3/internal/ws/WebSocketWriter;->maskKey:[B
- if-eqz p1, :cond_1
- const/16 p1, 0x2000
- new-array p2, p1, [B
- :cond_1
- iput-object p2, p0, Lokhttp3/internal/ws/WebSocketWriter;->maskBuffer:[B
- return-void
- :cond_2
- new-instance p1, Ljava/lang/NullPointerException;
- const-string p2, "random == null"
- invoke-direct {p1, p2}, Ljava/lang/NullPointerException;-><init>(Ljava/lang/String;)V
- throw p1
- :cond_3
- new-instance p1, Ljava/lang/NullPointerException;
- const-string p2, "sink == null"
- invoke-direct {p1, p2}, Ljava/lang/NullPointerException;-><init>(Ljava/lang/String;)V
- throw p1
- .end method
- .method private writeControlFrame(ILokio/ByteString;)V
- .locals 7
- .annotation system Ldalvik/annotation/Throws;
- value = {
- Ljava/io/IOException;
- }
- .end annotation
- iget-boolean v0, p0, Lokhttp3/internal/ws/WebSocketWriter;->writerClosed:Z
- if-nez v0, :cond_2
- invoke-virtual {p2}, Lokio/ByteString;->size()I
- move-result v0
- int-to-long v1, v0
- const-wide/16 v3, 0x7d
- cmp-long v5, v1, v3
- if-gtz v5, :cond_1
- or-int/lit16 p1, p1, 0x80
- iget-object v1, p0, Lokhttp3/internal/ws/WebSocketWriter;->sink:Lokio/BufferedSink;
- invoke-interface {v1, p1}, Lokio/BufferedSink;->writeByte(I)Lokio/BufferedSink;
- iget-boolean p1, p0, Lokhttp3/internal/ws/WebSocketWriter;->isClient:Z
- if-eqz p1, :cond_0
- or-int/lit16 p1, v0, 0x80
- iget-object v0, p0, Lokhttp3/internal/ws/WebSocketWriter;->sink:Lokio/BufferedSink;
- invoke-interface {v0, p1}, Lokio/BufferedSink;->writeByte(I)Lokio/BufferedSink;
- iget-object p1, p0, Lokhttp3/internal/ws/WebSocketWriter;->random:Ljava/util/Random;
- iget-object v0, p0, Lokhttp3/internal/ws/WebSocketWriter;->maskKey:[B
- invoke-virtual {p1, v0}, Ljava/util/Random;->nextBytes([B)V
- iget-object p1, p0, Lokhttp3/internal/ws/WebSocketWriter;->sink:Lokio/BufferedSink;
- iget-object v0, p0, Lokhttp3/internal/ws/WebSocketWriter;->maskKey:[B
- invoke-interface {p1, v0}, Lokio/BufferedSink;->write([B)Lokio/BufferedSink;
- invoke-virtual {p2}, Lokio/ByteString;->toByteArray()[B
- move-result-object p1
- array-length p2, p1
- int-to-long v2, p2
- iget-object v4, p0, Lokhttp3/internal/ws/WebSocketWriter;->maskKey:[B
- const-wide/16 v5, 0x0
- move-object v1, p1
- invoke-static/range {v1 .. v6}, Lokhttp3/internal/ws/WebSocketProtocol;->toggleMask([BJ[BJ)V
- iget-object p2, p0, Lokhttp3/internal/ws/WebSocketWriter;->sink:Lokio/BufferedSink;
- invoke-interface {p2, p1}, Lokio/BufferedSink;->write([B)Lokio/BufferedSink;
- goto :goto_0
- :cond_0
- iget-object p1, p0, Lokhttp3/internal/ws/WebSocketWriter;->sink:Lokio/BufferedSink;
- invoke-interface {p1, v0}, Lokio/BufferedSink;->writeByte(I)Lokio/BufferedSink;
- iget-object p1, p0, Lokhttp3/internal/ws/WebSocketWriter;->sink:Lokio/BufferedSink;
- invoke-interface {p1, p2}, Lokio/BufferedSink;->write(Lokio/ByteString;)Lokio/BufferedSink;
- :goto_0
- iget-object p1, p0, Lokhttp3/internal/ws/WebSocketWriter;->sink:Lokio/BufferedSink;
- invoke-interface {p1}, Lokio/BufferedSink;->flush()V
- return-void
- :cond_1
- new-instance p1, Ljava/lang/IllegalArgumentException;
- const-string p2, "Payload size must be less than or equal to 125"
- invoke-direct {p1, p2}, Ljava/lang/IllegalArgumentException;-><init>(Ljava/lang/String;)V
- throw p1
- :cond_2
- new-instance p1, Ljava/io/IOException;
- const-string p2, "closed"
- invoke-direct {p1, p2}, Ljava/io/IOException;-><init>(Ljava/lang/String;)V
- throw p1
- .end method
- # virtual methods
- .method newMessageSink(IJ)Lokio/Sink;
- .locals 2
- iget-boolean v0, p0, Lokhttp3/internal/ws/WebSocketWriter;->activeWriter:Z
- if-nez v0, :cond_0
- const/4 v0, 0x1
- iput-boolean v0, p0, Lokhttp3/internal/ws/WebSocketWriter;->activeWriter:Z
- iget-object v1, p0, Lokhttp3/internal/ws/WebSocketWriter;->frameSink:Lokhttp3/internal/ws/WebSocketWriter$FrameSink;
- iput p1, v1, Lokhttp3/internal/ws/WebSocketWriter$FrameSink;->formatOpcode:I
- iput-wide p2, v1, Lokhttp3/internal/ws/WebSocketWriter$FrameSink;->contentLength:J
- iput-boolean v0, v1, Lokhttp3/internal/ws/WebSocketWriter$FrameSink;->isFirstFrame:Z
- const/4 p1, 0x0
- iput-boolean p1, v1, Lokhttp3/internal/ws/WebSocketWriter$FrameSink;->closed:Z
- return-object v1
- :cond_0
- new-instance p1, Ljava/lang/IllegalStateException;
- const-string p2, "Another message writer is active. Did you call close()?"
- invoke-direct {p1, p2}, Ljava/lang/IllegalStateException;-><init>(Ljava/lang/String;)V
- throw p1
- .end method
- .method writeClose(ILokio/ByteString;)V
- .locals 1
- .annotation system Ldalvik/annotation/Throws;
- value = {
- Ljava/io/IOException;
- }
- .end annotation
- sget-object v0, Lokio/ByteString;->EMPTY:Lokio/ByteString;
- if-nez p1, :cond_0
- if-eqz p2, :cond_3
- :cond_0
- if-eqz p1, :cond_1
- invoke-static {p1}, Lokhttp3/internal/ws/WebSocketProtocol;->validateCloseCode(I)V
- :cond_1
- new-instance v0, Lokio/Buffer;
- invoke-direct {v0}, Lokio/Buffer;-><init>()V
- invoke-virtual {v0, p1}, Lokio/Buffer;->writeShort(I)Lokio/Buffer;
- if-eqz p2, :cond_2
- invoke-virtual {v0, p2}, Lokio/Buffer;->write(Lokio/ByteString;)Lokio/Buffer;
- :cond_2
- invoke-virtual {v0}, Lokio/Buffer;->readByteString()Lokio/ByteString;
- move-result-object v0
- :cond_3
- const/16 p1, 0x8
- const/4 p2, 0x1
- :try_start_0
- invoke-direct {p0, p1, v0}, Lokhttp3/internal/ws/WebSocketWriter;->writeControlFrame(ILokio/ByteString;)V
- :try_end_0
- .catchall {:try_start_0 .. :try_end_0} :catchall_0
- iput-boolean p2, p0, Lokhttp3/internal/ws/WebSocketWriter;->writerClosed:Z
- return-void
- :catchall_0
- move-exception p1
- iput-boolean p2, p0, Lokhttp3/internal/ws/WebSocketWriter;->writerClosed:Z
- throw p1
- .end method
- .method writeMessageFrame(IJZZ)V
- .locals 9
- .annotation system Ldalvik/annotation/Throws;
- value = {
- Ljava/io/IOException;
- }
- .end annotation
- iget-boolean v0, p0, Lokhttp3/internal/ws/WebSocketWriter;->writerClosed:Z
- if-nez v0, :cond_8
- const/4 v0, 0x0
- if-eqz p4, :cond_0
- goto :goto_0
- :cond_0
- const/4 p1, 0x0
- :goto_0
- if-eqz p5, :cond_1
- or-int/lit16 p1, p1, 0x80
- :cond_1
- iget-object p4, p0, Lokhttp3/internal/ws/WebSocketWriter;->sink:Lokio/BufferedSink;
- invoke-interface {p4, p1}, Lokio/BufferedSink;->writeByte(I)Lokio/BufferedSink;
- iget-boolean p1, p0, Lokhttp3/internal/ws/WebSocketWriter;->isClient:Z
- if-eqz p1, :cond_2
- const/16 p1, 0x80
- goto :goto_1
- :cond_2
- const/4 p1, 0x0
- :goto_1
- const-wide/16 p4, 0x7d
- cmp-long v1, p2, p4
- if-gtz v1, :cond_3
- long-to-int p4, p2
- or-int/2addr p1, p4
- iget-object p4, p0, Lokhttp3/internal/ws/WebSocketWriter;->sink:Lokio/BufferedSink;
- invoke-interface {p4, p1}, Lokio/BufferedSink;->writeByte(I)Lokio/BufferedSink;
- goto :goto_2
- :cond_3
- const-wide/32 p4, 0xffff
- cmp-long v1, p2, p4
- if-gtz v1, :cond_4
- or-int/lit8 p1, p1, 0x7e
- iget-object p4, p0, Lokhttp3/internal/ws/WebSocketWriter;->sink:Lokio/BufferedSink;
- invoke-interface {p4, p1}, Lokio/BufferedSink;->writeByte(I)Lokio/BufferedSink;
- iget-object p1, p0, Lokhttp3/internal/ws/WebSocketWriter;->sink:Lokio/BufferedSink;
- long-to-int p4, p2
- invoke-interface {p1, p4}, Lokio/BufferedSink;->writeShort(I)Lokio/BufferedSink;
- goto :goto_2
- :cond_4
- or-int/lit8 p1, p1, 0x7f
- iget-object p4, p0, Lokhttp3/internal/ws/WebSocketWriter;->sink:Lokio/BufferedSink;
- invoke-interface {p4, p1}, Lokio/BufferedSink;->writeByte(I)Lokio/BufferedSink;
- iget-object p1, p0, Lokhttp3/internal/ws/WebSocketWriter;->sink:Lokio/BufferedSink;
- invoke-interface {p1, p2, p3}, Lokio/BufferedSink;->writeLong(J)Lokio/BufferedSink;
- :goto_2
- iget-boolean p1, p0, Lokhttp3/internal/ws/WebSocketWriter;->isClient:Z
- if-eqz p1, :cond_6
- iget-object p1, p0, Lokhttp3/internal/ws/WebSocketWriter;->random:Ljava/util/Random;
- iget-object p4, p0, Lokhttp3/internal/ws/WebSocketWriter;->maskKey:[B
- invoke-virtual {p1, p4}, Ljava/util/Random;->nextBytes([B)V
- iget-object p1, p0, Lokhttp3/internal/ws/WebSocketWriter;->sink:Lokio/BufferedSink;
- iget-object p4, p0, Lokhttp3/internal/ws/WebSocketWriter;->maskKey:[B
- invoke-interface {p1, p4}, Lokio/BufferedSink;->write([B)Lokio/BufferedSink;
- const-wide/16 p4, 0x0
- :goto_3
- cmp-long p1, p4, p2
- if-gez p1, :cond_7
- iget-object p1, p0, Lokhttp3/internal/ws/WebSocketWriter;->maskBuffer:[B
- array-length p1, p1
- int-to-long v1, p1
- invoke-static {p2, p3, v1, v2}, Ljava/lang/Math;->min(JJ)J
- move-result-wide v1
- long-to-int p1, v1
- iget-object v1, p0, Lokhttp3/internal/ws/WebSocketWriter;->buffer:Lokio/Buffer;
- iget-object v2, p0, Lokhttp3/internal/ws/WebSocketWriter;->maskBuffer:[B
- invoke-virtual {v1, v2, v0, p1}, Lokio/Buffer;->read([BII)I
- move-result p1
- const/4 v1, -0x1
- if-eq p1, v1, :cond_5
- iget-object v1, p0, Lokhttp3/internal/ws/WebSocketWriter;->maskBuffer:[B
- int-to-long v7, p1
- iget-object v4, p0, Lokhttp3/internal/ws/WebSocketWriter;->maskKey:[B
- move-wide v2, v7
- move-wide v5, p4
- invoke-static/range {v1 .. v6}, Lokhttp3/internal/ws/WebSocketProtocol;->toggleMask([BJ[BJ)V
- iget-object v1, p0, Lokhttp3/internal/ws/WebSocketWriter;->sink:Lokio/BufferedSink;
- iget-object v2, p0, Lokhttp3/internal/ws/WebSocketWriter;->maskBuffer:[B
- invoke-interface {v1, v2, v0, p1}, Lokio/BufferedSink;->write([BII)Lokio/BufferedSink;
- add-long/2addr p4, v7
- goto :goto_3
- :cond_5
- new-instance p1, Ljava/lang/AssertionError;
- invoke-direct {p1}, Ljava/lang/AssertionError;-><init>()V
- throw p1
- :cond_6
- iget-object p1, p0, Lokhttp3/internal/ws/WebSocketWriter;->sink:Lokio/BufferedSink;
- iget-object p4, p0, Lokhttp3/internal/ws/WebSocketWriter;->buffer:Lokio/Buffer;
- invoke-interface {p1, p4, p2, p3}, Lokio/Sink;->write(Lokio/Buffer;J)V
- :cond_7
- iget-object p1, p0, Lokhttp3/internal/ws/WebSocketWriter;->sink:Lokio/BufferedSink;
- invoke-interface {p1}, Lokio/BufferedSink;->emit()Lokio/BufferedSink;
- return-void
- :cond_8
- new-instance p1, Ljava/io/IOException;
- const-string p2, "closed"
- invoke-direct {p1, p2}, Ljava/io/IOException;-><init>(Ljava/lang/String;)V
- goto :goto_5
- :goto_4
- throw p1
- :goto_5
- goto :goto_4
- .end method
- .method writePing(Lokio/ByteString;)V
- .locals 1
- .annotation system Ldalvik/annotation/Throws;
- value = {
- Ljava/io/IOException;
- }
- .end annotation
- const/16 v0, 0x9
- invoke-direct {p0, v0, p1}, Lokhttp3/internal/ws/WebSocketWriter;->writeControlFrame(ILokio/ByteString;)V
- return-void
- .end method
- .method writePong(Lokio/ByteString;)V
- .locals 1
- .annotation system Ldalvik/annotation/Throws;
- value = {
- Ljava/io/IOException;
- }
- .end annotation
- const/16 v0, 0xa
- invoke-direct {p0, v0, p1}, Lokhttp3/internal/ws/WebSocketWriter;->writeControlFrame(ILokio/ByteString;)V
- return-void
- .end method
|