websocket/src/main/java/org/nanohttpd/protocols/websockets/WebSocketFrame.java
private void readPayloadInfo(InputStream in) throws IOException {
        byte b = (byte) checkedRead(in.read());
        boolean masked = (b & 0x80) != 0;

        this._payloadLength = (byte) (0x7F & b);
        if (this._payloadLength == 126) {
            // checkedRead must return int for this to work
            this._payloadLength = (checkedRead(in.read()) << 8 | checkedRead(in.read())) & 0xFFFF;
            if (this._payloadLength < 126) {
                throw new WebSocketException(CloseCode.ProtocolError, "Invalid data frame 2byte length. (not using minimal length encoding)");
            }
        } else if (this._payloadLength == 127) {
            long _payloadLength =
                    (long) checkedRead(in.read()) << 56 | (long) checkedRead(in.read()) << 48 | (long) checkedRead(in.read()) << 40 | (long) checkedRead(in.read()) << 32
                            | checkedRead(in.read()) << 24 | checkedRead(in.read()) << 16 | checkedRead(in.read()) << 8 | checkedRead(in.read());
            if (_payloadLength < 65536) {
                throw new WebSocketException(CloseCode.ProtocolError, "Invalid data frame 4byte length. (not using minimal length encoding)");
            }
            if (_payloadLength < 0 || _payloadLength > Integer.MAX_VALUE) {
                throw new WebSocketException(CloseCode.MessageTooBig, "Max frame length has been exceeded.");
            }
            this._payloadLength = (int) _payloadLength;
        }

        if (this.opCode.isControlFrame()) {
            if (this._payloadLength > 125) {
                throw new WebSocketException(CloseCode.ProtocolError, "Control frame with payload length > 125 bytes.");
            }
            if (this.opCode == OpCode.Close && this._payloadLength == 1) {
                throw new WebSocketException(CloseCode.ProtocolError, "Received close frame with payload len 1.");
            }
        }

        if (masked) {
            this.maskingKey = new byte[4];
            int read = 0;
            while (read < this.maskingKey.length) {
                read += checkedRead(in.read(this.maskingKey, read, this.maskingKey.length - read));
            }
        }
    }
private void readPayloadInfo(InputStream in) throws IOException {
        byte b = (byte) checkedRead(in.read());
        boolean masked = (b & 0x80) != 0;

        this._payloadLength = (byte) (0x7F & b);
        if (this._payloadLength == 126) {
            // checkedRead must return int for this to work
            this._payloadLength = (checkedRead(in.read()) << 8 | checkedRead(in.read())) & 0xFFFF;
            if (this._payloadLength < 126) {
                throw new WebSocketException(CloseCode.ProtocolError, "Invalid data frame 2byte length. (not using minimal length encoding)");
            }
        } else if (this._payloadLength == 127) {
            long _payloadLength =
                    (long) checkedRead(in.read()) << 56 | (long) checkedRead(in.read()) << 48 | (long) checkedRead(in.read()) << 40 | (long) checkedRead(in.read()) << 32
                            | checkedRead(in.read()) << 24 | checkedRead(in.read()) << 16 | checkedRead(in.read()) << 8 | checkedRead(in.read());
            if (_payloadLength < 65536) {
                throw new WebSocketException(CloseCode.ProtocolError, "Invalid data frame 4byte length. (not using minimal length encoding)");
            }
            if (_payloadLength < 0 || _payloadLength > Integer.MAX_VALUE) {
                throw new WebSocketException(CloseCode.MessageTooBig, "Max frame length has been exceeded.");
            }
            this._payloadLength = (int) _payloadLength;
        }

        if (this.opCode.isControlFrame()) {
            if (this._payloadLength > 125) {
                throw new WebSocketException(CloseCode.ProtocolError, "Control frame with payload length > 125 bytes.");
            }
            if (this.opCode == OpCode.Close && this._payloadLength == 1) {
                throw new WebSocketException(CloseCode.ProtocolError, "Received close frame with payload len 1.");
            }
        }

        if (masked) {
            this.maskingKey = new byte[4];
            int read = 0;
            while (read < this.maskingKey.length) {
                read += checkedRead(in.read(this.maskingKey, read, this.maskingKey.length - read));
            }
        }
    }
private void readPayloadInfo ( InputStream in ) throws IOException { byte b = ( byte ) checkedRead ( in . read ( ) ) ; boolean masked = ( b & 0x80 ) != 0 ; this . _payloadLength = ( byte ) ( 0x7F & b ) ; if ( this . _payloadLength == 126 ) { // checkedRead must return int for this to work this . _payloadLength = ( checkedRead ( in . read ( ) ) << 8 | checkedRead ( in . read ( ) ) ) & 0xFFFF ; if ( this . _payloadLength < 126 ) { throw new WebSocketException ( CloseCode . ProtocolError , "Invalid data frame 2byte length. (not using minimal length encoding)" ) ; } } else if ( this . _payloadLength == 127 ) { long _payloadLength = ( long ) checkedRead ( in . read ( ) ) << 56 | ( long ) checkedRead ( in . read ( ) ) << 48 | ( long ) checkedRead ( in . read ( ) ) << 40 | ( long ) checkedRead ( in . read ( ) ) << 32 | checkedRead ( in . read ( ) ) << 24 | checkedRead ( in . read ( ) ) << 16 | checkedRead ( in . read ( ) ) << 8 | checkedRead ( in . read ( ) ) ; if ( _payloadLength < 65536 ) { throw new WebSocketException ( CloseCode . ProtocolError , "Invalid data frame 4byte length. (not using minimal length encoding)" ) ; } if ( _payloadLength < 0 || _payloadLength > Integer . MAX_VALUE ) { throw new WebSocketException ( CloseCode . MessageTooBig , "Max frame length has been exceeded." ) ; } this . _payloadLength = ( int ) _payloadLength ; } if ( this . opCode . isControlFrame ( ) ) { if ( this . _payloadLength > 125 ) { throw new WebSocketException ( CloseCode . ProtocolError , "Control frame with payload length > 125 bytes." ) ; } if ( this . opCode == OpCode . Close && this . _payloadLength == 1 ) { throw new WebSocketException ( CloseCode . ProtocolError , "Received close frame with payload len 1." ) ; } } if ( masked ) { this . maskingKey = new byte [ 4 ] ; int read = 0 ; while ( read < this . maskingKey . length ) { read += checkedRead ( in . read ( this . maskingKey , read , this . maskingKey . length - read ) ) ; } } }
--------------------------------ENCODING--------------------------------
-------------------------------- ENCODING --------------------------------