diff --git a/codec-dns/src/main/java/io/netty/handler/codec/dns/DefaultDnsRecordEncoder.java b/codec-dns/src/main/java/io/netty/handler/codec/dns/DefaultDnsRecordEncoder.java index 679e87e83e..63d7ac08e7 100644 --- a/codec-dns/src/main/java/io/netty/handler/codec/dns/DefaultDnsRecordEncoder.java +++ b/codec-dns/src/main/java/io/netty/handler/codec/dns/DefaultDnsRecordEncoder.java @@ -87,7 +87,7 @@ public class DefaultDnsRecordEncoder implements DnsRecordEncoder { return; } - final String[] labels = StringUtil.split(name, '.'); + final String[] labels = name.split("\\."); for (String label : labels) { final int labelLen = label.length(); if (labelLen == 0) { diff --git a/codec-haproxy/src/main/java/io/netty/handler/codec/haproxy/HAProxyMessage.java b/codec-haproxy/src/main/java/io/netty/handler/codec/haproxy/HAProxyMessage.java index 7172c00d03..5c3f804d3d 100644 --- a/codec-haproxy/src/main/java/io/netty/handler/codec/haproxy/HAProxyMessage.java +++ b/codec-haproxy/src/main/java/io/netty/handler/codec/haproxy/HAProxyMessage.java @@ -20,7 +20,6 @@ import io.netty.handler.codec.haproxy.HAProxyProxiedProtocol.AddressFamily; import io.netty.util.ByteProcessor; import io.netty.util.CharsetUtil; import io.netty.util.NetUtil; -import io.netty.util.internal.StringUtil; /** * Message container for decoded HAProxy proxy protocol parameters @@ -227,7 +226,7 @@ public final class HAProxyMessage { throw new HAProxyProtocolException("header"); } - String[] parts = StringUtil.split(header, ' '); + String[] parts = header.split(" "); int numParts = parts.length; if (numParts < 2) { diff --git a/codec-http/src/main/java/io/netty/handler/codec/http/CookieDecoder.java b/codec-http/src/main/java/io/netty/handler/codec/http/CookieDecoder.java index b71b7ad1de..137266bbea 100644 --- a/codec-http/src/main/java/io/netty/handler/codec/http/CookieDecoder.java +++ b/codec-http/src/main/java/io/netty/handler/codec/http/CookieDecoder.java @@ -19,7 +19,6 @@ import static io.netty.handler.codec.http.CookieUtil.firstInvalidCookieNameOctet import static io.netty.handler.codec.http.CookieUtil.firstInvalidCookieValueOctet; import static io.netty.handler.codec.http.CookieUtil.unwrapValue; import io.netty.handler.codec.http.cookie.CookieHeaderNames; -import io.netty.util.internal.StringUtil; import io.netty.util.internal.logging.InternalLogger; import io.netty.util.internal.logging.InternalLoggerFactory; @@ -65,8 +64,6 @@ public final class CookieDecoder { private static final String VERSION = "Version"; - private static final char COMMA = ','; - private final boolean strict; public static Set decode(String header) { @@ -169,7 +166,7 @@ public final class CookieDecoder { } else if (VERSION.equalsIgnoreCase(name)) { version = Integer.parseInt(value); } else if (PORT.equalsIgnoreCase(name)) { - String[] portList = StringUtil.split(value, COMMA); + String[] portList = value.split(","); for (String s1: portList) { try { ports.add(Integer.valueOf(s1)); diff --git a/codec-http/src/main/java/io/netty/handler/codec/http/HttpContentCompressor.java b/codec-http/src/main/java/io/netty/handler/codec/http/HttpContentCompressor.java index ac9e08f6a2..134be08c00 100644 --- a/codec-http/src/main/java/io/netty/handler/codec/http/HttpContentCompressor.java +++ b/codec-http/src/main/java/io/netty/handler/codec/http/HttpContentCompressor.java @@ -19,7 +19,6 @@ import io.netty.channel.ChannelHandlerContext; import io.netty.channel.embedded.EmbeddedChannel; import io.netty.handler.codec.compression.ZlibCodecFactory; import io.netty.handler.codec.compression.ZlibWrapper; -import io.netty.util.internal.StringUtil; /** * Compresses an {@link HttpMessage} and an {@link HttpContent} in {@code gzip} or @@ -136,7 +135,7 @@ public class HttpContentCompressor extends HttpContentEncoder { float starQ = -1.0f; float gzipQ = -1.0f; float deflateQ = -1.0f; - for (String encoding: StringUtil.split(acceptEncoding, ',')) { + for (String encoding : acceptEncoding.split(",")) { float q = 1.0f; int equalsPos = encoding.indexOf('='); if (equalsPos != -1) { diff --git a/codec-http/src/main/java/io/netty/handler/codec/http/HttpHeaders.java b/codec-http/src/main/java/io/netty/handler/codec/http/HttpHeaders.java index fe399f0956..394eaa01d1 100644 --- a/codec-http/src/main/java/io/netty/handler/codec/http/HttpHeaders.java +++ b/codec-http/src/main/java/io/netty/handler/codec/http/HttpHeaders.java @@ -19,7 +19,6 @@ import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBufUtil; import io.netty.handler.codec.Headers; import io.netty.util.AsciiString; -import io.netty.util.internal.StringUtil; import java.text.ParseException; import java.util.Calendar; @@ -1591,7 +1590,7 @@ public abstract class HttpHeaders implements Iterable> } private static boolean contains(String value, CharSequence expected, boolean ignoreCase) { - String[] parts = StringUtil.split(value, ','); + String[] parts = value.split(","); if (ignoreCase) { for (String s: parts) { if (AsciiString.contentEqualsIgnoreCase(expected, s.trim())) { diff --git a/codec-http/src/main/java/io/netty/handler/codec/http/multipart/HttpPostMultipartRequestDecoder.java b/codec-http/src/main/java/io/netty/handler/codec/http/multipart/HttpPostMultipartRequestDecoder.java index bb1b746b25..389636476e 100644 --- a/codec-http/src/main/java/io/netty/handler/codec/http/multipart/HttpPostMultipartRequestDecoder.java +++ b/codec-http/src/main/java/io/netty/handler/codec/http/multipart/HttpPostMultipartRequestDecoder.java @@ -704,7 +704,7 @@ public class HttpPostMultipartRequestDecoder implements InterfaceHttpPostRequest if (checkSecondArg) { // read next values and store them in the map as Attribute for (int i = 2; i < contents.length; i++) { - String[] values = StringUtil.split(contents[i], '=', 2); + String[] values = contents[i].split("=", 2); Attribute attribute; try { String name = cleanString(values[0]); @@ -1825,7 +1825,7 @@ public class HttpPostMultipartRequestDecoder implements InterfaceHttpPostRequest if (svalue.indexOf(';') >= 0) { values = splitMultipartHeaderValues(svalue); } else { - values = StringUtil.split(svalue, ','); + values = svalue.split(","); } for (String value : values) { headers.add(value.trim()); diff --git a/codec-http/src/main/java/io/netty/handler/codec/http/websocketx/WebSocketClientHandshaker.java b/codec-http/src/main/java/io/netty/handler/codec/http/websocketx/WebSocketClientHandshaker.java index 5f13bd462e..2f7c48e582 100644 --- a/codec-http/src/main/java/io/netty/handler/codec/http/websocketx/WebSocketClientHandshaker.java +++ b/codec-http/src/main/java/io/netty/handler/codec/http/websocketx/WebSocketClientHandshaker.java @@ -34,7 +34,6 @@ import io.netty.handler.codec.http.HttpResponse; import io.netty.handler.codec.http.HttpResponseDecoder; import io.netty.handler.codec.http.HttpScheme; import io.netty.util.ReferenceCountUtil; -import io.netty.util.internal.StringUtil; import io.netty.util.internal.ThrowableUtil; import java.net.URI; @@ -224,7 +223,7 @@ public abstract class WebSocketClientHandshaker { setActualSubprotocol(expectedSubprotocol); // null or "" - we echo what the user requested } else if (!expectedProtocol.isEmpty() && receivedProtocol != null && !receivedProtocol.isEmpty()) { // We require a subprotocol and received one -> verify it - for (String protocol : StringUtil.split(expectedSubprotocol, ',')) { + for (String protocol : expectedProtocol.split(",")) { if (protocol.trim().equals(receivedProtocol)) { protocolValid = true; setActualSubprotocol(receivedProtocol); diff --git a/codec-http/src/main/java/io/netty/handler/codec/http/websocketx/WebSocketServerHandshaker.java b/codec-http/src/main/java/io/netty/handler/codec/http/websocketx/WebSocketServerHandshaker.java index 00c54fe919..4eb43484c4 100644 --- a/codec-http/src/main/java/io/netty/handler/codec/http/websocketx/WebSocketServerHandshaker.java +++ b/codec-http/src/main/java/io/netty/handler/codec/http/websocketx/WebSocketServerHandshaker.java @@ -33,7 +33,6 @@ import io.netty.handler.codec.http.HttpResponseEncoder; import io.netty.handler.codec.http.HttpServerCodec; import io.netty.util.ReferenceCountUtil; import io.netty.util.internal.EmptyArrays; -import io.netty.util.internal.StringUtil; import io.netty.util.internal.ThrowableUtil; import io.netty.util.internal.logging.InternalLogger; import io.netty.util.internal.logging.InternalLoggerFactory; @@ -85,7 +84,7 @@ public abstract class WebSocketServerHandshaker { this.version = version; this.uri = uri; if (subprotocols != null) { - String[] subprotocolArray = StringUtil.split(subprotocols, ','); + String[] subprotocolArray = subprotocols.split(","); for (int i = 0; i < subprotocolArray.length; i++) { subprotocolArray[i] = subprotocolArray[i].trim(); } @@ -344,7 +343,7 @@ public abstract class WebSocketServerHandshaker { return null; } - String[] requestedSubprotocolArray = StringUtil.split(requestedSubprotocols, ','); + String[] requestedSubprotocolArray = requestedSubprotocols.split(","); for (String p: requestedSubprotocolArray) { String requestedSubprotocol = p.trim(); diff --git a/codec-http/src/main/java/io/netty/handler/codec/http/websocketx/extensions/WebSocketExtensionUtil.java b/codec-http/src/main/java/io/netty/handler/codec/http/websocketx/extensions/WebSocketExtensionUtil.java index 3b0af94739..fd91f72eab 100644 --- a/codec-http/src/main/java/io/netty/handler/codec/http/websocketx/extensions/WebSocketExtensionUtil.java +++ b/codec-http/src/main/java/io/netty/handler/codec/http/websocketx/extensions/WebSocketExtensionUtil.java @@ -18,7 +18,6 @@ package io.netty.handler.codec.http.websocketx.extensions; import io.netty.handler.codec.http.HttpHeaderNames; import io.netty.handler.codec.http.HttpHeaderValues; import io.netty.handler.codec.http.HttpHeaders; -import io.netty.util.internal.StringUtil; import java.util.ArrayList; import java.util.Collections; @@ -31,8 +30,8 @@ import java.util.regex.Pattern; public final class WebSocketExtensionUtil { - private static final char EXTENSION_SEPARATOR = ','; - private static final char PARAMETER_SEPARATOR = ';'; + private static final String EXTENSION_SEPARATOR = ","; + private static final String PARAMETER_SEPARATOR = ";"; private static final char PARAMETER_EQUAL = '='; private static final Pattern PARAMETER = Pattern.compile("^([^=]+)(=[\\\"]?([^\\\"]+)[\\\"]?)?$"); @@ -43,11 +42,11 @@ public final class WebSocketExtensionUtil { } public static List extractExtensions(String extensionHeader) { - String[] rawExtensions = StringUtil.split(extensionHeader, EXTENSION_SEPARATOR); + String[] rawExtensions = extensionHeader.split(EXTENSION_SEPARATOR); if (rawExtensions.length > 0) { List extensions = new ArrayList(rawExtensions.length); for (String rawExtension : rawExtensions) { - String[] extensionParameters = StringUtil.split(rawExtension, PARAMETER_SEPARATOR); + String[] extensionParameters = rawExtension.split(PARAMETER_SEPARATOR); String name = extensionParameters[0].trim(); Map parameters; if (extensionParameters.length > 1) { @@ -60,7 +59,7 @@ public final class WebSocketExtensionUtil { } } } else { - parameters = Collections.emptyMap(); + parameters = Collections.emptyMap(); } extensions.add(new WebSocketExtensionData(name, parameters)); } @@ -74,19 +73,14 @@ public final class WebSocketExtensionUtil { Map extensionParameters) { StringBuilder newHeaderValue = new StringBuilder( - currentHeaderValue != null ? currentHeaderValue.length() : 0 + extensionName.length() + 1); + currentHeaderValue != null ? currentHeaderValue.length() : extensionName.length() + 1); if (currentHeaderValue != null && !currentHeaderValue.trim().isEmpty()) { newHeaderValue.append(currentHeaderValue); newHeaderValue.append(EXTENSION_SEPARATOR); } newHeaderValue.append(extensionName); - boolean isFirst = true; for (Entry extensionParameter : extensionParameters.entrySet()) { - if (isFirst) { - newHeaderValue.append(PARAMETER_SEPARATOR); - } else { - isFirst = false; - } + newHeaderValue.append(PARAMETER_SEPARATOR); newHeaderValue.append(extensionParameter.getKey()); if (extensionParameter.getValue() != null) { newHeaderValue.append(PARAMETER_EQUAL); diff --git a/codec-stomp/src/main/java/io/netty/handler/codec/stomp/StompSubframeDecoder.java b/codec-stomp/src/main/java/io/netty/handler/codec/stomp/StompSubframeDecoder.java index 0172f7921e..e25c15447a 100644 --- a/codec-stomp/src/main/java/io/netty/handler/codec/stomp/StompSubframeDecoder.java +++ b/codec-stomp/src/main/java/io/netty/handler/codec/stomp/StompSubframeDecoder.java @@ -24,7 +24,6 @@ import io.netty.handler.codec.ReplayingDecoder; import io.netty.handler.codec.TooLongFrameException; import io.netty.handler.codec.stomp.StompSubframeDecoder.State; import io.netty.util.internal.AppendableCharSequence; -import io.netty.util.internal.StringUtil; import java.util.List; import java.util.Locale; @@ -212,7 +211,7 @@ public class StompSubframeDecoder extends ReplayingDecoder { for (;;) { String line = readLine(buffer, maxLineLength); if (!line.isEmpty()) { - String[] split = StringUtil.split(line, ':'); + String[] split = line.split(":"); if (split.length == 2) { headers.add(split[0], split[1]); } diff --git a/common/src/main/java/io/netty/util/internal/StringUtil.java b/common/src/main/java/io/netty/util/internal/StringUtil.java index 2efa28e9d2..d03387f019 100644 --- a/common/src/main/java/io/netty/util/internal/StringUtil.java +++ b/common/src/main/java/io/netty/util/internal/StringUtil.java @@ -68,91 +68,6 @@ public final class StringUtil { // Unused. } - /** - * Splits the specified {@link String} with the specified delimiter. This operation is a simplified and optimized - * version of {@link String#split(String)}. - */ - public static String[] split(String value, char delim) { - final int end = value.length(); - final List res = InternalThreadLocalMap.get().arrayList(); - - int start = 0; - for (int i = 0; i < end; i ++) { - if (value.charAt(i) == delim) { - if (start == i) { - res.add(EMPTY_STRING); - } else { - res.add(value.substring(start, i)); - } - start = i + 1; - } - } - - if (start == 0) { // If no delimiter was found in the value - res.add(value); - } else { - if (start != end) { - // Add the last element if it's not empty. - res.add(value.substring(start, end)); - } else { - // Truncate trailing empty elements. - for (int i = res.size() - 1; i >= 0; i --) { - if (res.get(i).isEmpty()) { - res.remove(i); - } else { - break; - } - } - } - } - - return res.toArray(new String[res.size()]); - } - - /** - * Splits the specified {@link String} with the specified delimiter in maxParts maximum parts. - * This operation is a simplified and optimized - * version of {@link String#split(String, int)}. - */ - public static String[] split(String value, char delim, int maxParts) { - final int end = value.length(); - final List res = InternalThreadLocalMap.get().arrayList(); - - int start = 0; - int cpt = 1; - for (int i = 0; i < end && cpt < maxParts; i ++) { - if (value.charAt(i) == delim) { - if (start == i) { - res.add(EMPTY_STRING); - } else { - res.add(value.substring(start, i)); - } - start = i + 1; - cpt++; - } - } - - if (start == 0) { // If no delimiter was found in the value - res.add(value); - } else { - if (start != end) { - // Add the last element if it's not empty. - res.add(value.substring(start, end)); - } else { - // Truncate trailing empty elements. - for (int i = res.size() - 1; i >= 0; i --) { - if (res.get(i).isEmpty()) { - res.remove(i); - } else { - break; - } - } - } - } - - return res.toArray(new String[res.size()]); - } - /** * Get the item after one char delim if the delim is found (else null). * This operation is a simplified and optimized diff --git a/common/src/test/java/io/netty/util/internal/StringUtilTest.java b/common/src/test/java/io/netty/util/internal/StringUtilTest.java index 7075153e6f..13016259e0 100644 --- a/common/src/test/java/io/netty/util/internal/StringUtilTest.java +++ b/common/src/test/java/io/netty/util/internal/StringUtilTest.java @@ -15,9 +15,10 @@ */ package io.netty.util.internal; -import java.util.Arrays; import org.junit.Test; +import java.util.Arrays; + import static io.netty.util.internal.StringUtil.*; import static org.hamcrest.CoreMatchers.*; import static org.junit.Assert.*; @@ -49,33 +50,48 @@ public class StringUtilTest { @Test public void splitSimple() { - assertArrayEquals(new String[] { "foo", "bar" }, split("foo:bar", ':')); + assertArrayEquals(new String[] { "foo", "bar" }, "foo:bar".split(":")); } @Test public void splitWithTrailingDelimiter() { - assertArrayEquals(new String[] { "foo", "bar" }, split("foo,bar,", ',')); + assertArrayEquals(new String[] { "foo", "bar" }, "foo,bar,".split(",")); } @Test public void splitWithTrailingDelimiters() { - assertArrayEquals(new String[] { "foo", "bar" }, split("foo!bar!!", '!')); + assertArrayEquals(new String[] { "foo", "bar" }, "foo!bar!!".split("!")); + } + + @Test + public void splitWithTrailingDelimitersDot() { + assertArrayEquals(new String[] { "foo", "bar" }, "foo.bar..".split("\\.")); + } + + @Test + public void splitWithTrailingDelimitersEq() { + assertArrayEquals(new String[] { "foo", "bar" }, "foo=bar==".split("=")); + } + + @Test + public void splitWithTrailingDelimitersSpace() { + assertArrayEquals(new String[] { "foo", "bar" }, "foo bar ".split(" ")); } @Test public void splitWithConsecutiveDelimiters() { - assertArrayEquals(new String[] { "foo", "", "bar" }, split("foo$$bar", '$')); + assertArrayEquals(new String[] { "foo", "", "bar" }, "foo$$bar".split("\\$")); } @Test public void splitWithDelimiterAtBeginning() { - assertArrayEquals(new String[] { "", "foo", "bar" }, split("#foo#bar", '#')); + assertArrayEquals(new String[] { "", "foo", "bar" }, "#foo#bar".split("#")); } @Test public void splitMaxPart() { - assertArrayEquals(new String[] { "foo", "bar:bar2" }, split("foo:bar:bar2", ':', 2)); - assertArrayEquals(new String[] { "foo", "bar", "bar2" }, split("foo:bar:bar2", ':', 3)); + assertArrayEquals(new String[] { "foo", "bar:bar2" }, "foo:bar:bar2".split(":", 2)); + assertArrayEquals(new String[] { "foo", "bar", "bar2" }, "foo:bar:bar2".split(":", 3)); } @Test diff --git a/handler-proxy/src/test/java/io/netty/handler/proxy/HttpProxyServer.java b/handler-proxy/src/test/java/io/netty/handler/proxy/HttpProxyServer.java index 1b1d55c32e..ee6426c503 100644 --- a/handler-proxy/src/test/java/io/netty/handler/proxy/HttpProxyServer.java +++ b/handler-proxy/src/test/java/io/netty/handler/proxy/HttpProxyServer.java @@ -29,13 +29,10 @@ import io.netty.handler.codec.http.FullHttpResponse; import io.netty.handler.codec.http.HttpHeaderNames; import io.netty.handler.codec.http.HttpMethod; import io.netty.handler.codec.http.HttpObjectAggregator; -import io.netty.handler.codec.http.HttpRequestDecoder; -import io.netty.handler.codec.http.HttpResponseEncoder; import io.netty.handler.codec.http.HttpResponseStatus; import io.netty.handler.codec.http.HttpServerCodec; import io.netty.handler.codec.http.HttpVersion; import io.netty.util.CharsetUtil; -import io.netty.util.internal.StringUtil; import java.net.InetSocketAddress; import java.net.SocketAddress; @@ -89,7 +86,7 @@ final class HttpProxyServer extends ProxyServer { if (username != null) { CharSequence authz = req.headers().get(HttpHeaderNames.PROXY_AUTHORIZATION); if (authz != null) { - String[] authzParts = StringUtil.split(authz.toString(), ' ', 2); + String[] authzParts = authz.toString().split(" ", 2); ByteBuf authzBuf64 = Unpooled.copiedBuffer(authzParts[1], CharsetUtil.US_ASCII); ByteBuf authzBuf = Base64.decode(authzBuf64); diff --git a/transport-native-epoll/src/test/java/io/netty/channel/epoll/EpollReuseAddrTest.java b/transport-native-epoll/src/test/java/io/netty/channel/epoll/EpollReuseAddrTest.java index f24df8d0c0..f3a825744c 100644 --- a/transport-native-epoll/src/test/java/io/netty/channel/epoll/EpollReuseAddrTest.java +++ b/transport-native-epoll/src/test/java/io/netty/channel/epoll/EpollReuseAddrTest.java @@ -27,7 +27,6 @@ import io.netty.testsuite.util.TestUtils; import io.netty.util.NetUtil; import io.netty.util.ReferenceCountUtil; import io.netty.util.ResourceLeakDetector; -import io.netty.util.internal.StringUtil; import org.junit.Assert; import org.junit.Assume; import org.junit.Ignore; @@ -53,7 +52,7 @@ public class EpollReuseAddrTest { if (index > -1) { kernelVersion = kernelVersion.substring(0, index); } - String[] versionParts = StringUtil.split(kernelVersion, '.'); + String[] versionParts = kernelVersion.split("\\."); if (versionParts.length <= 3) { MAJOR = Integer.parseInt(versionParts[0]); MINOR = Integer.parseInt(versionParts[1]);