src/java.net.http/share/classes/jdk/internal/net/http/websocket/MessageEncoder.java
author dfuchs
Wed, 14 Mar 2018 13:35:33 +0000
branchhttp-client-branch
changeset 56304 065641767a75
parent 56295 898dfb226bd0
child 56314 f92e7a8a189f
permissions -rw-r--r--
http-client-branch: change websocket to use System.Logger for debug logging
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
56263
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
     1
/*
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
     2
 * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
     4
 *
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
    10
 *
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
    15
 * accompanied this code).
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
    16
 *
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
    20
 *
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
    23
 * questions.
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
    24
 */
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
    25
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
    26
package jdk.internal.net.http.websocket;
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
    27
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
    28
import jdk.internal.net.http.common.Utils;
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
    29
import jdk.internal.net.http.websocket.Frame.Opcode;
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
    30
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
    31
import java.io.IOException;
56304
065641767a75 http-client-branch: change websocket to use System.Logger for debug logging
dfuchs
parents: 56295
diff changeset
    32
import java.lang.System.Logger.Level;
56263
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
    33
import java.nio.ByteBuffer;
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
    34
import java.nio.CharBuffer;
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
    35
import java.nio.charset.CharacterCodingException;
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
    36
import java.nio.charset.CharsetEncoder;
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
    37
import java.nio.charset.CoderResult;
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
    38
import java.nio.charset.CodingErrorAction;
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
    39
import java.nio.charset.StandardCharsets;
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
    40
import java.security.SecureRandom;
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
    41
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
    42
/*
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
    43
 * A stateful producer of binary representations of WebSocket messages being
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
    44
 * sent from the client to the server.
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
    45
 *
56269
234813fd33bc http-client-branch: (WebSocket) test fix + output closure
prappo
parents: 56263
diff changeset
    46
 * An encoding method is given an original message and a byte buffer to put the
234813fd33bc http-client-branch: (WebSocket) test fix + output closure
prappo
parents: 56263
diff changeset
    47
 * resulting bytes to. The method is called until it returns true. Then the
234813fd33bc http-client-branch: (WebSocket) test fix + output closure
prappo
parents: 56263
diff changeset
    48
 * reset method is called. The whole sequence repeats with next message.
56263
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
    49
 */
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
    50
public class MessageEncoder {
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
    51
56304
065641767a75 http-client-branch: change websocket to use System.Logger for debug logging
dfuchs
parents: 56295
diff changeset
    52
    private static final boolean DEBUG = Utils.DEBUG_WS;
065641767a75 http-client-branch: change websocket to use System.Logger for debug logging
dfuchs
parents: 56295
diff changeset
    53
    private static final System.Logger debug =
065641767a75 http-client-branch: change websocket to use System.Logger for debug logging
dfuchs
parents: 56295
diff changeset
    54
            Utils.getWebSocketLogger("[Output]"::toString, DEBUG);
56263
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
    55
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
    56
    private final SecureRandom maskingKeySource = new SecureRandom();
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
    57
    private final Frame.HeaderWriter headerWriter = new Frame.HeaderWriter();
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
    58
    private final Frame.Masker payloadMasker = new Frame.Masker();
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
    59
    private final CharsetEncoder charsetEncoder
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
    60
            = StandardCharsets.UTF_8.newEncoder()
56269
234813fd33bc http-client-branch: (WebSocket) test fix + output closure
prappo
parents: 56263
diff changeset
    61
                                    .onMalformedInput(CodingErrorAction.REPORT)
234813fd33bc http-client-branch: (WebSocket) test fix + output closure
prappo
parents: 56263
diff changeset
    62
                                    .onUnmappableCharacter(CodingErrorAction.REPORT);
56263
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
    63
    /*
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
    64
     * This buffer is used both to encode characters to UTF-8 and to calculate
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
    65
     * the length of the resulting frame's payload. The length of the payload
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
    66
     * must be known before the frame's header can be written.
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
    67
     * For implementation reasons, this buffer must have a capacity of at least
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
    68
     * the maximum size of a Close frame payload, which is 125 bytes
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
    69
     * (or Frame.MAX_CONTROL_FRAME_PAYLOAD_LENGTH).
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
    70
     */
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
    71
    private final ByteBuffer intermediateBuffer = createIntermediateBuffer(
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
    72
            Frame.MAX_CONTROL_FRAME_PAYLOAD_LENGTH);
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
    73
    private final ByteBuffer headerBuffer = ByteBuffer.allocate(
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
    74
            Frame.MAX_HEADER_SIZE_BYTES);
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
    75
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
    76
    private boolean started;
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
    77
    private boolean flushing;
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
    78
    private boolean moreText = true;
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
    79
    private long headerCount;
56269
234813fd33bc http-client-branch: (WebSocket) test fix + output closure
prappo
parents: 56263
diff changeset
    80
    /* Has the previous frame got its fin flag set? */
234813fd33bc http-client-branch: (WebSocket) test fix + output closure
prappo
parents: 56263
diff changeset
    81
    private boolean previousFin = true;
234813fd33bc http-client-branch: (WebSocket) test fix + output closure
prappo
parents: 56263
diff changeset
    82
    /* Was the previous frame TEXT or a CONTINUATION thereof? */
56263
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
    83
    private boolean previousText;
56269
234813fd33bc http-client-branch: (WebSocket) test fix + output closure
prappo
parents: 56263
diff changeset
    84
    private boolean closed; // TODO: too late, need to check it before accepting otherwise the queue might blow up
56263
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
    85
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
    86
    /*
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
    87
     * How many bytes of the current message have been already encoded.
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
    88
     *
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
    89
     * Even though the user hands their buffers over to us, they still can
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
    90
     * manipulate these buffers while we are getting data out of them.
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
    91
     * The number of produced bytes guards us from such behaviour in the
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
    92
     * case of messages that must be restricted in size (Ping, Pong and Close).
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
    93
     * For other messages this measure provides a best-effort attempt to detect
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
    94
     * concurrent changes to buffer.
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
    95
     *
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
    96
     * Making a shallow copy (duplicate/slice) and then checking the size
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
    97
     * precondition on it would also solve the problem, but at the cost of this
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
    98
     * extra copy.
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
    99
     */
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   100
    private int actualLen;
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   101
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   102
    /*
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   103
     * How many bytes were originally there in the message, before the encoding
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   104
     * started.
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   105
     */
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   106
    private int expectedLen;
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   107
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   108
    /* Exposed for testing purposes */
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   109
    protected ByteBuffer createIntermediateBuffer(int minSize) {
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   110
        int capacity = Utils.getIntegerNetProperty(
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   111
                "jdk.httpclient.websocket.intermediateBufferSize", 16384);
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   112
        return ByteBuffer.allocate(Math.max(minSize, capacity));
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   113
    }
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   114
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   115
    public void reset() {
56269
234813fd33bc http-client-branch: (WebSocket) test fix + output closure
prappo
parents: 56263
diff changeset
   116
        // Do not reset the message stream state fields, e.g. previousFin,
56263
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   117
        // previousText. Just an individual message state:
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   118
        started = false;
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   119
        flushing = false;
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   120
        moreText = true;
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   121
        headerCount = 0;
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   122
        actualLen = 0;
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   123
    }
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   124
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   125
    /*
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   126
     * Encodes text messages by cutting them into fragments of maximum size of
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   127
     * intermediateBuffer.capacity()
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   128
     */
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   129
    public boolean encodeText(CharBuffer src, boolean last, ByteBuffer dst)
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   130
            throws IOException
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   131
    {
56304
065641767a75 http-client-branch: change websocket to use System.Logger for debug logging
dfuchs
parents: 56295
diff changeset
   132
        debug.log(Level.DEBUG, "encodeText src.remaining()=%s, %s, %s",
065641767a75 http-client-branch: change websocket to use System.Logger for debug logging
dfuchs
parents: 56295
diff changeset
   133
                  src.remaining(), last, dst);
56263
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   134
        if (closed) {
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   135
            throw new IOException("Output closed");
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   136
        }
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   137
        if (!started) {
56269
234813fd33bc http-client-branch: (WebSocket) test fix + output closure
prappo
parents: 56263
diff changeset
   138
            if (!previousText && !previousFin) {
56263
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   139
                // Previous data message was a partial binary message
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   140
                throw new IllegalStateException("Unexpected text message");
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   141
            }
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   142
            started = true;
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   143
            headerBuffer.position(0).limit(0);
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   144
            intermediateBuffer.position(0).limit(0);
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   145
            charsetEncoder.reset();
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   146
        }
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   147
        while (true) {
56304
065641767a75 http-client-branch: change websocket to use System.Logger for debug logging
dfuchs
parents: 56295
diff changeset
   148
            debug.log(Level.DEBUG, "put");
56263
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   149
            if (!putAvailable(headerBuffer, dst)) {
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   150
                return false;
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   151
            }
56304
065641767a75 http-client-branch: change websocket to use System.Logger for debug logging
dfuchs
parents: 56295
diff changeset
   152
            debug.log(Level.DEBUG, "mask");
56263
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   153
            if (maskAvailable(intermediateBuffer, dst) < 0) {
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   154
                return false;
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   155
            }
56304
065641767a75 http-client-branch: change websocket to use System.Logger for debug logging
dfuchs
parents: 56295
diff changeset
   156
            debug.log(Level.DEBUG, "moreText");
56263
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   157
            if (!moreText) {
56269
234813fd33bc http-client-branch: (WebSocket) test fix + output closure
prappo
parents: 56263
diff changeset
   158
                previousFin = last;
234813fd33bc http-client-branch: (WebSocket) test fix + output closure
prappo
parents: 56263
diff changeset
   159
                previousText = true;
56263
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   160
                return true;
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   161
            }
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   162
            intermediateBuffer.clear();
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   163
            CoderResult r = null;
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   164
            if (!flushing) {
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   165
                r = charsetEncoder.encode(src, intermediateBuffer, true);
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   166
                if (r.isUnderflow()) {
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   167
                    flushing = true;
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   168
                }
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   169
            }
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   170
            if (flushing) {
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   171
                r = charsetEncoder.flush(intermediateBuffer);
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   172
                if (r.isUnderflow()) {
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   173
                    moreText = false;
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   174
                }
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   175
            }
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   176
            if (r.isError()) {
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   177
                try {
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   178
                    r.throwException();
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   179
                } catch (CharacterCodingException e) {
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   180
                    throw new IOException("Malformed text message", e);
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   181
                }
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   182
            }
56304
065641767a75 http-client-branch: change websocket to use System.Logger for debug logging
dfuchs
parents: 56295
diff changeset
   183
            debug.log(Level.DEBUG, "frame #%s", headerCount);
56263
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   184
            intermediateBuffer.flip();
56269
234813fd33bc http-client-branch: (WebSocket) test fix + output closure
prappo
parents: 56263
diff changeset
   185
            Opcode opcode = previousFin && headerCount == 0
56263
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   186
                    ? Opcode.TEXT : Opcode.CONTINUATION;
56269
234813fd33bc http-client-branch: (WebSocket) test fix + output closure
prappo
parents: 56263
diff changeset
   187
            boolean fin = last && !moreText;
56291
c8c4c707ff3a http-client-branch: (WebSocket) setting DEBUG to true; refactoring;
prappo
parents: 56269
diff changeset
   188
            setupHeader(opcode, fin, intermediateBuffer.remaining());
56263
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   189
            headerCount++;
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   190
        }
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   191
    }
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   192
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   193
    private boolean putAvailable(ByteBuffer src, ByteBuffer dst) {
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   194
        int available = dst.remaining();
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   195
        if (available >= src.remaining()) {
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   196
            dst.put(src);
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   197
            return true;
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   198
        } else {
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   199
            int lim = src.limit();                   // save the limit
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   200
            src.limit(src.position() + available);
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   201
            dst.put(src);
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   202
            src.limit(lim);                          // restore the limit
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   203
            return false;
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   204
        }
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   205
    }
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   206
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   207
    public boolean encodeBinary(ByteBuffer src, boolean last, ByteBuffer dst)
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   208
            throws IOException
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   209
    {
56304
065641767a75 http-client-branch: change websocket to use System.Logger for debug logging
dfuchs
parents: 56295
diff changeset
   210
        debug.log(Level.DEBUG, "encodeBinary %s, %s, %s",
065641767a75 http-client-branch: change websocket to use System.Logger for debug logging
dfuchs
parents: 56295
diff changeset
   211
                  src, last, dst);
56263
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   212
        if (closed) {
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   213
            throw new IOException("Output closed");
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   214
        }
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   215
        if (!started) {
56269
234813fd33bc http-client-branch: (WebSocket) test fix + output closure
prappo
parents: 56263
diff changeset
   216
            if (previousText && !previousFin) {
56263
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   217
                // Previous data message was a partial text message
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   218
                throw new IllegalStateException("Unexpected binary message");
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   219
            }
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   220
            expectedLen = src.remaining();
56291
c8c4c707ff3a http-client-branch: (WebSocket) setting DEBUG to true; refactoring;
prappo
parents: 56269
diff changeset
   221
            Opcode opcode = previousFin ? Opcode.BINARY : Opcode.CONTINUATION;
c8c4c707ff3a http-client-branch: (WebSocket) setting DEBUG to true; refactoring;
prappo
parents: 56269
diff changeset
   222
            setupHeader(opcode, last, expectedLen);
56269
234813fd33bc http-client-branch: (WebSocket) test fix + output closure
prappo
parents: 56263
diff changeset
   223
            previousFin = last;
56263
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   224
            previousText = false;
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   225
            started = true;
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   226
        }
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   227
        if (!putAvailable(headerBuffer, dst)) {
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   228
            return false;
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   229
        }
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   230
        int count = maskAvailable(src, dst);
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   231
        actualLen += Math.abs(count);
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   232
        if (count >= 0 && actualLen != expectedLen) {
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   233
            throw new IOException("Concurrent message modification");
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   234
        }
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   235
        return count >= 0;
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   236
    }
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   237
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   238
    private int maskAvailable(ByteBuffer src, ByteBuffer dst) {
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   239
        int r0 = dst.remaining();
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   240
        payloadMasker.transferMasking(src, dst);
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   241
        int masked = r0 - dst.remaining();
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   242
        return src.hasRemaining() ? -masked : masked;
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   243
    }
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   244
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   245
    public boolean encodePing(ByteBuffer src, ByteBuffer dst)
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   246
            throws IOException
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   247
    {
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   248
        if (closed) {
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   249
            throw new IOException("Output closed");
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   250
        }
56304
065641767a75 http-client-branch: change websocket to use System.Logger for debug logging
dfuchs
parents: 56295
diff changeset
   251
        debug.log(Level.DEBUG, "encodePing %s, %s", src, dst);
56263
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   252
        if (!started) {
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   253
            expectedLen = src.remaining();
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   254
            if (expectedLen > Frame.MAX_CONTROL_FRAME_PAYLOAD_LENGTH) {
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   255
                throw new IllegalArgumentException("Long message: " + expectedLen);
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   256
            }
56291
c8c4c707ff3a http-client-branch: (WebSocket) setting DEBUG to true; refactoring;
prappo
parents: 56269
diff changeset
   257
            setupHeader(Opcode.PING, true, expectedLen);
56263
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   258
            started = true;
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   259
        }
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   260
        if (!putAvailable(headerBuffer, dst)) {
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   261
            return false;
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   262
        }
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   263
        int count = maskAvailable(src, dst);
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   264
        actualLen += Math.abs(count);
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   265
        if (count >= 0 && actualLen != expectedLen) {
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   266
            throw new IOException("Concurrent message modification");
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   267
        }
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   268
        return count >= 0;
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   269
    }
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   270
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   271
    public boolean encodePong(ByteBuffer src, ByteBuffer dst)
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   272
            throws IOException
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   273
    {
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   274
        if (closed) {
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   275
            throw new IOException("Output closed");
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   276
        }
56304
065641767a75 http-client-branch: change websocket to use System.Logger for debug logging
dfuchs
parents: 56295
diff changeset
   277
        debug.log(Level.DEBUG, "encodePong %s, %s",
065641767a75 http-client-branch: change websocket to use System.Logger for debug logging
dfuchs
parents: 56295
diff changeset
   278
                  src, dst);
56263
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   279
        if (!started) {
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   280
            expectedLen = src.remaining();
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   281
            if (expectedLen > Frame.MAX_CONTROL_FRAME_PAYLOAD_LENGTH) {
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   282
                throw new IllegalArgumentException("Long message: " + expectedLen);
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   283
            }
56291
c8c4c707ff3a http-client-branch: (WebSocket) setting DEBUG to true; refactoring;
prappo
parents: 56269
diff changeset
   284
            setupHeader(Opcode.PONG, true, expectedLen);
56263
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   285
            started = true;
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   286
        }
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   287
        if (!putAvailable(headerBuffer, dst)) {
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   288
            return false;
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   289
        }
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   290
        int count = maskAvailable(src, dst);
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   291
        actualLen += Math.abs(count);
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   292
        if (count >= 0 && actualLen != expectedLen) {
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   293
            throw new IOException("Concurrent message modification");
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   294
        }
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   295
        return count >= 0;
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   296
    }
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   297
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   298
    public boolean encodeClose(int statusCode, CharBuffer reason, ByteBuffer dst)
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   299
            throws IOException
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   300
    {
56304
065641767a75 http-client-branch: change websocket to use System.Logger for debug logging
dfuchs
parents: 56295
diff changeset
   301
        debug.log(Level.DEBUG, "encodeClose %s, reason.length=%s, %s",
065641767a75 http-client-branch: change websocket to use System.Logger for debug logging
dfuchs
parents: 56295
diff changeset
   302
                  statusCode, reason.length(), dst);
56263
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   303
        if (closed) {
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   304
            throw new IOException("Output closed");
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   305
        }
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   306
        if (!started) {
56304
065641767a75 http-client-branch: change websocket to use System.Logger for debug logging
dfuchs
parents: 56295
diff changeset
   307
            debug.log(Level.DEBUG, "reason size %s", reason.remaining());
56263
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   308
            intermediateBuffer.position(0).limit(Frame.MAX_CONTROL_FRAME_PAYLOAD_LENGTH);
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   309
            intermediateBuffer.putChar((char) statusCode);
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   310
            CoderResult r = charsetEncoder.reset().encode(reason, intermediateBuffer, true);
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   311
            if (r.isUnderflow()) {
56304
065641767a75 http-client-branch: change websocket to use System.Logger for debug logging
dfuchs
parents: 56295
diff changeset
   312
                debug.log(Level.DEBUG, "flushing");
56263
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   313
                r = charsetEncoder.flush(intermediateBuffer);
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   314
            }
56304
065641767a75 http-client-branch: change websocket to use System.Logger for debug logging
dfuchs
parents: 56295
diff changeset
   315
            debug.log(Level.DEBUG, "encoding result: %s", r);
56263
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   316
            if (r.isError()) {
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   317
                try {
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   318
                    r.throwException();
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   319
                } catch (CharacterCodingException e) {
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   320
                    throw new IllegalArgumentException("Malformed reason", e);
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   321
                }
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   322
            } else if (r.isOverflow()) {
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   323
                // Here the 125 bytes size is ensured by the check for overflow
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   324
                throw new IllegalArgumentException("Long reason");
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   325
            } else if (!r.isUnderflow()) {
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   326
                throw new InternalError(); // assertion
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   327
            }
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   328
            intermediateBuffer.flip();
56291
c8c4c707ff3a http-client-branch: (WebSocket) setting DEBUG to true; refactoring;
prappo
parents: 56269
diff changeset
   329
            setupHeader(Opcode.CLOSE, true, intermediateBuffer.remaining());
56263
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   330
            started = true;
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   331
            closed = true;
56304
065641767a75 http-client-branch: change websocket to use System.Logger for debug logging
dfuchs
parents: 56295
diff changeset
   332
            debug.log(Level.DEBUG, "intermediateBuffer=%s",
065641767a75 http-client-branch: change websocket to use System.Logger for debug logging
dfuchs
parents: 56295
diff changeset
   333
                      intermediateBuffer);
56263
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   334
        }
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   335
        if (!putAvailable(headerBuffer, dst)) {
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   336
            return false;
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   337
        }
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   338
        return maskAvailable(intermediateBuffer, dst) >= 0;
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   339
    }
56291
c8c4c707ff3a http-client-branch: (WebSocket) setting DEBUG to true; refactoring;
prappo
parents: 56269
diff changeset
   340
c8c4c707ff3a http-client-branch: (WebSocket) setting DEBUG to true; refactoring;
prappo
parents: 56269
diff changeset
   341
    private void setupHeader(Opcode opcode, boolean fin, long payloadLen) {
56304
065641767a75 http-client-branch: change websocket to use System.Logger for debug logging
dfuchs
parents: 56295
diff changeset
   342
        debug.log(Level.DEBUG, "frame opcode=%s fin=%s len=%s",
065641767a75 http-client-branch: change websocket to use System.Logger for debug logging
dfuchs
parents: 56295
diff changeset
   343
                  opcode, fin, payloadLen);
56291
c8c4c707ff3a http-client-branch: (WebSocket) setting DEBUG to true; refactoring;
prappo
parents: 56269
diff changeset
   344
        headerBuffer.clear();
c8c4c707ff3a http-client-branch: (WebSocket) setting DEBUG to true; refactoring;
prappo
parents: 56269
diff changeset
   345
        int mask = maskingKeySource.nextInt();
c8c4c707ff3a http-client-branch: (WebSocket) setting DEBUG to true; refactoring;
prappo
parents: 56269
diff changeset
   346
        headerWriter.fin(fin)
c8c4c707ff3a http-client-branch: (WebSocket) setting DEBUG to true; refactoring;
prappo
parents: 56269
diff changeset
   347
                    .opcode(opcode)
c8c4c707ff3a http-client-branch: (WebSocket) setting DEBUG to true; refactoring;
prappo
parents: 56269
diff changeset
   348
                    .payloadLen(payloadLen)
c8c4c707ff3a http-client-branch: (WebSocket) setting DEBUG to true; refactoring;
prappo
parents: 56269
diff changeset
   349
                    .mask(mask)
c8c4c707ff3a http-client-branch: (WebSocket) setting DEBUG to true; refactoring;
prappo
parents: 56269
diff changeset
   350
                    .write(headerBuffer);
c8c4c707ff3a http-client-branch: (WebSocket) setting DEBUG to true; refactoring;
prappo
parents: 56269
diff changeset
   351
        headerBuffer.flip();
c8c4c707ff3a http-client-branch: (WebSocket) setting DEBUG to true; refactoring;
prappo
parents: 56269
diff changeset
   352
        payloadMasker.mask(mask);
c8c4c707ff3a http-client-branch: (WebSocket) setting DEBUG to true; refactoring;
prappo
parents: 56269
diff changeset
   353
    }
56263
4933a477d628 http-client-branch: (WebSocket) impl change
prappo
parents:
diff changeset
   354
}