< prev index next >

src/jdk.incubator.httpclient/share/classes/jdk/incubator/http/internal/websocket/OutgoingMessage.java

Print this page

        

*** 69,84 **** /* * Performs contextualization. This method is not a part of the constructor * so it would be possible to defer the work it does until the most * convenient moment (up to the point where sentTo is invoked). */ ! protected void contextualize(Context context) { // masking and charset decoding should be performed here rather than in // the constructor (as of today) if (context.isCloseSent()) { throw new IllegalStateException("Close sent"); } } protected boolean sendTo(RawChannel channel) throws IOException { while ((offset = nextUnwrittenIndex()) != -1) { long n = channel.write(frame, offset, frame.length - offset); --- 69,85 ---- /* * Performs contextualization. This method is not a part of the constructor * so it would be possible to defer the work it does until the most * convenient moment (up to the point where sentTo is invoked). */ ! protected boolean contextualize(Context context) { // masking and charset decoding should be performed here rather than in // the constructor (as of today) if (context.isCloseSent()) { throw new IllegalStateException("Close sent"); } + return true; } protected boolean sendTo(RawChannel channel) throws IOException { while ((offset = nextUnwrittenIndex()) != -1) { long n = channel.write(frame, offset, frame.length - offset);
*** 113,132 **** } this.isLast = isLast; } @Override ! protected void contextualize(Context context) { super.contextualize(context); if (context.isPreviousBinary() && !context.isPreviousLast()) { throw new IllegalStateException("Unexpected text message"); } frame = getDataMessageBuffers( TEXT, context.isPreviousLast(), isLast, payload, payload); context.setPreviousBinary(false); context.setPreviousText(true); context.setPreviousLast(isLast); } } static final class Binary extends OutgoingMessage { --- 114,134 ---- } this.isLast = isLast; } @Override ! protected boolean contextualize(Context context) { super.contextualize(context); if (context.isPreviousBinary() && !context.isPreviousLast()) { throw new IllegalStateException("Unexpected text message"); } frame = getDataMessageBuffers( TEXT, context.isPreviousLast(), isLast, payload, payload); context.setPreviousBinary(false); context.setPreviousText(true); context.setPreviousLast(isLast); + return true; } } static final class Binary extends OutgoingMessage {
*** 137,157 **** this.payload = requireNonNull(payload); this.isLast = isLast; } @Override ! protected void contextualize(Context context) { super.contextualize(context); if (context.isPreviousText() && !context.isPreviousLast()) { throw new IllegalStateException("Unexpected binary message"); } ByteBuffer newBuffer = ByteBuffer.allocate(payload.remaining()); frame = getDataMessageBuffers( BINARY, context.isPreviousLast(), isLast, payload, newBuffer); context.setPreviousText(false); context.setPreviousBinary(true); context.setPreviousLast(isLast); } } static final class Ping extends OutgoingMessage { --- 139,160 ---- this.payload = requireNonNull(payload); this.isLast = isLast; } @Override ! protected boolean contextualize(Context context) { super.contextualize(context); if (context.isPreviousText() && !context.isPreviousLast()) { throw new IllegalStateException("Unexpected binary message"); } ByteBuffer newBuffer = ByteBuffer.allocate(payload.remaining()); frame = getDataMessageBuffers( BINARY, context.isPreviousLast(), isLast, payload, newBuffer); context.setPreviousText(false); context.setPreviousBinary(true); context.setPreviousLast(isLast); + return true; } } static final class Ping extends OutgoingMessage {
*** 193,205 **** payload.flip(); frame = getControlMessageBuffers(CLOSE, payload); } @Override ! protected void contextualize(Context context) { ! super.contextualize(context); context.setCloseSent(); } } private static ByteBuffer[] getControlMessageBuffers(Opcode opcode, ByteBuffer payload) { --- 196,212 ---- payload.flip(); frame = getControlMessageBuffers(CLOSE, payload); } @Override ! protected boolean contextualize(Context context) { ! if (context.isCloseSent()) { ! return false; ! } else { context.setCloseSent(); + return true; + } } } private static ByteBuffer[] getControlMessageBuffers(Opcode opcode, ByteBuffer payload) {
< prev index next >