@Test public void calculateLengthEncodedSizeFor2097151() { assertEquals(3, WsUtils.calculateEncodedLengthSize(2097151)); }
public static int calculateEncodedLengthSize(int lengthValue) { int ceilLog2LengthPlus1 = 32 - Integer.numberOfLeadingZeros(lengthValue); switch (ceilLog2LengthPlus1) { case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7: return 1; case 8: case 9: case 10: case 11: case 12: case 13: case 14: return 2; case 15: case 16: case 17: case 18: case 19: case 20: case 21: return 3; case 22: case 23: case 24: case 25: case 26: case 27: case 28: return 4; case 29: case 30: case 31: return 5; default: throw new IllegalArgumentException("Negative length is not supported"); } }
WsUtils { public static int calculateEncodedLengthSize(int lengthValue) { int ceilLog2LengthPlus1 = 32 - Integer.numberOfLeadingZeros(lengthValue); switch (ceilLog2LengthPlus1) { case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7: return 1; case 8: case 9: case 10: case 11: case 12: case 13: case 14: return 2; case 15: case 16: case 17: case 18: case 19: case 20: case 21: return 3; case 22: case 23: case 24: case 25: case 26: case 27: case 28: return 4; case 29: case 30: case 31: return 5; default: throw new IllegalArgumentException("Negative length is not supported"); } } }
WsUtils { public static int calculateEncodedLengthSize(int lengthValue) { int ceilLog2LengthPlus1 = 32 - Integer.numberOfLeadingZeros(lengthValue); switch (ceilLog2LengthPlus1) { case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7: return 1; case 8: case 9: case 10: case 11: case 12: case 13: case 14: return 2; case 15: case 16: case 17: case 18: case 19: case 20: case 21: return 3; case 22: case 23: case 24: case 25: case 26: case 27: case 28: return 4; case 29: case 30: case 31: return 5; default: throw new IllegalArgumentException("Negative length is not supported"); } } private  WsUtils(); }
WsUtils { public static int calculateEncodedLengthSize(int lengthValue) { int ceilLog2LengthPlus1 = 32 - Integer.numberOfLeadingZeros(lengthValue); switch (ceilLog2LengthPlus1) { case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7: return 1; case 8: case 9: case 10: case 11: case 12: case 13: case 14: return 2; case 15: case 16: case 17: case 18: case 19: case 20: case 21: return 3; case 22: case 23: case 24: case 25: case 26: case 27: case 28: return 4; case 29: case 30: case 31: return 5; default: throw new IllegalArgumentException("Negative length is not supported"); } } private  WsUtils(); static void addExtensionFilters(List<WebSocketExtension> extensions,
                                           ExtensionHelper helper,
                                           IoFilterChain filterChain,
                                           boolean hasCodec); static ByteBuffer computeHash(CharSequence key1, CharSequence key2, ByteBuffer key3); static String acceptHash(String key); static int calculateEncodedLengthSize(int lengthValue); static void encodeLength(ByteBuffer buf, int lengthValue); static void handleExtensionNegotiationException(HttpAcceptSession session, List<String> clientRequestedExtensions,
                                                            ProtocolException e, Logger logger); static WebSocketWireProtocol guessWireProtocolVersion(HttpRequestMessage httpRequest); static List<WebSocketExtension> negotiateExtensionsAndSetResponseHeader(
                                                        WebSocketExtensionFactory factory,
                                                        WsResourceAddress address,
                                                        List<String> requestedExtensions,
                                                        HttpAcceptSession session,
                                                        String extendionsHeaderName, ExtensionHelper extensionHelper); static String negotiateWebSocketProtocol(HttpAcceptSession session, String protocolHeaderName,
                                                    List<String> clientRequestedWsProtocols,
                                                    List<String> serverWsProtocols); static void removeExtensionFilters(List<WebSocketExtension> extensions, IoFilterChain filterChain); static String secWebSocketKey(); }
WsUtils { public static int calculateEncodedLengthSize(int lengthValue) { int ceilLog2LengthPlus1 = 32 - Integer.numberOfLeadingZeros(lengthValue); switch (ceilLog2LengthPlus1) { case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7: return 1; case 8: case 9: case 10: case 11: case 12: case 13: case 14: return 2; case 15: case 16: case 17: case 18: case 19: case 20: case 21: return 3; case 22: case 23: case 24: case 25: case 26: case 27: case 28: return 4; case 29: case 30: case 31: return 5; default: throw new IllegalArgumentException("Negative length is not supported"); } } private  WsUtils(); static void addExtensionFilters(List<WebSocketExtension> extensions,
                                           ExtensionHelper helper,
                                           IoFilterChain filterChain,
                                           boolean hasCodec); static ByteBuffer computeHash(CharSequence key1, CharSequence key2, ByteBuffer key3); static String acceptHash(String key); static int calculateEncodedLengthSize(int lengthValue); static void encodeLength(ByteBuffer buf, int lengthValue); static void handleExtensionNegotiationException(HttpAcceptSession session, List<String> clientRequestedExtensions,
                                                            ProtocolException e, Logger logger); static WebSocketWireProtocol guessWireProtocolVersion(HttpRequestMessage httpRequest); static List<WebSocketExtension> negotiateExtensionsAndSetResponseHeader(
                                                        WebSocketExtensionFactory factory,
                                                        WsResourceAddress address,
                                                        List<String> requestedExtensions,
                                                        HttpAcceptSession session,
                                                        String extendionsHeaderName, ExtensionHelper extensionHelper); static String negotiateWebSocketProtocol(HttpAcceptSession session, String protocolHeaderName,
                                                    List<String> clientRequestedWsProtocols,
                                                    List<String> serverWsProtocols); static void removeExtensionFilters(List<WebSocketExtension> extensions, IoFilterChain filterChain); static String secWebSocketKey(); static final String SEC_WEB_SOCKET_VERSION; static final String SEC_WEB_SOCKET_KEY; static final String SEC_WEB_SOCKET_KEY1; static final String SEC_WEB_SOCKET_KEY2; static final String HEADER_X_WEBSOCKET_EXTENSIONS; static final String HEADER_WEBSOCKET_EXTENSIONS; static final String HEADER_SEC_WEBSOCKET_EXTENSIONS; static final TypedAttributeKey<List<WebSocketExtension>> ACTIVE_EXTENSIONS_KEY; }