final class Http2Writer
extends java.lang.Object
implements java.io.Closeable
Modifier and Type | Field and Description |
---|---|
private boolean |
client |
private boolean |
closed |
private okio.Buffer |
hpackBuffer |
(package private) Hpack.Writer |
hpackWriter |
private static java.util.logging.Logger |
logger |
private int |
maxFrameSize |
private okio.BufferedSink |
sink |
Constructor and Description |
---|
Http2Writer(okio.BufferedSink sink,
boolean client) |
Modifier and Type | Method and Description |
---|---|
void |
applyAndAckSettings(Settings peerSettings)
Applies
peerSettings and then sends a settings ACK. |
void |
close() |
void |
connectionPreface() |
void |
data(boolean outFinished,
int streamId,
okio.Buffer source,
int byteCount)
source.length may be longer than the max length of the variant's data frame. |
(package private) void |
dataFrame(int streamId,
byte flags,
okio.Buffer buffer,
int byteCount) |
void |
flush() |
void |
frameHeader(int streamId,
int length,
byte type,
byte flags) |
void |
goAway(int lastGoodStreamId,
ErrorCode errorCode,
byte[] debugData)
Tell the peer to stop creating streams and that we last processed
lastGoodStreamId , or
zero if no streams were processed. |
(package private) void |
headers(boolean outFinished,
int streamId,
java.util.List<Header> headerBlock) |
void |
headers(int streamId,
java.util.List<Header> headerBlock) |
int |
maxDataLength()
The maximum size of bytes that may be sent in a single call to
data(boolean, int, okio.Buffer, int) . |
void |
ping(boolean ack,
int payload1,
int payload2)
Send a connection-level ping to the peer.
|
void |
pushPromise(int streamId,
int promisedStreamId,
java.util.List<Header> requestHeaders)
HTTP/2 only.
|
void |
rstStream(int streamId,
ErrorCode errorCode) |
void |
settings(Settings settings)
Write okhttp's settings to the peer.
|
void |
synReply(boolean outFinished,
int streamId,
java.util.List<Header> headerBlock) |
void |
synStream(boolean outFinished,
int streamId,
int associatedStreamId,
java.util.List<Header> headerBlock) |
void |
windowUpdate(int streamId,
long windowSizeIncrement)
Inform peer that an additional
windowSizeIncrement bytes can be sent on streamId , or the connection if streamId is zero. |
private void |
writeContinuationFrames(int streamId,
long byteCount) |
private static void |
writeMedium(okio.BufferedSink sink,
int i) |
private static final java.util.logging.Logger logger
private final okio.BufferedSink sink
private final boolean client
private final okio.Buffer hpackBuffer
private int maxFrameSize
private boolean closed
final Hpack.Writer hpackWriter
public void connectionPreface() throws java.io.IOException
java.io.IOException
public void applyAndAckSettings(Settings peerSettings) throws java.io.IOException
peerSettings
and then sends a settings ACK.java.io.IOException
public void pushPromise(int streamId, int promisedStreamId, java.util.List<Header> requestHeaders) throws java.io.IOException
A push promise contains all the headers that pertain to a server-initiated request, and a
promisedStreamId
to which response frames will be delivered. Push promise frames are
sent as a part of the response to streamId
. The promisedStreamId
has a priority
of one greater than streamId
.
streamId
- client-initiated stream ID. Must be an odd number.promisedStreamId
- server-initiated stream ID. Must be an even number.requestHeaders
- minimally includes :method
, :scheme
, :authority
,
and :path
.java.io.IOException
public void flush() throws java.io.IOException
java.io.IOException
public void synStream(boolean outFinished, int streamId, int associatedStreamId, java.util.List<Header> headerBlock) throws java.io.IOException
java.io.IOException
public void synReply(boolean outFinished, int streamId, java.util.List<Header> headerBlock) throws java.io.IOException
java.io.IOException
public void headers(int streamId, java.util.List<Header> headerBlock) throws java.io.IOException
java.io.IOException
public void rstStream(int streamId, ErrorCode errorCode) throws java.io.IOException
java.io.IOException
public int maxDataLength()
data(boolean, int, okio.Buffer, int)
.public void data(boolean outFinished, int streamId, okio.Buffer source, int byteCount) throws java.io.IOException
source.length
may be longer than the max length of the variant's data frame.
Implementations must send multiple frames as necessary.source
- the buffer to draw bytes from. May be null if byteCount is 0.byteCount
- must be between 0 and the minimum of source.length
and maxDataLength()
.java.io.IOException
void dataFrame(int streamId, byte flags, okio.Buffer buffer, int byteCount) throws java.io.IOException
java.io.IOException
public void settings(Settings settings) throws java.io.IOException
java.io.IOException
public void ping(boolean ack, int payload1, int payload2) throws java.io.IOException
ack
indicates this is a reply. The data in
payload1
and payload2
opaque binary, and there are no rules on the content.java.io.IOException
public void goAway(int lastGoodStreamId, ErrorCode errorCode, byte[] debugData) throws java.io.IOException
lastGoodStreamId
, or
zero if no streams were processed.lastGoodStreamId
- the last stream ID processed, or zero if no streams were processed.errorCode
- reason for closing the connection.debugData
- only valid for HTTP/2; opaque debug data to send.java.io.IOException
public void windowUpdate(int streamId, long windowSizeIncrement) throws java.io.IOException
windowSizeIncrement
bytes can be sent on streamId
, or the connection if streamId
is zero.java.io.IOException
public void frameHeader(int streamId, int length, byte type, byte flags) throws java.io.IOException
java.io.IOException
public void close() throws java.io.IOException
close
in interface java.io.Closeable
close
in interface java.lang.AutoCloseable
java.io.IOException
private static void writeMedium(okio.BufferedSink sink, int i) throws java.io.IOException
java.io.IOException
private void writeContinuationFrames(int streamId, long byteCount) throws java.io.IOException
java.io.IOException
void headers(boolean outFinished, int streamId, java.util.List<Header> headerBlock) throws java.io.IOException
java.io.IOException