Java 8 migration. Use string switch where possible (#8753)
Motivation: Replace "if else" conditions with string switch. It is easier to read the code, for large "if else" constructions switch also could be faster. Modification: Replaced "if else" with a string switch. Result: Use new language features
This commit is contained in:
parent
c34340fff8
commit
5fb515f4af
|
@ -34,6 +34,12 @@ final class HttpPostBodyUtil {
|
|||
*/
|
||||
public static final String DEFAULT_TEXT_CONTENT_TYPE = "text/plain";
|
||||
|
||||
static final String BIT_7_STRING = "7bit";
|
||||
|
||||
static final String BIT_8_STRING = "8bit";
|
||||
|
||||
static final String BINARY_STRING = "binary";
|
||||
|
||||
/**
|
||||
* Allowed mechanism for multipart
|
||||
* mechanism := "7bit"
|
||||
|
@ -46,15 +52,15 @@ final class HttpPostBodyUtil {
|
|||
/**
|
||||
* Default encoding
|
||||
*/
|
||||
BIT7("7bit"),
|
||||
BIT7(BIT_7_STRING),
|
||||
/**
|
||||
* Short lines but not in ASCII - no encoding
|
||||
*/
|
||||
BIT8("8bit"),
|
||||
BIT8(BIT_8_STRING),
|
||||
/**
|
||||
* Could be long text not in ASCII - no encoding
|
||||
*/
|
||||
BINARY("binary");
|
||||
BINARY(BINARY_STRING);
|
||||
|
||||
private final String value;
|
||||
|
||||
|
|
|
@ -41,8 +41,12 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
import static io.netty.buffer.Unpooled.*;
|
||||
import static io.netty.util.internal.ObjectUtil.*;
|
||||
import static io.netty.buffer.Unpooled.buffer;
|
||||
import static io.netty.handler.codec.http.multipart.HttpPostBodyUtil.BINARY_STRING;
|
||||
import static io.netty.handler.codec.http.multipart.HttpPostBodyUtil.BIT_7_STRING;
|
||||
import static io.netty.handler.codec.http.multipart.HttpPostBodyUtil.BIT_8_STRING;
|
||||
import static io.netty.util.internal.ObjectUtil.checkNotNull;
|
||||
import static io.netty.util.internal.ObjectUtil.checkPositiveOrZero;
|
||||
|
||||
/**
|
||||
* This decoder will decode Body and can handle POST BODY.
|
||||
|
@ -849,16 +853,20 @@ public class HttpPostMultipartRequestDecoder implements InterfaceHttpPostRequest
|
|||
} catch (IOException e) {
|
||||
throw new ErrorDataDecoderException(e);
|
||||
}
|
||||
if (code.equals(HttpPostBodyUtil.TransferEncodingMechanism.BIT7.value())) {
|
||||
localCharset = CharsetUtil.US_ASCII;
|
||||
} else if (code.equals(HttpPostBodyUtil.TransferEncodingMechanism.BIT8.value())) {
|
||||
localCharset = CharsetUtil.ISO_8859_1;
|
||||
mechanism = TransferEncodingMechanism.BIT8;
|
||||
} else if (code.equals(HttpPostBodyUtil.TransferEncodingMechanism.BINARY.value())) {
|
||||
// no real charset, so let the default
|
||||
mechanism = TransferEncodingMechanism.BINARY;
|
||||
} else {
|
||||
throw new ErrorDataDecoderException("TransferEncoding Unknown: " + code);
|
||||
switch (code) {
|
||||
case BIT_7_STRING:
|
||||
localCharset = CharsetUtil.US_ASCII;
|
||||
break;
|
||||
case BIT_8_STRING:
|
||||
localCharset = CharsetUtil.ISO_8859_1;
|
||||
mechanism = TransferEncodingMechanism.BIT8;
|
||||
break;
|
||||
case BINARY_STRING:
|
||||
// no real charset, so let the default
|
||||
mechanism = TransferEncodingMechanism.BINARY;
|
||||
break;
|
||||
default:
|
||||
throw new ErrorDataDecoderException("TransferEncoding Unknown: " + code);
|
||||
}
|
||||
}
|
||||
Attribute charsetAttribute = currentFieldAttributes.get(HttpHeaderValues.CHARSET);
|
||||
|
|
|
@ -1515,48 +1515,55 @@ public class ReferenceCountedOpenSslEngine extends SSLEngine implements Referenc
|
|||
if (!OpenSsl.SUPPORTED_PROTOCOLS_SET.contains(p)) {
|
||||
throw new IllegalArgumentException("Protocol " + p + " is not supported.");
|
||||
}
|
||||
if (p.equals(PROTOCOL_SSL_V2)) {
|
||||
if (minProtocolIndex > OPENSSL_OP_NO_PROTOCOL_INDEX_SSLV2) {
|
||||
minProtocolIndex = OPENSSL_OP_NO_PROTOCOL_INDEX_SSLV2;
|
||||
}
|
||||
if (maxProtocolIndex < OPENSSL_OP_NO_PROTOCOL_INDEX_SSLV2) {
|
||||
maxProtocolIndex = OPENSSL_OP_NO_PROTOCOL_INDEX_SSLV2;
|
||||
}
|
||||
} else if (p.equals(PROTOCOL_SSL_V3)) {
|
||||
if (minProtocolIndex > OPENSSL_OP_NO_PROTOCOL_INDEX_SSLV3) {
|
||||
minProtocolIndex = OPENSSL_OP_NO_PROTOCOL_INDEX_SSLV3;
|
||||
}
|
||||
if (maxProtocolIndex < OPENSSL_OP_NO_PROTOCOL_INDEX_SSLV3) {
|
||||
maxProtocolIndex = OPENSSL_OP_NO_PROTOCOL_INDEX_SSLV3;
|
||||
}
|
||||
} else if (p.equals(PROTOCOL_TLS_V1)) {
|
||||
if (minProtocolIndex > OPENSSL_OP_NO_PROTOCOL_INDEX_TLSv1) {
|
||||
minProtocolIndex = OPENSSL_OP_NO_PROTOCOL_INDEX_TLSv1;
|
||||
}
|
||||
if (maxProtocolIndex < OPENSSL_OP_NO_PROTOCOL_INDEX_TLSv1) {
|
||||
maxProtocolIndex = OPENSSL_OP_NO_PROTOCOL_INDEX_TLSv1;
|
||||
}
|
||||
} else if (p.equals(PROTOCOL_TLS_V1_1)) {
|
||||
if (minProtocolIndex > OPENSSL_OP_NO_PROTOCOL_INDEX_TLSv1_1) {
|
||||
minProtocolIndex = OPENSSL_OP_NO_PROTOCOL_INDEX_TLSv1_1;
|
||||
}
|
||||
if (maxProtocolIndex < OPENSSL_OP_NO_PROTOCOL_INDEX_TLSv1_1) {
|
||||
maxProtocolIndex = OPENSSL_OP_NO_PROTOCOL_INDEX_TLSv1_1;
|
||||
}
|
||||
} else if (p.equals(PROTOCOL_TLS_V1_2)) {
|
||||
if (minProtocolIndex > OPENSSL_OP_NO_PROTOCOL_INDEX_TLSv1_2) {
|
||||
minProtocolIndex = OPENSSL_OP_NO_PROTOCOL_INDEX_TLSv1_2;
|
||||
}
|
||||
if (maxProtocolIndex < OPENSSL_OP_NO_PROTOCOL_INDEX_TLSv1_2) {
|
||||
maxProtocolIndex = OPENSSL_OP_NO_PROTOCOL_INDEX_TLSv1_2;
|
||||
}
|
||||
} else if (p.equals(PROTOCOL_TLS_V1_3)) {
|
||||
if (minProtocolIndex > OPENSSL_OP_NO_PROTOCOL_INDEX_TLSv1_3) {
|
||||
minProtocolIndex = OPENSSL_OP_NO_PROTOCOL_INDEX_TLSv1_3;
|
||||
}
|
||||
if (maxProtocolIndex < OPENSSL_OP_NO_PROTOCOL_INDEX_TLSv1_3) {
|
||||
maxProtocolIndex = OPENSSL_OP_NO_PROTOCOL_INDEX_TLSv1_3;
|
||||
}
|
||||
switch (p) {
|
||||
case PROTOCOL_SSL_V2:
|
||||
if (minProtocolIndex > OPENSSL_OP_NO_PROTOCOL_INDEX_SSLV2) {
|
||||
minProtocolIndex = OPENSSL_OP_NO_PROTOCOL_INDEX_SSLV2;
|
||||
}
|
||||
if (maxProtocolIndex < OPENSSL_OP_NO_PROTOCOL_INDEX_SSLV2) {
|
||||
maxProtocolIndex = OPENSSL_OP_NO_PROTOCOL_INDEX_SSLV2;
|
||||
}
|
||||
break;
|
||||
case PROTOCOL_SSL_V3:
|
||||
if (minProtocolIndex > OPENSSL_OP_NO_PROTOCOL_INDEX_SSLV3) {
|
||||
minProtocolIndex = OPENSSL_OP_NO_PROTOCOL_INDEX_SSLV3;
|
||||
}
|
||||
if (maxProtocolIndex < OPENSSL_OP_NO_PROTOCOL_INDEX_SSLV3) {
|
||||
maxProtocolIndex = OPENSSL_OP_NO_PROTOCOL_INDEX_SSLV3;
|
||||
}
|
||||
break;
|
||||
case PROTOCOL_TLS_V1:
|
||||
if (minProtocolIndex > OPENSSL_OP_NO_PROTOCOL_INDEX_TLSv1) {
|
||||
minProtocolIndex = OPENSSL_OP_NO_PROTOCOL_INDEX_TLSv1;
|
||||
}
|
||||
if (maxProtocolIndex < OPENSSL_OP_NO_PROTOCOL_INDEX_TLSv1) {
|
||||
maxProtocolIndex = OPENSSL_OP_NO_PROTOCOL_INDEX_TLSv1;
|
||||
}
|
||||
break;
|
||||
case PROTOCOL_TLS_V1_1:
|
||||
if (minProtocolIndex > OPENSSL_OP_NO_PROTOCOL_INDEX_TLSv1_1) {
|
||||
minProtocolIndex = OPENSSL_OP_NO_PROTOCOL_INDEX_TLSv1_1;
|
||||
}
|
||||
if (maxProtocolIndex < OPENSSL_OP_NO_PROTOCOL_INDEX_TLSv1_1) {
|
||||
maxProtocolIndex = OPENSSL_OP_NO_PROTOCOL_INDEX_TLSv1_1;
|
||||
}
|
||||
break;
|
||||
case PROTOCOL_TLS_V1_2:
|
||||
if (minProtocolIndex > OPENSSL_OP_NO_PROTOCOL_INDEX_TLSv1_2) {
|
||||
minProtocolIndex = OPENSSL_OP_NO_PROTOCOL_INDEX_TLSv1_2;
|
||||
}
|
||||
if (maxProtocolIndex < OPENSSL_OP_NO_PROTOCOL_INDEX_TLSv1_2) {
|
||||
maxProtocolIndex = OPENSSL_OP_NO_PROTOCOL_INDEX_TLSv1_2;
|
||||
}
|
||||
break;
|
||||
case PROTOCOL_TLS_V1_3:
|
||||
if (minProtocolIndex > OPENSSL_OP_NO_PROTOCOL_INDEX_TLSv1_3) {
|
||||
minProtocolIndex = OPENSSL_OP_NO_PROTOCOL_INDEX_TLSv1_3;
|
||||
}
|
||||
if (maxProtocolIndex < OPENSSL_OP_NO_PROTOCOL_INDEX_TLSv1_3) {
|
||||
maxProtocolIndex = OPENSSL_OP_NO_PROTOCOL_INDEX_TLSv1_3;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
synchronized (this) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user