/** * @return the trailer-part of the chunked body. * This method should only be called after the full body has been read. Before that, it will * just return an empty set of headers. */ public RawHttpHeaders getTrailer() { return trailer == null ? RawHttpHeaders.empty() : trailer; } }
/** * @return the trailer-part of the chunked body. * This method should only be called after the full body has been read. Before that, it will * just return an empty set of headers. */ public RawHttpHeaders getTrailer() { return trailer == null ? RawHttpHeaders.empty() : trailer; } }
/** * Send a binary message. * <p> * The message should not be empty because sending an empty chunk would signal the end of the transmission. * For this reason, an empty message is turned into a "ping" (see {@link MessageSender#ping()} message. * * @param message the binary message * @throws IllegalStateException if the message queue is already full */ public void sendBinaryMessage(byte[] message) { sendBinaryMessage(message, RawHttpHeaders.empty()); }
/** * Send a text message. * <p> * The message should not be empty because sending an empty chunk would signal the end of the transmission. * For this reason, an empty message is turned into a "ping" (see {@link MessageSender#ping()} message. * * @param message the text message * @throws IllegalStateException if the message queue is already full */ public void sendTextMessage(String message) { sendTextMessage(message, RawHttpHeaders.empty()); }
/** * Close the connection. */ public void close() { if (!isClosed.getAndSet(true)) { messages.addLast(new Message(new byte[0], RawHttpHeaders.empty())); } }
void readNextChunk() throws IOException { ChunkedBodyContents.Chunk chunk; if (chunkStream.hasNext()) { chunk = chunkStream.next(); } else { chunk = new ChunkedBodyContents.Chunk(RawHttpHeaders.empty(), new byte[0]); } ByteArrayOutputStream out = new ByteArrayOutputStream(chunk.size() + 4); chunk.writeTo(out); chunkBytes = out.toByteArray(); hasNextChunk = chunk.size() > 0; } };