summaryrefslogtreecommitdiffstatsabout
diff options
context:
space:
mode:
authorMikhail Mazursky2013-11-02 04:44:36 (EDT)
committer Mikhail Mazursky2013-11-02 04:44:36 (EDT)
commit6b0269a16d7ee923ae70082eb60595d432861707 (patch)
treefebef6ee712c505c99f95a8a059bf4d7eb64c688
parent56fcfa45fb642825db38b8197467a63ee2aeffd6 (diff)
downloadorg.eclipse.jetty.project-6b0269a16d7ee923ae70082eb60595d432861707.zip
org.eclipse.jetty.project-6b0269a16d7ee923ae70082eb60595d432861707.tar.gz
org.eclipse.jetty.project-6b0269a16d7ee923ae70082eb60595d432861707.tar.bz2
[Bug 420930] Use Charset to specify character encodingrefs/changes/96/17996/1
Signed-off-by: Mikhail Mazursky <mikhail.mazursky@gmail.com>
-rw-r--r--jetty-client/src/main/java/org/eclipse/jetty/client/HttpContentResponse.java16
-rw-r--r--jetty-client/src/main/java/org/eclipse/jetty/client/util/BasicAuthentication.java4
-rw-r--r--jetty-client/src/main/java/org/eclipse/jetty/client/util/BufferingResponseListener.java14
-rw-r--r--jetty-client/src/main/java/org/eclipse/jetty/client/util/DigestAuthentication.java8
-rw-r--r--jetty-client/src/main/java/org/eclipse/jetty/client/util/StringContentProvider.java3
-rw-r--r--jetty-client/src/test/java/org/eclipse/jetty/client/GZIPContentDecoderTest.java45
-rw-r--r--jetty-client/src/test/java/org/eclipse/jetty/client/HttpClientContinueTest.java5
-rw-r--r--jetty-client/src/test/java/org/eclipse/jetty/client/HttpClientProxyTest.java3
-rw-r--r--jetty-client/src/test/java/org/eclipse/jetty/client/HttpClientTest.java17
-rw-r--r--jetty-client/src/test/java/org/eclipse/jetty/client/HttpReceiverTest.java3
-rw-r--r--jetty-client/src/test/java/org/eclipse/jetty/client/HttpSenderTest.java7
-rw-r--r--jetty-client/src/test/java/org/eclipse/jetty/client/api/Usage.java3
-rw-r--r--jetty-client/src/test/java/org/eclipse/jetty/client/ssl/SslBytesClientTest.java21
-rw-r--r--jetty-client/src/test/java/org/eclipse/jetty/client/ssl/SslBytesServerTest.java77
-rw-r--r--jetty-http/src/main/java/org/eclipse/jetty/http/HttpField.java5
-rw-r--r--jetty-http/src/main/java/org/eclipse/jetty/http/HttpParser.java5
-rw-r--r--jetty-http/src/main/java/org/eclipse/jetty/http/HttpTester.java3
-rw-r--r--jetty-http/src/main/java/org/eclipse/jetty/http/HttpURI.java37
-rw-r--r--jetty-http/src/test/java/org/eclipse/jetty/http/HttpParserTest.java11
-rw-r--r--jetty-io/src/main/java/org/eclipse/jetty/io/ByteArrayEndPoint.java7
-rw-r--r--jetty-io/src/main/java/org/eclipse/jetty/io/WriterOutputStream.java5
-rw-r--r--jetty-io/src/test/java/org/eclipse/jetty/io/IOTest.java3
-rw-r--r--jetty-io/src/test/java/org/eclipse/jetty/io/SelectChannelEndPointSslTest.java3
-rw-r--r--jetty-io/src/test/java/org/eclipse/jetty/io/SelectChannelEndPointTest.java27
-rw-r--r--jetty-io/src/test/java/org/eclipse/jetty/io/SslConnectionTest.java13
-rw-r--r--jetty-jaspi/src/main/java/org/eclipse/jetty/security/jaspi/modules/BaseAuthModule.java3
-rw-r--r--jetty-jaspi/src/main/java/org/eclipse/jetty/security/jaspi/modules/DigestAuthModule.java23
-rw-r--r--jetty-proxy/src/test/java/org/eclipse/jetty/proxy/ConnectHandlerSSLTest.java9
-rw-r--r--jetty-proxy/src/test/java/org/eclipse/jetty/proxy/ConnectHandlerTest.java67
-rw-r--r--jetty-rewrite/src/test/java/org/eclipse/jetty/rewrite/handler/RewriteRegexRuleTest.java3
-rw-r--r--jetty-security/src/main/java/org/eclipse/jetty/security/authentication/BasicAuthenticator.java3
-rw-r--r--jetty-security/src/main/java/org/eclipse/jetty/security/authentication/DigestAuthenticator.java23
-rw-r--r--jetty-security/src/test/java/org/eclipse/jetty/security/ConstraintTest.java23
-rw-r--r--jetty-server/src/main/java/org/eclipse/jetty/server/HttpChannel.java3
-rw-r--r--jetty-server/src/main/java/org/eclipse/jetty/server/LocalConnector.java9
-rw-r--r--jetty-server/src/main/java/org/eclipse/jetty/server/Request.java24
-rw-r--r--jetty-server/src/main/java/org/eclipse/jetty/server/ShutdownMonitor.java5
-rw-r--r--jetty-server/src/test/java/org/eclipse/jetty/server/AbstractHttpTest.java3
-rw-r--r--jetty-server/src/test/java/org/eclipse/jetty/server/AsyncRequestReadTest.java13
-rw-r--r--jetty-server/src/test/java/org/eclipse/jetty/server/AsyncStressTest.java5
-rw-r--r--jetty-server/src/test/java/org/eclipse/jetty/server/ConnectionOpenCloseTest.java5
-rw-r--r--jetty-server/src/test/java/org/eclipse/jetty/server/DumpHandler.java3
-rw-r--r--jetty-server/src/test/java/org/eclipse/jetty/server/GracefulStopTest.java3
-rw-r--r--jetty-server/src/test/java/org/eclipse/jetty/server/HostHeaderCustomizerTest.java5
-rw-r--r--jetty-server/src/test/java/org/eclipse/jetty/server/HttpServerTestBase.java11
-rw-r--r--jetty-server/src/test/java/org/eclipse/jetty/server/HttpURITest.java13
-rw-r--r--jetty-server/src/test/java/org/eclipse/jetty/server/HttpWriterTest.java27
-rw-r--r--jetty-server/src/test/java/org/eclipse/jetty/server/LowResourcesMonitorTest.java7
-rw-r--r--jetty-server/src/test/java/org/eclipse/jetty/server/NetworkTrafficListenerTest.java47
-rw-r--r--jetty-server/src/test/java/org/eclipse/jetty/server/RequestTest.java7
-rw-r--r--jetty-server/src/test/java/org/eclipse/jetty/server/SelectChannelAsyncContextTest.java3
-rw-r--r--jetty-server/src/test/java/org/eclipse/jetty/server/SelectChannelTimeoutTest.java3
-rw-r--r--jetty-server/src/test/java/org/eclipse/jetty/server/SlowClientWithPipelinedRequestTest.java5
-rw-r--r--jetty-server/src/test/java/org/eclipse/jetty/server/handler/IPAccessHandlerTest.java3
-rw-r--r--jetty-server/src/test/java/org/eclipse/jetty/server/ssl/SSLCloseTest.java3
-rw-r--r--jetty-servlet/src/test/java/org/eclipse/jetty/servlet/AsyncContextListenersTest.java19
-rw-r--r--jetty-servlet/src/test/java/org/eclipse/jetty/servlet/AsyncServletLongPollTest.java11
-rw-r--r--jetty-servlet/src/test/java/org/eclipse/jetty/servlet/AsyncServletTest.java3
-rw-r--r--jetty-servlet/src/test/java/org/eclipse/jetty/servlet/DefaultServletRangesTest.java3
-rw-r--r--jetty-servlet/src/test/java/org/eclipse/jetty/servlet/DefaultServletTest.java3
-rw-r--r--jetty-servlet/src/test/java/org/eclipse/jetty/servlet/RequestHeadersTest.java3
-rw-r--r--jetty-servlets/src/main/java/org/eclipse/jetty/servlets/EventSourceServlet.java31
-rw-r--r--jetty-servlets/src/main/java/org/eclipse/jetty/servlets/MultiPartFilter.java25
-rw-r--r--jetty-servlets/src/test/java/org/eclipse/jetty/servlets/AbstractDoSFilterTest.java9
-rw-r--r--jetty-servlets/src/test/java/org/eclipse/jetty/servlets/EventSourceServletTest.java5
-rw-r--r--jetty-servlets/src/test/java/org/eclipse/jetty/servlets/MultipartFilterTest.java3
-rw-r--r--jetty-spdy/spdy-core/src/main/java/org/eclipse/jetty/spdy/api/DataInfo.java13
-rw-r--r--jetty-spdy/spdy-core/src/main/java/org/eclipse/jetty/spdy/api/StringDataInfo.java6
-rw-r--r--jetty-spdy/spdy-core/src/main/java/org/eclipse/jetty/spdy/generator/HeadersBlockGenerator.java9
-rw-r--r--jetty-spdy/spdy-core/src/main/java/org/eclipse/jetty/spdy/parser/HeadersBlockParser.java8
-rw-r--r--jetty-spdy/spdy-core/src/test/java/org/eclipse/jetty/spdy/api/ClientUsageTest.java7
-rw-r--r--jetty-spdy/spdy-core/src/test/java/org/eclipse/jetty/spdy/parser/ParseVersusCacheBenchmarkTest.java12
-rw-r--r--jetty-spdy/spdy-http-server/src/test/java/org/eclipse/jetty/spdy/server/http/ProtocolNegotiationTest.java13
-rw-r--r--jetty-spdy/spdy-http-server/src/test/java/org/eclipse/jetty/spdy/server/http/ServerHTTPSPDYTest.java31
-rw-r--r--jetty-spdy/spdy-http-server/src/test/java/org/eclipse/jetty/spdy/server/proxy/ProxyHTTPToSPDYTest.java7
-rw-r--r--jetty-spdy/spdy-http-server/src/test/java/org/eclipse/jetty/spdy/server/proxy/ProxySPDYToHTTPTest.java3
-rw-r--r--jetty-spdy/spdy-http-server/src/test/java/org/eclipse/jetty/spdy/server/proxy/ProxySPDYToSPDYTest.java7
-rw-r--r--jetty-spdy/spdy-server/src/test/java/org/eclipse/jetty/spdy/server/SynReplyTest.java13
-rw-r--r--jetty-spring/src/main/java/org/eclipse/jetty/spring/SpringConfigurationProcessor.java3
-rw-r--r--jetty-util/src/main/java/org/eclipse/jetty/util/AbstractTrie.java3
-rw-r--r--jetty-util/src/main/java/org/eclipse/jetty/util/B64Code.java36
-rw-r--r--jetty-util/src/main/java/org/eclipse/jetty/util/BufferUtil.java9
-rw-r--r--jetty-util/src/main/java/org/eclipse/jetty/util/ByteArrayISO8859Writer.java3
-rw-r--r--jetty-util/src/main/java/org/eclipse/jetty/util/IO.java15
-rw-r--r--jetty-util/src/main/java/org/eclipse/jetty/util/MultiPartInputStreamParser.java3
-rw-r--r--jetty-util/src/main/java/org/eclipse/jetty/util/MultiPartOutputStream.java11
-rw-r--r--jetty-util/src/main/java/org/eclipse/jetty/util/ReadLineInputStream.java7
-rw-r--r--jetty-util/src/main/java/org/eclipse/jetty/util/StringUtil.java40
-rw-r--r--jetty-util/src/main/java/org/eclipse/jetty/util/TreeTrie.java3
-rw-r--r--jetty-util/src/main/java/org/eclipse/jetty/util/URIUtil.java11
-rw-r--r--jetty-util/src/main/java/org/eclipse/jetty/util/UrlEncoded.java23
-rw-r--r--jetty-util/src/main/java/org/eclipse/jetty/util/security/Credential.java5
-rw-r--r--jetty-util/src/test/java/org/eclipse/jetty/util/B64CodeTest.java12
-rw-r--r--jetty-util/src/test/java/org/eclipse/jetty/util/ReadLineInputStreamTest.java9
-rw-r--r--jetty-util/src/test/java/org/eclipse/jetty/util/StringUtilTest.java6
-rw-r--r--jetty-util/src/test/java/org/eclipse/jetty/util/URITest.java3
-rw-r--r--jetty-util/src/test/java/org/eclipse/jetty/util/URLEncodedTest.java47
-rw-r--r--jetty-util/src/test/java/org/eclipse/jetty/util/Utf8LineParserTest.java2
-rw-r--r--jetty-util/src/test/java/org/eclipse/jetty/util/Utf8StringBufferTest.java11
-rw-r--r--jetty-util/src/test/java/org/eclipse/jetty/util/Utf8StringBuilderTest.java12
-rw-r--r--jetty-util/src/test/java/org/eclipse/jetty/util/log/StdErrLogTest.java3
-rw-r--r--jetty-util/src/test/java/org/eclipse/jetty/util/resource/FileResourceTest.java3
-rw-r--r--jetty-websocket/websocket-api/src/main/java/org/eclipse/jetty/websocket/api/io/WebSocketWriter.java2
-rw-r--r--jetty-websocket/websocket-client/src/main/java/org/eclipse/jetty/websocket/client/ClientUpgradeRequest.java3
-rw-r--r--jetty-websocket/websocket-client/src/main/java/org/eclipse/jetty/websocket/client/io/UpgradeConnection.java3
-rw-r--r--jetty-websocket/websocket-client/src/test/java/org/eclipse/jetty/websocket/client/examples/TestClient.java3
-rw-r--r--jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/AcceptHash.java17
-rw-r--r--jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/WebSocketFrame.java3
-rw-r--r--jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/WebSocketSession.java3
-rw-r--r--jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/extensions/mux/op/MuxAddChannelRequest.java3
-rw-r--r--jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/extensions/mux/op/MuxAddChannelResponse.java3
-rw-r--r--jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/ClosePayloadParserTest.java3
-rw-r--r--jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/TextPayloadParserTest.java13
-rw-r--r--jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/ab/TestABCase7_3.java5
-rw-r--r--jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/extensions/FragmentExtensionTest.java7
-rw-r--r--jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/extensions/IdentityExtensionTest.java5
-rw-r--r--jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/extensions/compress/DeflateCompressionMethodTest.java3
-rw-r--r--jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/extensions/compress/FrameCompressionExtensionTest.java3
-rw-r--r--jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/extensions/compress/MessageCompressionExtensionTest.java11
-rw-r--r--jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/extensions/mux/MuxParserRFCTest.java3
-rw-r--r--jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/io/http/HttpResponseHeaderParserTest.java7
-rw-r--r--jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/blockhead/BlockheadClient.java3
-rw-r--r--jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/helper/SafariD00.java5
-rw-r--r--tests/test-continuation/src/test/java/org/eclipse/jetty/continuation/ContinuationBase.java3
-rw-r--r--tests/test-integration/src/test/java/org/eclipse/jetty/test/DigestPostTest.java11
125 files changed, 772 insertions, 580 deletions
diff --git a/jetty-client/src/main/java/org/eclipse/jetty/client/HttpContentResponse.java b/jetty-client/src/main/java/org/eclipse/jetty/client/HttpContentResponse.java
index c3b50fd..fe54f85 100644
--- a/jetty-client/src/main/java/org/eclipse/jetty/client/HttpContentResponse.java
+++ b/jetty-client/src/main/java/org/eclipse/jetty/client/HttpContentResponse.java
@@ -19,6 +19,7 @@
package org.eclipse.jetty.client;
import java.io.UnsupportedEncodingException;
+import java.nio.charset.StandardCharsets;
import java.nio.charset.UnsupportedCharsetException;
import java.util.List;
@@ -92,13 +93,20 @@ public class HttpContentResponse implements ContentResponse
public String getContentAsString()
{
String encoding = this.encoding;
- try
+ if (encoding == null)
{
- return new String(getContent(), encoding == null ? "UTF-8" : encoding);
+ return new String(getContent(), StandardCharsets.UTF_8);
}
- catch (UnsupportedEncodingException e)
+ else
{
- throw new UnsupportedCharsetException(encoding);
+ try
+ {
+ return new String(getContent(), encoding);
+ }
+ catch (UnsupportedEncodingException e)
+ {
+ throw new UnsupportedCharsetException(encoding);
+ }
}
}
diff --git a/jetty-client/src/main/java/org/eclipse/jetty/client/util/BasicAuthentication.java b/jetty-client/src/main/java/org/eclipse/jetty/client/util/BasicAuthentication.java
index 7bf9fc2..d50d6d9 100644
--- a/jetty-client/src/main/java/org/eclipse/jetty/client/util/BasicAuthentication.java
+++ b/jetty-client/src/main/java/org/eclipse/jetty/client/util/BasicAuthentication.java
@@ -19,6 +19,7 @@
package org.eclipse.jetty.client.util;
import java.net.URI;
+import java.nio.charset.StandardCharsets;
import org.eclipse.jetty.client.HttpClient;
import org.eclipse.jetty.client.api.Authentication;
@@ -73,8 +74,7 @@ public class BasicAuthentication implements Authentication
@Override
public Result authenticate(Request request, ContentResponse response, HeaderInfo headerInfo, Attributes context)
{
- String encoding = StringUtil.__ISO_8859_1;
- String value = "Basic " + B64Code.encode(user + ":" + password, encoding);
+ String value = "Basic " + B64Code.encode(user + ":" + password, StandardCharsets.ISO_8859_1);
return new BasicResult(headerInfo.getHeader(), uri, value);
}
diff --git a/jetty-client/src/main/java/org/eclipse/jetty/client/util/BufferingResponseListener.java b/jetty-client/src/main/java/org/eclipse/jetty/client/util/BufferingResponseListener.java
index 6a7969d..50ddbd1 100644
--- a/jetty-client/src/main/java/org/eclipse/jetty/client/util/BufferingResponseListener.java
+++ b/jetty-client/src/main/java/org/eclipse/jetty/client/util/BufferingResponseListener.java
@@ -20,6 +20,8 @@ package org.eclipse.jetty.client.util;
import java.io.UnsupportedEncodingException;
import java.nio.ByteBuffer;
+import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
import java.nio.charset.UnsupportedCharsetException;
import java.util.Locale;
@@ -130,7 +132,7 @@ public abstract class BufferingResponseListener extends Response.Listener.Empty
{
String encoding = this.encoding;
if (encoding == null)
- encoding = "UTF-8";
+ return getContentAsString(StandardCharsets.UTF_8);
return getContentAsString(encoding);
}
@@ -150,4 +152,14 @@ public abstract class BufferingResponseListener extends Response.Listener.Empty
throw new UnsupportedCharsetException(encoding);
}
}
+
+ /**
+ * @param encoding the encoding of the content bytes
+ * @return the content as a string, with the specified encoding
+ * @see #getContentAsString()
+ */
+ public String getContentAsString(Charset encoding)
+ {
+ return new String(getContent(), encoding);
+ }
}
diff --git a/jetty-client/src/main/java/org/eclipse/jetty/client/util/DigestAuthentication.java b/jetty-client/src/main/java/org/eclipse/jetty/client/util/DigestAuthentication.java
index 55ac0ec..d80db07 100644
--- a/jetty-client/src/main/java/org/eclipse/jetty/client/util/DigestAuthentication.java
+++ b/jetty-client/src/main/java/org/eclipse/jetty/client/util/DigestAuthentication.java
@@ -20,6 +20,7 @@ package org.eclipse.jetty.client.util;
import java.net.URI;
import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
@@ -217,14 +218,13 @@ public class DigestAuthentication implements Authentication
if (digester == null)
return;
- Charset charset = Charset.forName("ISO-8859-1");
String A1 = user + ":" + realm + ":" + password;
- String hashA1 = toHexString(digester.digest(A1.getBytes(charset)));
+ String hashA1 = toHexString(digester.digest(A1.getBytes(StandardCharsets.ISO_8859_1)));
String A2 = request.method() + ":" + request.getURI();
if ("auth-int".equals(qop))
A2 += ":" + toHexString(digester.digest(content));
- String hashA2 = toHexString(digester.digest(A2.getBytes(charset)));
+ String hashA2 = toHexString(digester.digest(A2.getBytes(StandardCharsets.ISO_8859_1)));
String nonceCount;
String clientNonce;
@@ -241,7 +241,7 @@ public class DigestAuthentication implements Authentication
clientNonce = null;
A3 = hashA1 + ":" + nonce + ":" + hashA2;
}
- String hashA3 = toHexString(digester.digest(A3.getBytes(charset)));
+ String hashA3 = toHexString(digester.digest(A3.getBytes(StandardCharsets.ISO_8859_1)));
StringBuilder value = new StringBuilder("Digest");
value.append(" username=\"").append(user).append("\"");
diff --git a/jetty-client/src/main/java/org/eclipse/jetty/client/util/StringContentProvider.java b/jetty-client/src/main/java/org/eclipse/jetty/client/util/StringContentProvider.java
index 95036b7..49fa442 100644
--- a/jetty-client/src/main/java/org/eclipse/jetty/client/util/StringContentProvider.java
+++ b/jetty-client/src/main/java/org/eclipse/jetty/client/util/StringContentProvider.java
@@ -19,6 +19,7 @@
package org.eclipse.jetty.client.util;
import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
import org.eclipse.jetty.client.api.ContentProvider;
@@ -32,7 +33,7 @@ public class StringContentProvider extends BytesContentProvider
{
public StringContentProvider(String content)
{
- this(content, "UTF-8");
+ this(content, StandardCharsets.UTF_8);
}
public StringContentProvider(String content, String encoding)
diff --git a/jetty-client/src/test/java/org/eclipse/jetty/client/GZIPContentDecoderTest.java b/jetty-client/src/test/java/org/eclipse/jetty/client/GZIPContentDecoderTest.java
index 436d684..8c0a44d 100644
--- a/jetty-client/src/test/java/org/eclipse/jetty/client/GZIPContentDecoderTest.java
+++ b/jetty-client/src/test/java/org/eclipse/jetty/client/GZIPContentDecoderTest.java
@@ -26,6 +26,7 @@ import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.nio.ByteBuffer;
import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream;
@@ -59,7 +60,7 @@ public class GZIPContentDecoderTest
data += data;
ByteArrayOutputStream baos = new ByteArrayOutputStream();
GZIPOutputStream output = new GZIPOutputStream(baos);
- output.write(data.getBytes("UTF-8"));
+ output.write(data.getBytes(StandardCharsets.UTF_8));
output.close();
byte[] bytes = baos.toByteArray();
@@ -68,7 +69,7 @@ public class GZIPContentDecoderTest
int read;
while ((read = input.read()) >= 0)
baos.write(read);
- assertEquals(data, new String(baos.toByteArray(), "UTF-8"));
+ assertEquals(data, new String(baos.toByteArray(), StandardCharsets.UTF_8));
}
@Test
@@ -91,13 +92,13 @@ public class GZIPContentDecoderTest
ByteArrayOutputStream baos = new ByteArrayOutputStream();
GZIPOutputStream output = new GZIPOutputStream(baos);
- output.write(data.getBytes("UTF-8"));
+ output.write(data.getBytes(StandardCharsets.UTF_8));
output.close();
byte[] bytes = baos.toByteArray();
GZIPContentDecoder decoder = new GZIPContentDecoder();
ByteBuffer decoded = decoder.decode(ByteBuffer.wrap(bytes));
- assertEquals(data, Charset.forName("UTF-8").decode(decoded).toString());
+ assertEquals(data, StandardCharsets.UTF_8.decode(decoded).toString());
}
@Test
@@ -107,7 +108,7 @@ public class GZIPContentDecoderTest
ByteArrayOutputStream baos = new ByteArrayOutputStream();
GZIPOutputStream output = new GZIPOutputStream(baos);
- output.write(data.getBytes("UTF-8"));
+ output.write(data.getBytes(StandardCharsets.UTF_8));
output.close();
byte[] bytes = baos.toByteArray();
@@ -121,7 +122,7 @@ public class GZIPContentDecoderTest
ByteBuffer decoded = decoder.decode(ByteBuffer.wrap(bytes1));
assertEquals(0, decoded.capacity());
decoded = decoder.decode(ByteBuffer.wrap(bytes2));
- assertEquals(data, Charset.forName("UTF-8").decode(decoded).toString());
+ assertEquals(data, StandardCharsets.UTF_8.decode(decoded).toString());
}
@Test
@@ -131,7 +132,7 @@ public class GZIPContentDecoderTest
ByteArrayOutputStream baos = new ByteArrayOutputStream();
GZIPOutputStream output = new GZIPOutputStream(baos);
- output.write(data.getBytes("UTF-8"));
+ output.write(data.getBytes(StandardCharsets.UTF_8));
output.close();
byte[] bytes = baos.toByteArray();
@@ -143,7 +144,7 @@ public class GZIPContentDecoderTest
GZIPContentDecoder decoder = new GZIPContentDecoder();
ByteBuffer decoded = decoder.decode(ByteBuffer.wrap(bytes1));
- assertEquals(data, Charset.forName("UTF-8").decode(decoded).toString());
+ assertEquals(data, StandardCharsets.UTF_8.decode(decoded).toString());
assertFalse(decoder.isFinished());
decoded = decoder.decode(ByteBuffer.wrap(bytes2));
assertEquals(0, decoded.remaining());
@@ -157,7 +158,7 @@ public class GZIPContentDecoderTest
ByteArrayOutputStream baos = new ByteArrayOutputStream();
GZIPOutputStream output = new GZIPOutputStream(baos);
- output.write(data.getBytes("UTF-8"));
+ output.write(data.getBytes(StandardCharsets.UTF_8));
output.close();
byte[] bytes = baos.toByteArray();
@@ -171,7 +172,7 @@ public class GZIPContentDecoderTest
ByteBuffer decoded = decoder.decode(ByteBuffer.wrap(bytes1));
assertEquals(0, decoded.capacity());
decoded = decoder.decode(ByteBuffer.wrap(bytes2));
- assertEquals(data, Charset.forName("UTF-8").decode(decoded).toString());
+ assertEquals(data, StandardCharsets.UTF_8.decode(decoded).toString());
}
@Test
@@ -180,14 +181,14 @@ public class GZIPContentDecoderTest
String data1 = "0";
ByteArrayOutputStream baos = new ByteArrayOutputStream();
GZIPOutputStream output = new GZIPOutputStream(baos);
- output.write(data1.getBytes("UTF-8"));
+ output.write(data1.getBytes(StandardCharsets.UTF_8));
output.close();
byte[] bytes1 = baos.toByteArray();
String data2 = "1";
baos = new ByteArrayOutputStream();
output = new GZIPOutputStream(baos);
- output.write(data2.getBytes("UTF-8"));
+ output.write(data2.getBytes(StandardCharsets.UTF_8));
output.close();
byte[] bytes2 = baos.toByteArray();
@@ -198,11 +199,11 @@ public class GZIPContentDecoderTest
GZIPContentDecoder decoder = new GZIPContentDecoder();
ByteBuffer buffer = ByteBuffer.wrap(bytes);
ByteBuffer decoded = decoder.decode(buffer);
- assertEquals(data1, Charset.forName("UTF-8").decode(decoded).toString());
+ assertEquals(data1, StandardCharsets.UTF_8.decode(decoded).toString());
assertTrue(decoder.isFinished());
assertTrue(buffer.hasRemaining());
decoded = decoder.decode(buffer);
- assertEquals(data2, Charset.forName("UTF-8").decode(decoded).toString());
+ assertEquals(data2, StandardCharsets.UTF_8.decode(decoded).toString());
assertTrue(decoder.isFinished());
assertFalse(buffer.hasRemaining());
}
@@ -215,7 +216,7 @@ public class GZIPContentDecoderTest
data += data;
ByteArrayOutputStream baos = new ByteArrayOutputStream();
GZIPOutputStream output = new GZIPOutputStream(baos);
- output.write(data.getBytes("UTF-8"));
+ output.write(data.getBytes(StandardCharsets.UTF_8));
output.close();
byte[] bytes = baos.toByteArray();
@@ -225,7 +226,7 @@ public class GZIPContentDecoderTest
while (buffer.hasRemaining())
{
ByteBuffer decoded = decoder.decode(buffer);
- result += Charset.forName("UTF-8").decode(decoded).toString();
+ result += StandardCharsets.UTF_8.decode(decoded).toString();
}
assertEquals(data, result);
}
@@ -238,7 +239,7 @@ public class GZIPContentDecoderTest
data += data;
ByteArrayOutputStream baos = new ByteArrayOutputStream();
GZIPOutputStream output = new GZIPOutputStream(baos);
- output.write(data.getBytes("UTF-8"));
+ output.write(data.getBytes(StandardCharsets.UTF_8));
output.close();
byte[] bytes = baos.toByteArray();
@@ -249,7 +250,7 @@ public class GZIPContentDecoderTest
{
ByteBuffer decoded = decoder.decode(ByteBuffer.wrap(new byte[]{buffer.get()}));
if (decoded.hasRemaining())
- result += Charset.forName("UTF-8").decode(decoded).toString();
+ result += StandardCharsets.UTF_8.decode(decoded).toString();
}
assertEquals(data, result);
assertTrue(decoder.isFinished());
@@ -263,12 +264,12 @@ public class GZIPContentDecoderTest
data1 += data1;
ByteArrayOutputStream baos = new ByteArrayOutputStream();
GZIPOutputStream output = new GZIPOutputStream(baos);
- output.write(data1.getBytes("UTF-8"));
+ output.write(data1.getBytes(StandardCharsets.UTF_8));
output.close();
byte[] bytes1 = baos.toByteArray();
String data2 = "HELLO";
- byte[] bytes2 = data2.getBytes("UTF-8");
+ byte[] bytes2 = data2.getBytes(StandardCharsets.UTF_8);
byte[] bytes = new byte[bytes1.length + bytes2.length];
System.arraycopy(bytes1, 0, bytes, 0, bytes1.length);
@@ -281,12 +282,12 @@ public class GZIPContentDecoderTest
{
ByteBuffer decoded = decoder.decode(buffer);
if (decoded.hasRemaining())
- result += Charset.forName("UTF-8").decode(decoded).toString();
+ result += StandardCharsets.UTF_8.decode(decoded).toString();
if (decoder.isFinished())
break;
}
assertEquals(data1, result);
assertTrue(buffer.hasRemaining());
- assertEquals(data2, Charset.forName("UTF-8").decode(buffer).toString());
+ assertEquals(data2, StandardCharsets.UTF_8.decode(buffer).toString());
}
}
diff --git a/jetty-client/src/test/java/org/eclipse/jetty/client/HttpClientContinueTest.java b/jetty-client/src/test/java/org/eclipse/jetty/client/HttpClientContinueTest.java
index e281ac4..50b7a9e 100644
--- a/jetty-client/src/test/java/org/eclipse/jetty/client/HttpClientContinueTest.java
+++ b/jetty-client/src/test/java/org/eclipse/jetty/client/HttpClientContinueTest.java
@@ -21,6 +21,7 @@ package org.eclipse.jetty.client;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
+import java.nio.charset.StandardCharsets;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.CountDownLatch;
@@ -60,13 +61,13 @@ public class HttpClientContinueTest extends AbstractHttpClientServerTest
@Test
public void test_Expect100Continue_WithOneContent_Respond100Continue() throws Exception
{
- test_Expect100Continue_Respond100Continue("data1".getBytes("UTF-8"));
+ test_Expect100Continue_Respond100Continue("data1".getBytes(StandardCharsets.UTF_8));
}
@Test
public void test_Expect100Continue_WithMultipleContents_Respond100Continue() throws Exception
{
- test_Expect100Continue_Respond100Continue("data1".getBytes("UTF-8"), "data2".getBytes("UTF-8"), "data3".getBytes("UTF-8"));
+ test_Expect100Continue_Respond100Continue("data1".getBytes(StandardCharsets.UTF_8), "data2".getBytes(StandardCharsets.UTF_8), "data3".getBytes(StandardCharsets.UTF_8));
}
private void test_Expect100Continue_Respond100Continue(byte[]... contents) throws Exception
diff --git a/jetty-client/src/test/java/org/eclipse/jetty/client/HttpClientProxyTest.java b/jetty-client/src/test/java/org/eclipse/jetty/client/HttpClientProxyTest.java
index cb5f7d9..c44acc5 100644
--- a/jetty-client/src/test/java/org/eclipse/jetty/client/HttpClientProxyTest.java
+++ b/jetty-client/src/test/java/org/eclipse/jetty/client/HttpClientProxyTest.java
@@ -20,6 +20,7 @@ package org.eclipse.jetty.client;
import java.io.IOException;
import java.net.URI;
+import java.nio.charset.StandardCharsets;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import javax.servlet.ServletException;
@@ -83,7 +84,7 @@ public class HttpClientProxyTest extends AbstractHttpClientServerTest
{
final String user = "foo";
final String password = "bar";
- final String credentials = B64Code.encode(user + ":" + password, "ISO-8859-1");
+ final String credentials = B64Code.encode(user + ":" + password, StandardCharsets.ISO_8859_1);
final String serverHost = "server";
final String realm = "test_realm";
final int status = HttpStatus.NO_CONTENT_204;
diff --git a/jetty-client/src/test/java/org/eclipse/jetty/client/HttpClientTest.java b/jetty-client/src/test/java/org/eclipse/jetty/client/HttpClientTest.java
index 9fc6a81..ce3a19f 100644
--- a/jetty-client/src/test/java/org/eclipse/jetty/client/HttpClientTest.java
+++ b/jetty-client/src/test/java/org/eclipse/jetty/client/HttpClientTest.java
@@ -25,6 +25,7 @@ import java.net.URI;
import java.net.URLEncoder;
import java.nio.ByteBuffer;
import java.nio.channels.UnresolvedAddressException;
+import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
@@ -171,10 +172,10 @@ public class HttpClientTest extends AbstractHttpClientServerTest
response.setCharacterEncoding("UTF-8");
ServletOutputStream output = response.getOutputStream();
String paramValue1 = request.getParameter(paramName1);
- output.write(paramValue1.getBytes("UTF-8"));
+ output.write(paramValue1.getBytes(StandardCharsets.UTF_8));
String paramValue2 = request.getParameter(paramName2);
Assert.assertEquals("", paramValue2);
- output.write("empty".getBytes("UTF-8"));
+ output.write("empty".getBytes(StandardCharsets.UTF_8));
baseRequest.setHandled(true);
}
});
@@ -186,7 +187,7 @@ public class HttpClientTest extends AbstractHttpClientServerTest
Assert.assertNotNull(response);
Assert.assertEquals(200, response.getStatus());
- String content = new String(response.getContent(), "UTF-8");
+ String content = new String(response.getContent(), StandardCharsets.UTF_8);
Assert.assertEquals(value1 + "empty", content);
}
@@ -204,9 +205,9 @@ public class HttpClientTest extends AbstractHttpClientServerTest
ServletOutputStream output = response.getOutputStream();
String[] paramValues1 = request.getParameterValues(paramName1);
for (String paramValue : paramValues1)
- output.write(paramValue.getBytes("UTF-8"));
+ output.write(paramValue.getBytes(StandardCharsets.UTF_8));
String paramValue2 = request.getParameter(paramName2);
- output.write(paramValue2.getBytes("UTF-8"));
+ output.write(paramValue2.getBytes(StandardCharsets.UTF_8));
baseRequest.setHandled(true);
}
});
@@ -222,7 +223,7 @@ public class HttpClientTest extends AbstractHttpClientServerTest
Assert.assertNotNull(response);
Assert.assertEquals(200, response.getStatus());
- String content = new String(response.getContent(), "UTF-8");
+ String content = new String(response.getContent(), StandardCharsets.UTF_8);
Assert.assertEquals(value11 + value12 + value2, content);
}
@@ -254,7 +255,7 @@ public class HttpClientTest extends AbstractHttpClientServerTest
Assert.assertNotNull(response);
Assert.assertEquals(200, response.getStatus());
- Assert.assertEquals(paramValue, new String(response.getContent(), "UTF-8"));
+ Assert.assertEquals(paramValue, new String(response.getContent(), StandardCharsets.UTF_8));
}
@Test
@@ -286,7 +287,7 @@ public class HttpClientTest extends AbstractHttpClientServerTest
Assert.assertNotNull(response);
Assert.assertEquals(200, response.getStatus());
- Assert.assertEquals(paramValue, new String(response.getContent(), "UTF-8"));
+ Assert.assertEquals(paramValue, new String(response.getContent(), StandardCharsets.UTF_8));
}
@Test
diff --git a/jetty-client/src/test/java/org/eclipse/jetty/client/HttpReceiverTest.java b/jetty-client/src/test/java/org/eclipse/jetty/client/HttpReceiverTest.java
index ad78b1e..e7a55a5 100644
--- a/jetty-client/src/test/java/org/eclipse/jetty/client/HttpReceiverTest.java
+++ b/jetty-client/src/test/java/org/eclipse/jetty/client/HttpReceiverTest.java
@@ -22,6 +22,7 @@ import java.io.ByteArrayOutputStream;
import java.io.EOFException;
import java.net.URI;
import java.nio.ByteBuffer;
+import java.nio.charset.StandardCharsets;
import java.util.Collections;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
@@ -126,7 +127,7 @@ public class HttpReceiverTest
Assert.assertNotNull(headers);
Assert.assertEquals(1, headers.size());
Assert.assertEquals(String.valueOf(content.length()), headers.get(HttpHeader.CONTENT_LENGTH));
- String received = listener.getContentAsString("UTF-8");
+ String received = listener.getContentAsString(StandardCharsets.UTF_8);
Assert.assertEquals(content, received);
}
diff --git a/jetty-client/src/test/java/org/eclipse/jetty/client/HttpSenderTest.java b/jetty-client/src/test/java/org/eclipse/jetty/client/HttpSenderTest.java
index e4cb6a0..f63b532 100644
--- a/jetty-client/src/test/java/org/eclipse/jetty/client/HttpSenderTest.java
+++ b/jetty-client/src/test/java/org/eclipse/jetty/client/HttpSenderTest.java
@@ -20,6 +20,7 @@ package org.eclipse.jetty.client;
import java.net.URI;
import java.nio.ByteBuffer;
+import java.nio.charset.StandardCharsets;
import java.util.Locale;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
@@ -191,7 +192,7 @@ public class HttpSenderTest
HttpConnection connection = new HttpConnection(client, endPoint, destination);
Request request = client.newRequest(URI.create("http://localhost/"));
String content = "abcdef";
- request.content(new ByteBufferContentProvider(ByteBuffer.wrap(content.getBytes("UTF-8"))));
+ request.content(new ByteBufferContentProvider(ByteBuffer.wrap(content.getBytes(StandardCharsets.UTF_8))));
final CountDownLatch headersLatch = new CountDownLatch(1);
final CountDownLatch successLatch = new CountDownLatch(1);
request.listener(new Request.Listener.Empty()
@@ -226,7 +227,7 @@ public class HttpSenderTest
Request request = client.newRequest(URI.create("http://localhost/"));
String content1 = "0123456789";
String content2 = "abcdef";
- request.content(new ByteBufferContentProvider(ByteBuffer.wrap(content1.getBytes("UTF-8")), ByteBuffer.wrap(content2.getBytes("UTF-8"))));
+ request.content(new ByteBufferContentProvider(ByteBuffer.wrap(content1.getBytes(StandardCharsets.UTF_8)), ByteBuffer.wrap(content2.getBytes(StandardCharsets.UTF_8))));
final CountDownLatch headersLatch = new CountDownLatch(1);
final CountDownLatch successLatch = new CountDownLatch(1);
request.listener(new Request.Listener.Empty()
@@ -261,7 +262,7 @@ public class HttpSenderTest
Request request = client.newRequest(URI.create("http://localhost/"));
String content1 = "0123456789";
String content2 = "ABCDEF";
- request.content(new ByteBufferContentProvider(ByteBuffer.wrap(content1.getBytes("UTF-8")), ByteBuffer.wrap(content2.getBytes("UTF-8")))
+ request.content(new ByteBufferContentProvider(ByteBuffer.wrap(content1.getBytes(StandardCharsets.UTF_8)), ByteBuffer.wrap(content2.getBytes(StandardCharsets.UTF_8)))
{
@Override
public long getLength()
diff --git a/jetty-client/src/test/java/org/eclipse/jetty/client/api/Usage.java b/jetty-client/src/test/java/org/eclipse/jetty/client/api/Usage.java
index cd7d09e..15d15e2 100644
--- a/jetty-client/src/test/java/org/eclipse/jetty/client/api/Usage.java
+++ b/jetty-client/src/test/java/org/eclipse/jetty/client/api/Usage.java
@@ -24,6 +24,7 @@ import java.io.OutputStream;
import java.net.HttpCookie;
import java.net.URI;
import java.nio.ByteBuffer;
+import java.nio.charset.StandardCharsets;
import java.nio.file.Paths;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
@@ -269,7 +270,7 @@ public class Usage
HttpClient client = new HttpClient();
client.start();
- InputStream input = new ByteArrayInputStream("content".getBytes("UTF-8"));
+ InputStream input = new ByteArrayInputStream("content".getBytes(StandardCharsets.UTF_8));
ContentResponse response = client.newRequest("localhost", 8080)
// Provide the content as InputStream
diff --git a/jetty-client/src/test/java/org/eclipse/jetty/client/ssl/SslBytesClientTest.java b/jetty-client/src/test/java/org/eclipse/jetty/client/ssl/SslBytesClientTest.java
index ad75b48..b2b860d 100644
--- a/jetty-client/src/test/java/org/eclipse/jetty/client/ssl/SslBytesClientTest.java
+++ b/jetty-client/src/test/java/org/eclipse/jetty/client/ssl/SslBytesClientTest.java
@@ -24,6 +24,7 @@ import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.SocketTimeoutException;
+import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
@@ -151,7 +152,7 @@ public class SslBytesClientTest extends SslBytesTest
SimpleProxy.AutomaticFlow automaticProxyFlow = proxy.startAutomaticFlow();
// Read request
- BufferedReader reader = new BufferedReader(new InputStreamReader(server.getInputStream(), "UTF-8"));
+ BufferedReader reader = new BufferedReader(new InputStreamReader(server.getInputStream(), StandardCharsets.UTF_8));
String line = reader.readLine();
Assert.assertTrue(line.startsWith("GET"));
while (line.length() > 0)
@@ -161,7 +162,7 @@ public class SslBytesClientTest extends SslBytesTest
OutputStream output = server.getOutputStream();
output.write(("HTTP/1.1 200 OK\r\n" +
"Content-Length: 0\r\n" +
- "\r\n").getBytes("UTF-8"));
+ "\r\n").getBytes(StandardCharsets.UTF_8));
output.flush();
Assert.assertTrue(automaticProxyFlow.stop(5, TimeUnit.SECONDS));
@@ -197,7 +198,7 @@ public class SslBytesClientTest extends SslBytesTest
// Read request
InputStream serverInput = server.getInputStream();
- BufferedReader reader = new BufferedReader(new InputStreamReader(serverInput, "UTF-8"));
+ BufferedReader reader = new BufferedReader(new InputStreamReader(serverInput, StandardCharsets.UTF_8));
String line = reader.readLine();
Assert.assertTrue(line.startsWith("GET"));
while (line.length() > 0)
@@ -206,16 +207,16 @@ public class SslBytesClientTest extends SslBytesTest
OutputStream serverOutput = server.getOutputStream();
byte[] data1 = new byte[1024];
Arrays.fill(data1, (byte)'X');
- String content1 = new String(data1, "UTF-8");
+ String content1 = new String(data1, StandardCharsets.UTF_8);
byte[] data2 = new byte[1024];
Arrays.fill(data2, (byte)'Y');
- final String content2 = new String(data2, "UTF-8");
+ final String content2 = new String(data2, StandardCharsets.UTF_8);
// Write first part of the response
serverOutput.write(("HTTP/1.1 200 OK\r\n" +
"Content-Type: text/plain\r\n" +
"Content-Length: " + (content1.length() + content2.length()) + "\r\n" +
"\r\n" +
- content1).getBytes("UTF-8"));
+ content1).getBytes(StandardCharsets.UTF_8));
serverOutput.flush();
Assert.assertTrue(automaticProxyFlow.stop(5, TimeUnit.SECONDS));
@@ -319,7 +320,7 @@ public class SslBytesClientTest extends SslBytesTest
// Read request
InputStream serverInput = server.getInputStream();
- BufferedReader reader = new BufferedReader(new InputStreamReader(serverInput, "UTF-8"));
+ BufferedReader reader = new BufferedReader(new InputStreamReader(serverInput, StandardCharsets.UTF_8));
String line = reader.readLine();
Assert.assertTrue(line.startsWith("GET"));
while (line.length() > 0)
@@ -328,16 +329,16 @@ public class SslBytesClientTest extends SslBytesTest
OutputStream serverOutput = server.getOutputStream();
byte[] data1 = new byte[1024];
Arrays.fill(data1, (byte)'X');
- String content1 = new String(data1, "UTF-8");
+ String content1 = new String(data1, StandardCharsets.UTF_8);
byte[] data2 = new byte[1024];
Arrays.fill(data2, (byte)'Y');
- final String content2 = new String(data2, "UTF-8");
+ final String content2 = new String(data2, StandardCharsets.UTF_8);
// Write first part of the response
serverOutput.write(("HTTP/1.1 200 OK\r\n" +
"Content-Type: text/plain\r\n" +
"Content-Length: " + (content1.length() + content2.length()) + "\r\n" +
"\r\n" +
- content1).getBytes("UTF-8"));
+ content1).getBytes(StandardCharsets.UTF_8));
serverOutput.flush();
Assert.assertTrue(automaticProxyFlow.stop(5, TimeUnit.SECONDS));
diff --git a/jetty-client/src/test/java/org/eclipse/jetty/client/ssl/SslBytesServerTest.java b/jetty-client/src/test/java/org/eclipse/jetty/client/ssl/SslBytesServerTest.java
index 4802db7..9f585ac 100644
--- a/jetty-client/src/test/java/org/eclipse/jetty/client/ssl/SslBytesServerTest.java
+++ b/jetty-client/src/test/java/org/eclipse/jetty/client/ssl/SslBytesServerTest.java
@@ -28,6 +28,7 @@ import java.net.SocketTimeoutException;
import java.nio.ByteBuffer;
import java.nio.channels.SelectionKey;
import java.nio.channels.SocketChannel;
+import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.concurrent.Callable;
import java.util.concurrent.CountDownLatch;
@@ -575,7 +576,7 @@ public class SslBytesServerTest extends SslBytesTest
clientOutput.write(("" +
"GET / HTTP/1.1\r\n" +
"Host: localhost\r\n" +
- "\r\n").getBytes("UTF-8"));
+ "\r\n").getBytes(StandardCharsets.UTF_8));
clientOutput.flush();
return null;
}
@@ -617,7 +618,7 @@ public class SslBytesServerTest extends SslBytesTest
clientOutput.write(("" +
"GET / HTTP/1.1\r\n" +
"Host: localhost\r\n" +
- "\r\n").getBytes("UTF-8"));
+ "\r\n").getBytes(StandardCharsets.UTF_8));
clientOutput.flush();
return null;
}
@@ -633,7 +634,7 @@ public class SslBytesServerTest extends SslBytesTest
Assert.assertEquals(TLSRecord.Type.APPLICATION, record.getType());
proxy.flushToClient(record);
- BufferedReader reader = new BufferedReader(new InputStreamReader(client.getInputStream(), "UTF-8"));
+ BufferedReader reader = new BufferedReader(new InputStreamReader(client.getInputStream(), StandardCharsets.UTF_8));
String line = reader.readLine();
Assert.assertNotNull(line);
Assert.assertTrue(line.startsWith("HTTP/1.1 200 "));
@@ -710,7 +711,7 @@ public class SslBytesServerTest extends SslBytesTest
clientOutput.write(("" +
"GET / HTTP/1.1\r\n" +
"Host: localhost\r\n" +
- "\r\n").getBytes("UTF-8"));
+ "\r\n").getBytes(StandardCharsets.UTF_8));
clientOutput.flush();
return null;
}
@@ -727,7 +728,7 @@ public class SslBytesServerTest extends SslBytesTest
Assert.assertEquals(TLSRecord.Type.APPLICATION, record.getType());
proxy.flushToClient(record);
- BufferedReader reader = new BufferedReader(new InputStreamReader(client.getInputStream(), "UTF-8"));
+ BufferedReader reader = new BufferedReader(new InputStreamReader(client.getInputStream(), StandardCharsets.UTF_8));
String line = reader.readLine();
Assert.assertNotNull(line);
Assert.assertTrue(line.startsWith("HTTP/1.1 200 "));
@@ -782,7 +783,7 @@ public class SslBytesServerTest extends SslBytesTest
clientOutput.write(("" +
"GET / HTTP/1.1\r\n" +
"Host: localhost\r\n" +
- "\r\n").getBytes("UTF-8"));
+ "\r\n").getBytes(StandardCharsets.UTF_8));
clientOutput.flush();
return null;
}
@@ -850,7 +851,7 @@ public class SslBytesServerTest extends SslBytesTest
clientOutput.write(("" +
"GET / HTTP/1.1\r\n" +
"Host: localhost\r\n" +
- "\r\n").getBytes("UTF-8"));
+ "\r\n").getBytes(StandardCharsets.UTF_8));
clientOutput.flush();
return null;
}
@@ -913,7 +914,7 @@ public class SslBytesServerTest extends SslBytesTest
clientOutput.write(("" +
"GET / HTTP/1.1\r\n" +
"Host: localhost\r\n" +
- "\r\n").getBytes("UTF-8"));
+ "\r\n").getBytes(StandardCharsets.UTF_8));
clientOutput.flush();
return null;
}
@@ -964,7 +965,7 @@ public class SslBytesServerTest extends SslBytesTest
clientOutput.write(("" +
"GET / HTTP/1.1\r\n" +
"Host: localhost\r\n" +
- "\r\n").getBytes("UTF-8"));
+ "\r\n").getBytes(StandardCharsets.UTF_8));
clientOutput.flush();
return null;
}
@@ -1007,7 +1008,7 @@ public class SslBytesServerTest extends SslBytesTest
byte[] data = new byte[128 * 1024];
Arrays.fill(data, (byte)'X');
- final String content = new String(data, "UTF-8");
+ final String content = new String(data, StandardCharsets.UTF_8);
Future<Object> request = threadPool.submit(new Callable<Object>()
{
@Override
@@ -1019,7 +1020,7 @@ public class SslBytesServerTest extends SslBytesTest
"Host: localhost\r\n" +
"Content-Length: " + content.length() + "\r\n" +
"\r\n" +
- content).getBytes("UTF-8"));
+ content).getBytes(StandardCharsets.UTF_8));
clientOutput.flush();
return null;
}
@@ -1065,7 +1066,7 @@ public class SslBytesServerTest extends SslBytesTest
byte[] data = new byte[128 * 1024];
Arrays.fill(data, (byte)'X');
- final String content = new String(data, "UTF-8");
+ final String content = new String(data, StandardCharsets.UTF_8);
Future<Object> request = threadPool.submit(new Callable<Object>()
{
@Override
@@ -1077,7 +1078,7 @@ public class SslBytesServerTest extends SslBytesTest
"Host: localhost\r\n" +
"Content-Length: " + content.length() + "\r\n" +
"\r\n" +
- content).getBytes("UTF-8"));
+ content).getBytes(StandardCharsets.UTF_8));
clientOutput.flush();
return null;
}
@@ -1139,7 +1140,7 @@ public class SslBytesServerTest extends SslBytesTest
clientOutput.write(("" +
"GET / HTTP/1.1\r\n" +
"Host: localhost\r\n" +
- "\r\n").getBytes("UTF-8"));
+ "\r\n").getBytes(StandardCharsets.UTF_8));
clientOutput.flush();
return null;
}
@@ -1211,7 +1212,7 @@ public class SslBytesServerTest extends SslBytesTest
"Content-Type: text/plain\r\n" +
"Content-Length: " + content.length() + "\r\n" +
"\r\n" +
- content).getBytes("UTF-8"));
+ content).getBytes(StandardCharsets.UTF_8));
clientOutput.flush();
return null;
}
@@ -1232,7 +1233,7 @@ public class SslBytesServerTest extends SslBytesTest
Assert.assertEquals(TLSRecord.Type.APPLICATION, record.getType());
proxy.flushToClient(record);
- BufferedReader reader = new BufferedReader(new InputStreamReader(client.getInputStream(), "UTF-8"));
+ BufferedReader reader = new BufferedReader(new InputStreamReader(client.getInputStream(), StandardCharsets.UTF_8));
String line = reader.readLine();
Assert.assertNotNull(line);
Assert.assertTrue(line.startsWith("HTTP/1.1 200 "));
@@ -1263,7 +1264,7 @@ public class SslBytesServerTest extends SslBytesTest
// Use a content that is larger than the TLS record which is 2^14 (around 16k)
byte[] data = new byte[128 * 1024];
Arrays.fill(data, (byte)'X');
- final String content = new String(data, "UTF-8");
+ final String content = new String(data, StandardCharsets.UTF_8);
Future<Object> request = threadPool.submit(new Callable<Object>()
{
@@ -1277,7 +1278,7 @@ public class SslBytesServerTest extends SslBytesTest
"Content-Type: text/plain\r\n" +
"Content-Length: " + content.length() + "\r\n" +
"\r\n" +
- content).getBytes("UTF-8"));
+ content).getBytes(StandardCharsets.UTF_8));
clientOutput.flush();
return null;
}
@@ -1309,7 +1310,7 @@ public class SslBytesServerTest extends SslBytesTest
Assert.assertEquals(TLSRecord.Type.APPLICATION, record.getType());
proxy.flushToClient(record);
- BufferedReader reader = new BufferedReader(new InputStreamReader(client.getInputStream(), "UTF-8"));
+ BufferedReader reader = new BufferedReader(new InputStreamReader(client.getInputStream(), StandardCharsets.UTF_8));
String line = reader.readLine();
Assert.assertNotNull(line);
Assert.assertTrue(line.startsWith("HTTP/1.1 200 "));
@@ -1344,10 +1345,10 @@ public class SslBytesServerTest extends SslBytesTest
byte[] data1 = new byte[1024];
Arrays.fill(data1, (byte)'X');
- String content1 = new String(data1, "UTF-8");
+ String content1 = new String(data1, StandardCharsets.UTF_8);
byte[] data2 = new byte[1024];
Arrays.fill(data2, (byte)'Y');
- final String content2 = new String(data2, "UTF-8");
+ final String content2 = new String(data2, StandardCharsets.UTF_8);
// Write only part of the body
automaticProxyFlow = proxy.startAutomaticFlow();
@@ -1357,7 +1358,7 @@ public class SslBytesServerTest extends SslBytesTest
"Content-Type: text/plain\r\n" +
"Content-Length: " + (content1.length() + content2.length()) + "\r\n" +
"\r\n" +
- content1).getBytes("UTF-8"));
+ content1).getBytes(StandardCharsets.UTF_8));
clientOutput.flush();
Assert.assertTrue(automaticProxyFlow.stop(5, TimeUnit.SECONDS));
@@ -1391,7 +1392,7 @@ public class SslBytesServerTest extends SslBytesTest
@Override
public Object call() throws Exception
{
- clientOutput.write(content2.getBytes("UTF-8"));
+ clientOutput.write(content2.getBytes(StandardCharsets.UTF_8));
clientOutput.flush();
return null;
}
@@ -1435,10 +1436,10 @@ public class SslBytesServerTest extends SslBytesTest
// Use a content that is larger than the TLS record which is 2^14 (around 16k)
byte[] data1 = new byte[80 * 1024];
Arrays.fill(data1, (byte)'X');
- String content1 = new String(data1, "UTF-8");
+ String content1 = new String(data1, StandardCharsets.UTF_8);
byte[] data2 = new byte[48 * 1024];
Arrays.fill(data2, (byte)'Y');
- final String content2 = new String(data2, "UTF-8");
+ final String content2 = new String(data2, StandardCharsets.UTF_8);
// Write only part of the body
automaticProxyFlow = proxy.startAutomaticFlow();
@@ -1448,7 +1449,7 @@ public class SslBytesServerTest extends SslBytesTest
"Content-Type: text/plain\r\n" +
"Content-Length: " + (content1.length() + content2.length()) + "\r\n" +
"\r\n" +
- content1).getBytes("UTF-8"));
+ content1).getBytes(StandardCharsets.UTF_8));
clientOutput.flush();
Assert.assertTrue(automaticProxyFlow.stop(5, TimeUnit.SECONDS));
@@ -1513,7 +1514,7 @@ public class SslBytesServerTest extends SslBytesTest
@Override
public Object call() throws Exception
{
- clientOutput.write(content2.getBytes("UTF-8"));
+ clientOutput.write(content2.getBytes(StandardCharsets.UTF_8));
clientOutput.flush();
return null;
}
@@ -1535,7 +1536,7 @@ public class SslBytesServerTest extends SslBytesTest
Assert.assertEquals(TLSRecord.Type.APPLICATION, record.getType());
proxy.flushToClient(record);
- BufferedReader reader = new BufferedReader(new InputStreamReader(client.getInputStream(), "UTF-8"));
+ BufferedReader reader = new BufferedReader(new InputStreamReader(client.getInputStream(), StandardCharsets.UTF_8));
String line = reader.readLine();
Assert.assertNotNull(line);
Assert.assertTrue(line.startsWith("HTTP/1.1 200 "));
@@ -1569,10 +1570,10 @@ public class SslBytesServerTest extends SslBytesTest
// Use a content that is larger than the TLS record which is 2^14 (around 16k)
byte[] data1 = new byte[80 * 1024];
Arrays.fill(data1, (byte)'X');
- String content1 = new String(data1, "UTF-8");
+ String content1 = new String(data1, StandardCharsets.UTF_8);
byte[] data2 = new byte[48 * 1024];
Arrays.fill(data2, (byte)'Y');
- final String content2 = new String(data2, "UTF-8");
+ final String content2 = new String(data2, StandardCharsets.UTF_8);
// Write only part of the body
automaticProxyFlow = proxy.startAutomaticFlow();
@@ -1582,7 +1583,7 @@ public class SslBytesServerTest extends SslBytesTest
"Content-Type: text/plain\r\n" +
"Content-Length: " + (content1.length() + content2.length()) + "\r\n" +
"\r\n" +
- content1).getBytes("UTF-8"));
+ content1).getBytes(StandardCharsets.UTF_8));
clientOutput.flush();
Assert.assertTrue(automaticProxyFlow.stop(5, TimeUnit.SECONDS));
@@ -1665,7 +1666,7 @@ public class SslBytesServerTest extends SslBytesTest
@Override
public Object call() throws Exception
{
- clientOutput.write(content2.getBytes("UTF-8"));
+ clientOutput.write(content2.getBytes(StandardCharsets.UTF_8));
clientOutput.flush();
return null;
}
@@ -1697,7 +1698,7 @@ public class SslBytesServerTest extends SslBytesTest
Assert.assertEquals(TLSRecord.Type.APPLICATION, record.getType());
proxy.flushToClient(record);
- BufferedReader reader = new BufferedReader(new InputStreamReader(client.getInputStream(), "UTF-8"));
+ BufferedReader reader = new BufferedReader(new InputStreamReader(client.getInputStream(), StandardCharsets.UTF_8));
String line = reader.readLine();
Assert.assertNotNull(line);
Assert.assertTrue(line.startsWith("HTTP/1.1 200 "));
@@ -1728,7 +1729,7 @@ public class SslBytesServerTest extends SslBytesTest
byte[] data = new byte[3 * 1024];
Arrays.fill(data, (byte)'Y');
- String content = new String(data, "UTF-8");
+ String content = new String(data, StandardCharsets.UTF_8);
automaticProxyFlow = proxy.startAutomaticFlow();
clientOutput.write(("" +
"POST / HTTP/1.1\r\n" +
@@ -1737,10 +1738,10 @@ public class SslBytesServerTest extends SslBytesTest
"Content-Length: " + content.length() + "\r\n" +
"Connection: close\r\n" +
"\r\n" +
- content).getBytes("UTF-8"));
+ content).getBytes(StandardCharsets.UTF_8));
clientOutput.flush();
- BufferedReader reader = new BufferedReader(new InputStreamReader(client.getInputStream(), "UTF-8"));
+ BufferedReader reader = new BufferedReader(new InputStreamReader(client.getInputStream(), StandardCharsets.UTF_8));
String line = reader.readLine();
Assert.assertNotNull(line);
Assert.assertTrue(line.startsWith("HTTP/1.1 200 "));
@@ -1786,7 +1787,7 @@ public class SslBytesServerTest extends SslBytesTest
});
// Instead of passing the Client Hello, we simulate plain text was passed in
- proxy.flushToServer(0, "GET / HTTP/1.1\r\n".getBytes("UTF-8"));
+ proxy.flushToServer(0, "GET / HTTP/1.1\r\n".getBytes(StandardCharsets.UTF_8));
// We expect that the server closes the connection immediately
TLSRecord record = proxy.readFromServer();
@@ -1820,7 +1821,7 @@ public class SslBytesServerTest extends SslBytesTest
clientOutput.write(("" +
"GET / HTTP/1.1\r\n" +
"Host: localhost\r\n" +
- "\r\n").getBytes("UTF-8"));
+ "\r\n").getBytes(StandardCharsets.UTF_8));
clientOutput.flush();
latch.countDown();
}
diff --git a/jetty-http/src/main/java/org/eclipse/jetty/http/HttpField.java b/jetty-http/src/main/java/org/eclipse/jetty/http/HttpField.java
index 8241d1d..81af822 100644
--- a/jetty-http/src/main/java/org/eclipse/jetty/http/HttpField.java
+++ b/jetty-http/src/main/java/org/eclipse/jetty/http/HttpField.java
@@ -19,6 +19,7 @@
package org.eclipse.jetty.http;
import java.nio.ByteBuffer;
+import java.nio.charset.StandardCharsets;
import java.util.HashSet;
import java.util.Set;
@@ -176,7 +177,7 @@ public class HttpField
private static byte[] toSanitisedName(String s)
{
- byte[] bytes = s.getBytes(StringUtil.__ISO_8859_1_CHARSET);
+ byte[] bytes = s.getBytes(StandardCharsets.ISO_8859_1);
for (int i=bytes.length;i-->0;)
{
switch(bytes[i])
@@ -192,7 +193,7 @@ public class HttpField
private static byte[] toSanitisedValue(String s)
{
- byte[] bytes = s.getBytes(StringUtil.__ISO_8859_1_CHARSET);
+ byte[] bytes = s.getBytes(StandardCharsets.ISO_8859_1);
for (int i=bytes.length;i-->0;)
{
switch(bytes[i])
diff --git a/jetty-http/src/main/java/org/eclipse/jetty/http/HttpParser.java b/jetty-http/src/main/java/org/eclipse/jetty/http/HttpParser.java
index db46429..7810666 100644
--- a/jetty-http/src/main/java/org/eclipse/jetty/http/HttpParser.java
+++ b/jetty-http/src/main/java/org/eclipse/jetty/http/HttpParser.java
@@ -19,6 +19,7 @@
package org.eclipse.jetty.http;
import java.nio.ByteBuffer;
+import java.nio.charset.StandardCharsets;
import org.eclipse.jetty.http.HttpTokens.EndOfContent;
import org.eclipse.jetty.util.ArrayTernaryTrie;
@@ -969,12 +970,12 @@ public class HttpParser
// Have to get the fields exactly from the buffer to match case
String fn=field.getName();
String fv=field.getValue();
- n=BufferUtil.toString(buffer,buffer.position()-1,fn.length(),StringUtil.__US_ASCII_CHARSET);
+ n=BufferUtil.toString(buffer,buffer.position()-1,fn.length(),StandardCharsets.US_ASCII);
if (fv==null)
v=null;
else
{
- v=BufferUtil.toString(buffer,buffer.position()+fn.length()+1,fv.length(),StringUtil.__ISO_8859_1_CHARSET);
+ v=BufferUtil.toString(buffer,buffer.position()+fn.length()+1,fv.length(),StandardCharsets.ISO_8859_1);
field=new HttpField(field.getHeader(),n,v);
}
}
diff --git a/jetty-http/src/main/java/org/eclipse/jetty/http/HttpTester.java b/jetty-http/src/main/java/org/eclipse/jetty/http/HttpTester.java
index 0170d3e..ee4801f 100644
--- a/jetty-http/src/main/java/org/eclipse/jetty/http/HttpTester.java
+++ b/jetty-http/src/main/java/org/eclipse/jetty/http/HttpTester.java
@@ -22,6 +22,7 @@ import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
import org.eclipse.jetty.http.HttpGenerator.RequestInfo;
import org.eclipse.jetty.http.HttpGenerator.ResponseInfo;
@@ -346,7 +347,7 @@ public class HttpTester
String content_type=get(HttpHeader.CONTENT_TYPE);
String encoding=MimeTypes.getCharsetFromContentType(content_type);
- Charset charset=encoding==null?StringUtil.__UTF8_CHARSET:Charset.forName(encoding);
+ Charset charset=encoding==null?StandardCharsets.UTF_8:Charset.forName(encoding);
return new String(bytes,charset);
}
diff --git a/jetty-http/src/main/java/org/eclipse/jetty/http/HttpURI.java b/jetty-http/src/main/java/org/eclipse/jetty/http/HttpURI.java
index dcd00cf..4710126 100644
--- a/jetty-http/src/main/java/org/eclipse/jetty/http/HttpURI.java
+++ b/jetty-http/src/main/java/org/eclipse/jetty/http/HttpURI.java
@@ -21,6 +21,7 @@ package org.eclipse.jetty.http;
import java.io.UnsupportedEncodingException;
import java.net.URI;
import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
import org.eclipse.jetty.util.MultiMap;
import org.eclipse.jetty.util.StringUtil;
@@ -100,15 +101,7 @@ public class HttpURI
public HttpURI(String raw)
{
_rawString=raw;
- byte[] b;
- try
- {
- b = raw.getBytes(StringUtil.__UTF8);
- }
- catch (UnsupportedEncodingException e)
- {
- throw new RuntimeException(e.getMessage());
- }
+ byte[] b = raw.getBytes(StandardCharsets.UTF_8);
parse(b,0,b.length);
_charset = URIUtil.__CHARSET;
}
@@ -617,9 +610,14 @@ public class HttpURI
return StringUtil.toUTF8String(_raw, _path, _param-_path);
return utf8b.toString();
}
-
+
public String getDecodedPath(String encoding)
{
+ return getDecodedPath(Charset.forName(encoding));
+ }
+
+ public String getDecodedPath(Charset encoding)
+ {
if (_path==_param)
return null;
@@ -678,9 +676,9 @@ public class HttpURI
if (bytes==null)
- return StringUtil.toString(_raw,_path,_param-_path,encoding);
+ return new String(_raw,_path,_param-_path,encoding);
- return StringUtil.toString(bytes,0,n,encoding);
+ return new String(bytes,0,n,encoding);
}
public String getPathAndParam()
@@ -734,10 +732,10 @@ public class HttpURI
{
if (_query==_fragment)
return;
- if (_charset==StringUtil.__UTF8_CHARSET)
+ if (_charset.equals(StandardCharsets.UTF_8))
UrlEncoded.decodeUtf8To(_raw,_query+1,_fragment-_query-1,parameters);
else
- UrlEncoded.decodeTo(StringUtil.toString(_raw,_query+1,_fragment-_query-1,_charset.toString()),parameters,_charset.toString(),-1);
+ UrlEncoded.decodeTo(new String(_raw,_query+1,_fragment-_query-1,_charset),parameters,_charset,-1);
}
public void decodeQueryTo(MultiMap<String> parameters, String encoding) throws UnsupportedEncodingException
@@ -751,6 +749,17 @@ public class HttpURI
UrlEncoded.decodeTo(StringUtil.toString(_raw,_query+1,_fragment-_query-1,encoding),parameters,encoding,-1);
}
+ public void decodeQueryTo(MultiMap<String> parameters, Charset encoding) throws UnsupportedEncodingException
+ {
+ if (_query==_fragment)
+ return;
+
+ if (encoding==null || StandardCharsets.UTF_8.equals(encoding))
+ UrlEncoded.decodeUtf8To(_raw,_query+1,_fragment-_query-1,parameters);
+ else
+ UrlEncoded.decodeTo(new String(_raw,_query+1,_fragment-_query-1,encoding),parameters,encoding,-1);
+ }
+
public void clear()
{
_scheme=_authority=_host=_port=_path=_param=_query=_fragment=_end=0;
diff --git a/jetty-http/src/test/java/org/eclipse/jetty/http/HttpParserTest.java b/jetty-http/src/test/java/org/eclipse/jetty/http/HttpParserTest.java
index 0c88ca5..9f105ca 100644
--- a/jetty-http/src/test/java/org/eclipse/jetty/http/HttpParserTest.java
+++ b/jetty-http/src/test/java/org/eclipse/jetty/http/HttpParserTest.java
@@ -24,6 +24,7 @@ import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import java.nio.ByteBuffer;
+import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;
@@ -112,7 +113,7 @@ public class HttpParserTest
@Test
public void testLineParse3() throws Exception
{
- ByteBuffer buffer= BufferUtil.toBuffer("POST /fo\u0690 HTTP/1.0\015\012" + "\015\012",StringUtil.__UTF8_CHARSET);
+ ByteBuffer buffer= BufferUtil.toBuffer("POST /fo\u0690 HTTP/1.0\015\012" + "\015\012",StandardCharsets.UTF_8);
HttpParser.RequestHandler<ByteBuffer> handler = new Handler();
HttpParser parser= new HttpParser(handler);
@@ -126,7 +127,7 @@ public class HttpParserTest
@Test
public void testLineParse4() throws Exception
{
- ByteBuffer buffer= BufferUtil.toBuffer("POST /foo?param=\u0690 HTTP/1.0\015\012" + "\015\012",StringUtil.__UTF8_CHARSET);
+ ByteBuffer buffer= BufferUtil.toBuffer("POST /foo?param=\u0690 HTTP/1.0\015\012" + "\015\012",StandardCharsets.UTF_8);
HttpParser.RequestHandler<ByteBuffer> handler = new Handler();
HttpParser parser= new HttpParser(handler);
@@ -321,10 +322,10 @@ public class HttpParserTest
ByteBuffer buffer=BufferUtil.allocate(4096);
BufferUtil.flipToFill(buffer);
BufferUtil.put(BufferUtil.toBuffer("GET "),buffer);
- buffer.put("/foo/\u0690/".getBytes(StringUtil.__UTF8_CHARSET));
+ buffer.put("/foo/\u0690/".getBytes(StandardCharsets.UTF_8));
BufferUtil.put(BufferUtil.toBuffer(" HTTP/1.0\r\n"),buffer);
BufferUtil.put(BufferUtil.toBuffer("Header1: "),buffer);
- buffer.put("\u00e6 \u00e6".getBytes(StringUtil.__ISO_8859_1_CHARSET));
+ buffer.put("\u00e6 \u00e6".getBytes(StandardCharsets.ISO_8859_1));
BufferUtil.put(BufferUtil.toBuffer(" \r\n\r\n"),buffer);
BufferUtil.flipToFlush(buffer,0);
@@ -1165,7 +1166,7 @@ public class HttpParserTest
{
if (_content==null)
_content="";
- String c = BufferUtil.toString(ref,StringUtil.__UTF8_CHARSET);
+ String c = BufferUtil.toString(ref,StandardCharsets.UTF_8);
//System.err.println("content '"+c+"'");
_content= _content + c;
ref.position(ref.limit());
diff --git a/jetty-io/src/main/java/org/eclipse/jetty/io/ByteArrayEndPoint.java b/jetty-io/src/main/java/org/eclipse/jetty/io/ByteArrayEndPoint.java
index 156cd15..460b298 100644
--- a/jetty-io/src/main/java/org/eclipse/jetty/io/ByteArrayEndPoint.java
+++ b/jetty-io/src/main/java/org/eclipse/jetty/io/ByteArrayEndPoint.java
@@ -23,6 +23,7 @@ import java.net.InetSocketAddress;
import java.nio.ByteBuffer;
import java.nio.channels.ClosedChannelException;
import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
import org.eclipse.jetty.util.BufferUtil;
import org.eclipse.jetty.util.StringUtil;
@@ -153,7 +154,7 @@ public class ByteArrayEndPoint extends AbstractEndPoint
/* ------------------------------------------------------------ */
public void setInput(String s)
{
- setInput(BufferUtil.toBuffer(s,StringUtil.__UTF8_CHARSET));
+ setInput(BufferUtil.toBuffer(s,StandardCharsets.UTF_8));
}
/* ------------------------------------------------------------ */
@@ -177,7 +178,7 @@ public class ByteArrayEndPoint extends AbstractEndPoint
*/
public String getOutputString()
{
- return getOutputString(StringUtil.__UTF8_CHARSET);
+ return getOutputString(StandardCharsets.UTF_8);
}
/* ------------------------------------------------------------ */
@@ -207,7 +208,7 @@ public class ByteArrayEndPoint extends AbstractEndPoint
*/
public String takeOutputString()
{
- return takeOutputString(StringUtil.__UTF8_CHARSET);
+ return takeOutputString(StandardCharsets.UTF_8);
}
/* ------------------------------------------------------------ */
diff --git a/jetty-io/src/main/java/org/eclipse/jetty/io/WriterOutputStream.java b/jetty-io/src/main/java/org/eclipse/jetty/io/WriterOutputStream.java
index d94c270..6ea17ff 100644
--- a/jetty-io/src/main/java/org/eclipse/jetty/io/WriterOutputStream.java
+++ b/jetty-io/src/main/java/org/eclipse/jetty/io/WriterOutputStream.java
@@ -21,6 +21,7 @@ package org.eclipse.jetty.io;
import java.io.IOException;
import java.io.OutputStream;
import java.io.Writer;
+import java.nio.charset.Charset;
/* ------------------------------------------------------------ */
@@ -33,14 +34,14 @@ import java.io.Writer;
public class WriterOutputStream extends OutputStream
{
protected final Writer _writer;
- protected final String _encoding;
+ protected final Charset _encoding;
private final byte[] _buf=new byte[1];
/* ------------------------------------------------------------ */
public WriterOutputStream(Writer writer, String encoding)
{
_writer=writer;
- _encoding=encoding;
+ _encoding=encoding==null?null:Charset.forName(encoding);
}
/* ------------------------------------------------------------ */
diff --git a/jetty-io/src/test/java/org/eclipse/jetty/io/IOTest.java b/jetty-io/src/test/java/org/eclipse/jetty/io/IOTest.java
index 18f0404..2d77b93 100644
--- a/jetty-io/src/test/java/org/eclipse/jetty/io/IOTest.java
+++ b/jetty-io/src/test/java/org/eclipse/jetty/io/IOTest.java
@@ -36,6 +36,7 @@ import java.nio.channels.AsynchronousServerSocketChannel;
import java.nio.channels.AsynchronousSocketChannel;
import java.nio.channels.ServerSocketChannel;
import java.nio.channels.SocketChannel;
+import java.nio.charset.StandardCharsets;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
@@ -444,7 +445,7 @@ public class IOTest
ByteBuffer read = ByteBuffer.allocate(1024);
Future<Integer> reading = server.read(read);
- byte[] data = "Testing 1 2 3".getBytes("UTF-8");
+ byte[] data = "Testing 1 2 3".getBytes(StandardCharsets.UTF_8);
ByteBuffer write = BufferUtil.toBuffer(data);
Future<Integer> writing = client.write(write);
diff --git a/jetty-io/src/test/java/org/eclipse/jetty/io/SelectChannelEndPointSslTest.java b/jetty-io/src/test/java/org/eclipse/jetty/io/SelectChannelEndPointSslTest.java
index 7bd0596..c796e86 100644
--- a/jetty-io/src/test/java/org/eclipse/jetty/io/SelectChannelEndPointSslTest.java
+++ b/jetty-io/src/test/java/org/eclipse/jetty/io/SelectChannelEndPointSslTest.java
@@ -23,6 +23,7 @@ import java.io.IOException;
import java.net.Socket;
import java.nio.ByteBuffer;
import java.nio.channels.SocketChannel;
+import java.nio.charset.StandardCharsets;
import javax.net.ssl.SSLEngine;
import javax.net.ssl.SSLEngineResult;
import javax.net.ssl.SSLEngineResult.HandshakeStatus;
@@ -170,7 +171,7 @@ public class SelectChannelEndPointSslTest extends SelectChannelEndPointTest
if (debug) System.err.println("\nSay Hello");
// write a message
- appOut.put("HelloWorld".getBytes("UTF-8"));
+ appOut.put("HelloWorld".getBytes(StandardCharsets.UTF_8));
appOut.flip();
SSLEngineResult result =engine.wrap(appOut,sslOut);
if (debug) System.err.println(result);
diff --git a/jetty-io/src/test/java/org/eclipse/jetty/io/SelectChannelEndPointTest.java b/jetty-io/src/test/java/org/eclipse/jetty/io/SelectChannelEndPointTest.java
index 1849dbf..2050706 100644
--- a/jetty-io/src/test/java/org/eclipse/jetty/io/SelectChannelEndPointTest.java
+++ b/jetty-io/src/test/java/org/eclipse/jetty/io/SelectChannelEndPointTest.java
@@ -29,6 +29,7 @@ import java.nio.ByteBuffer;
import java.nio.channels.SelectionKey;
import java.nio.channels.ServerSocketChannel;
import java.nio.channels.SocketChannel;
+import java.nio.charset.StandardCharsets;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
@@ -228,7 +229,7 @@ public class SelectChannelEndPointTest
_manager.accept(server);
// Write client to server
- client.getOutputStream().write("HelloWorld".getBytes("UTF-8"));
+ client.getOutputStream().write("HelloWorld".getBytes(StandardCharsets.UTF_8));
// Verify echo server to client
for (char c : "HelloWorld".toCharArray())
@@ -253,7 +254,7 @@ public class SelectChannelEndPointTest
}
// write then shutdown
- client.getOutputStream().write("Goodbye Cruel TLS".getBytes("UTF-8"));
+ client.getOutputStream().write("Goodbye Cruel TLS".getBytes(StandardCharsets.UTF_8));
// Verify echo server to client
for (char c : "Goodbye Cruel TLS".toCharArray())
@@ -287,7 +288,7 @@ public class SelectChannelEndPointTest
_manager.accept(server);
// Write client to server
- client.getOutputStream().write("HelloWorld".getBytes("UTF-8"));
+ client.getOutputStream().write("HelloWorld".getBytes(StandardCharsets.UTF_8));
// Verify echo server to client
for (char c : "HelloWorld".toCharArray())
@@ -310,7 +311,7 @@ public class SelectChannelEndPointTest
}
// write then shutdown
- client.getOutputStream().write("Goodbye Cruel TLS".getBytes("UTF-8"));
+ client.getOutputStream().write("Goodbye Cruel TLS".getBytes(StandardCharsets.UTF_8));
client.shutdownOutput();
// Verify echo server to client
@@ -343,7 +344,7 @@ public class SelectChannelEndPointTest
// Write 8 and cause block waiting for 10
_blockAt = 10;
- clientOutputStream.write("12345678".getBytes("UTF-8"));
+ clientOutputStream.write("12345678".getBytes(StandardCharsets.UTF_8));
clientOutputStream.flush();
Assert.assertTrue(_lastEndPointLatch.await(1, TimeUnit.SECONDS));
@@ -363,7 +364,7 @@ public class SelectChannelEndPointTest
}
// write remaining characters
- clientOutputStream.write("90ABCDEF".getBytes("UTF-8"));
+ clientOutputStream.write("90ABCDEF".getBytes(StandardCharsets.UTF_8));
clientOutputStream.flush();
// Verify echo server to client
@@ -388,7 +389,7 @@ public class SelectChannelEndPointTest
_manager.accept(server);
// Write client to server
- client.getOutputStream().write("HelloWorld".getBytes("UTF-8"));
+ client.getOutputStream().write("HelloWorld".getBytes(StandardCharsets.UTF_8));
// Verify echo server to client
for (char c : "HelloWorld".toCharArray())
@@ -436,7 +437,7 @@ public class SelectChannelEndPointTest
_manager.accept(server);
// Write client to server
- clientOutputStream.write("HelloWorld".getBytes("UTF-8"));
+ clientOutputStream.write("HelloWorld".getBytes(StandardCharsets.UTF_8));
// Verify echo server to client
for (char c : "HelloWorld".toCharArray())
@@ -452,7 +453,7 @@ public class SelectChannelEndPointTest
// Write 8 and cause block waiting for 10
_blockAt = 10;
- clientOutputStream.write("12345678".getBytes("UTF-8"));
+ clientOutputStream.write("12345678".getBytes(StandardCharsets.UTF_8));
clientOutputStream.flush();
// read until idle shutdown received
@@ -493,8 +494,8 @@ public class SelectChannelEndPointTest
_manager.accept(server);
final int writes = 200000;
- final byte[] bytes = "HelloWorld-".getBytes(StringUtil.__UTF8_CHARSET);
- byte[] count = "0\n".getBytes(StringUtil.__UTF8_CHARSET);
+ final byte[] bytes = "HelloWorld-".getBytes(StandardCharsets.UTF_8);
+ byte[] count = "0\n".getBytes(StandardCharsets.UTF_8);
BufferedOutputStream out = new BufferedOutputStream(client.getOutputStream());
final CountDownLatch latch = new CountDownLatch(writes);
final InputStream in = new BufferedInputStream(client.getInputStream());
@@ -561,7 +562,7 @@ public class SelectChannelEndPointTest
for (int i = 1; i < writes; i++)
{
out.write(bytes);
- out.write(Integer.toString(i).getBytes(StringUtil.__ISO_8859_1_CHARSET));
+ out.write(Integer.toString(i).getBytes(StandardCharsets.ISO_8859_1));
out.write('\n');
if (i % 1000 == 0)
{
@@ -599,7 +600,7 @@ public class SelectChannelEndPointTest
// Write client to server
_writeCount = 10000;
String data = "Now is the time for all good men to come to the aid of the party";
- client.getOutputStream().write(data.getBytes("UTF-8"));
+ client.getOutputStream().write(data.getBytes(StandardCharsets.UTF_8));
BufferedInputStream in = new BufferedInputStream(client.getInputStream());
int byteNum = 0;
diff --git a/jetty-io/src/test/java/org/eclipse/jetty/io/SslConnectionTest.java b/jetty-io/src/test/java/org/eclipse/jetty/io/SslConnectionTest.java
index c02bd00..83a2c40 100644
--- a/jetty-io/src/test/java/org/eclipse/jetty/io/SslConnectionTest.java
+++ b/jetty-io/src/test/java/org/eclipse/jetty/io/SslConnectionTest.java
@@ -27,6 +27,7 @@ import java.nio.ByteBuffer;
import java.nio.channels.SelectionKey;
import java.nio.channels.ServerSocketChannel;
import java.nio.channels.SocketChannel;
+import java.nio.charset.StandardCharsets;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
@@ -234,14 +235,14 @@ public class SslConnectionTest
server.configureBlocking(false);
_manager.accept(server);
- client.getOutputStream().write("Hello".getBytes("UTF-8"));
+ client.getOutputStream().write("Hello".getBytes(StandardCharsets.UTF_8));
byte[] buffer = new byte[1024];
int len=client.getInputStream().read(buffer);
Assert.assertEquals(5, len);
- Assert.assertEquals("Hello",new String(buffer,0,len,StringUtil.__UTF8_CHARSET));
+ Assert.assertEquals("Hello",new String(buffer,0,len,StandardCharsets.UTF_8));
_dispatches.set(0);
- client.getOutputStream().write("World".getBytes("UTF-8"));
+ client.getOutputStream().write("World".getBytes(StandardCharsets.UTF_8));
len=5;
while(len>0)
len-=client.getInputStream().read(buffer);
@@ -266,7 +267,7 @@ public class SslConnectionTest
byte[] buffer = new byte[1024];
int len=client.getInputStream().read(buffer);
- Assert.assertEquals("Hello Client",new String(buffer,0,len,StringUtil.__UTF8_CHARSET));
+ Assert.assertEquals("Hello Client",new String(buffer,0,len,StandardCharsets.UTF_8));
Assert.assertEquals(null,_writeCallback.get(100,TimeUnit.MILLISECONDS));
client.close();
}
@@ -292,7 +293,7 @@ public class SslConnectionTest
{
try
{
- BufferedReader in = new BufferedReader(new InputStreamReader(client.getInputStream(),StringUtil.__UTF8_CHARSET));
+ BufferedReader in = new BufferedReader(new InputStreamReader(client.getInputStream(),StandardCharsets.UTF_8));
while(count.getCount()>0)
{
String line=in.readLine();
@@ -311,7 +312,7 @@ public class SslConnectionTest
for (int i=0;i<LINES;i++)
{
- client.getOutputStream().write(("HelloWorld "+i+"\n").getBytes("UTF-8"));
+ client.getOutputStream().write(("HelloWorld "+i+"\n").getBytes(StandardCharsets.UTF_8));
// System.err.println("wrote");
if (i%1000==0)
{
diff --git a/jetty-jaspi/src/main/java/org/eclipse/jetty/security/jaspi/modules/BaseAuthModule.java b/jetty-jaspi/src/main/java/org/eclipse/jetty/security/jaspi/modules/BaseAuthModule.java
index 5a9a54a..423ffe8 100644
--- a/jetty-jaspi/src/main/java/org/eclipse/jetty/security/jaspi/modules/BaseAuthModule.java
+++ b/jetty-jaspi/src/main/java/org/eclipse/jetty/security/jaspi/modules/BaseAuthModule.java
@@ -19,6 +19,7 @@
package org.eclipse.jetty.security.jaspi.modules;
import java.io.IOException;
+import java.nio.charset.StandardCharsets;
import java.util.Map;
import java.util.Set;
@@ -119,7 +120,7 @@ public class BaseAuthModule implements ServerAuthModule, ServerAuthContext
throws IOException, UnsupportedCallbackException
{
credentials = credentials.substring(credentials.indexOf(' ')+1);
- credentials = B64Code.decode(credentials,StringUtil.__ISO_8859_1);
+ credentials = B64Code.decode(credentials, StandardCharsets.ISO_8859_1);
int i = credentials.indexOf(':');
String userName = credentials.substring(0,i);
String password = credentials.substring(i+1);
diff --git a/jetty-jaspi/src/main/java/org/eclipse/jetty/security/jaspi/modules/DigestAuthModule.java b/jetty-jaspi/src/main/java/org/eclipse/jetty/security/jaspi/modules/DigestAuthModule.java
index f2384b7..90441d9 100644
--- a/jetty-jaspi/src/main/java/org/eclipse/jetty/security/jaspi/modules/DigestAuthModule.java
+++ b/jetty-jaspi/src/main/java/org/eclipse/jetty/security/jaspi/modules/DigestAuthModule.java
@@ -19,6 +19,7 @@
package org.eclipse.jetty.security.jaspi.modules;
import java.io.IOException;
+import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.util.Map;
@@ -306,18 +307,18 @@ public class DigestAuthModule extends BaseAuthModule
else
{
// calc A1 digest
- md.update(username.getBytes(StringUtil.__ISO_8859_1));
+ md.update(username.getBytes(StandardCharsets.ISO_8859_1));
md.update((byte) ':');
- md.update(realm.getBytes(StringUtil.__ISO_8859_1));
+ md.update(realm.getBytes(StandardCharsets.ISO_8859_1));
md.update((byte) ':');
- md.update(password.getBytes(StringUtil.__ISO_8859_1));
+ md.update(password.getBytes(StandardCharsets.ISO_8859_1));
ha1 = md.digest();
}
// calc A2 digest
md.reset();
- md.update(method.getBytes(StringUtil.__ISO_8859_1));
+ md.update(method.getBytes(StandardCharsets.ISO_8859_1));
md.update((byte) ':');
- md.update(uri.getBytes(StringUtil.__ISO_8859_1));
+ md.update(uri.getBytes(StandardCharsets.ISO_8859_1));
byte[] ha2 = md.digest();
// calc digest
@@ -327,17 +328,17 @@ public class DigestAuthModule extends BaseAuthModule
// request-digest = <"> < KD ( H(A1), unq(nonce-value) ":" H(A2)
// ) > <">
- md.update(TypeUtil.toString(ha1, 16).getBytes(StringUtil.__ISO_8859_1));
+ md.update(TypeUtil.toString(ha1, 16).getBytes(StandardCharsets.ISO_8859_1));
md.update((byte) ':');
- md.update(nonce.getBytes(StringUtil.__ISO_8859_1));
+ md.update(nonce.getBytes(StandardCharsets.ISO_8859_1));
md.update((byte) ':');
- md.update(nc.getBytes(StringUtil.__ISO_8859_1));
+ md.update(nc.getBytes(StandardCharsets.ISO_8859_1));
md.update((byte) ':');
- md.update(cnonce.getBytes(StringUtil.__ISO_8859_1));
+ md.update(cnonce.getBytes(StandardCharsets.ISO_8859_1));
md.update((byte) ':');
- md.update(qop.getBytes(StringUtil.__ISO_8859_1));
+ md.update(qop.getBytes(StandardCharsets.ISO_8859_1));
md.update((byte) ':');
- md.update(TypeUtil.toString(ha2, 16).getBytes(StringUtil.__ISO_8859_1));
+ md.update(TypeUtil.toString(ha2, 16).getBytes(StandardCharsets.ISO_8859_1));
byte[] digest = md.digest();
// check digest
diff --git a/jetty-proxy/src/test/java/org/eclipse/jetty/proxy/ConnectHandlerSSLTest.java b/jetty-proxy/src/test/java/org/eclipse/jetty/proxy/ConnectHandlerSSLTest.java
index 656f4e8..e7b18c8 100644
--- a/jetty-proxy/src/test/java/org/eclipse/jetty/proxy/ConnectHandlerSSLTest.java
+++ b/jetty-proxy/src/test/java/org/eclipse/jetty/proxy/ConnectHandlerSSLTest.java
@@ -25,6 +25,7 @@ import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.Socket;
+import java.nio.charset.StandardCharsets;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSocket;
@@ -78,7 +79,7 @@ public class ConnectHandlerSSLTest extends AbstractConnectHandlerTest
OutputStream output = socket.getOutputStream();
BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
- output.write(request.getBytes("UTF-8"));
+ output.write(request.getBytes(StandardCharsets.UTF_8));
output.flush();
// Expect 200 OK from the CONNECT request
@@ -98,7 +99,7 @@ public class ConnectHandlerSSLTest extends AbstractConnectHandlerTest
"GET /echo HTTP/1.1\r\n" +
"Host: " + hostPort + "\r\n" +
"\r\n";
- output.write(request.getBytes("UTF-8"));
+ output.write(request.getBytes(StandardCharsets.UTF_8));
output.flush();
response = readResponse(input);
@@ -121,7 +122,7 @@ public class ConnectHandlerSSLTest extends AbstractConnectHandlerTest
OutputStream output = socket.getOutputStream();
BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
- output.write(request.getBytes("UTF-8"));
+ output.write(request.getBytes(StandardCharsets.UTF_8));
output.flush();
// Expect 200 OK from the CONNECT request
@@ -145,7 +146,7 @@ public class ConnectHandlerSSLTest extends AbstractConnectHandlerTest
"Content-Length: 5\r\n" +
"\r\n" +
"HELLO";
- output.write(request.getBytes("UTF-8"));
+ output.write(request.getBytes(StandardCharsets.UTF_8));
output.flush();
response = readResponse(input);
diff --git a/jetty-proxy/src/test/java/org/eclipse/jetty/proxy/ConnectHandlerTest.java b/jetty-proxy/src/test/java/org/eclipse/jetty/proxy/ConnectHandlerTest.java
index ed929ef..e24e57e 100644
--- a/jetty-proxy/src/test/java/org/eclipse/jetty/proxy/ConnectHandlerTest.java
+++ b/jetty-proxy/src/test/java/org/eclipse/jetty/proxy/ConnectHandlerTest.java
@@ -27,6 +27,7 @@ import java.io.OutputStream;
import java.net.InetAddress;
import java.net.Socket;
import java.net.UnknownHostException;
+import java.nio.charset.StandardCharsets;
import java.util.Locale;
import java.util.concurrent.ConcurrentMap;
@@ -71,7 +72,7 @@ public class ConnectHandlerTest extends AbstractConnectHandlerTest
OutputStream output = socket.getOutputStream();
BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
- output.write(request.getBytes("UTF-8"));
+ output.write(request.getBytes(StandardCharsets.UTF_8));
output.flush();
// Expect 200 OK from the CONNECT request
@@ -93,7 +94,7 @@ public class ConnectHandlerTest extends AbstractConnectHandlerTest
OutputStream output = socket.getOutputStream();
BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
- output.write(request.getBytes("UTF-8"));
+ output.write(request.getBytes(StandardCharsets.UTF_8));
output.flush();
// Expect 200 OK from the CONNECT request
@@ -104,7 +105,7 @@ public class ConnectHandlerTest extends AbstractConnectHandlerTest
"GET /echo" + " HTTP/1.1\r\n" +
"Host: " + hostPort + "\r\n" +
"\r\n";
- output.write(request.getBytes("UTF-8"));
+ output.write(request.getBytes(StandardCharsets.UTF_8));
output.flush();
response = readResponse(input);
@@ -130,7 +131,7 @@ public class ConnectHandlerTest extends AbstractConnectHandlerTest
OutputStream output = socket.getOutputStream();
BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
- output.write(request.getBytes("UTF-8"));
+ output.write(request.getBytes(StandardCharsets.UTF_8));
output.flush();
// Expect 403 from the CONNECT request
@@ -151,7 +152,7 @@ public class ConnectHandlerTest extends AbstractConnectHandlerTest
OutputStream output = socket.getOutputStream();
BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
- output.write(request.getBytes("UTF-8"));
+ output.write(request.getBytes(StandardCharsets.UTF_8));
output.flush();
// Expect 200 from the CONNECT request
@@ -162,7 +163,7 @@ public class ConnectHandlerTest extends AbstractConnectHandlerTest
"GET /echo" + " HTTP/1.1\r\n" +
"Host: " + hostPort + "\r\n" +
"\r\n";
- output.write(request.getBytes("UTF-8"));
+ output.write(request.getBytes(StandardCharsets.UTF_8));
output.flush();
response = readResponse(input);
@@ -188,7 +189,7 @@ public class ConnectHandlerTest extends AbstractConnectHandlerTest
OutputStream output = socket.getOutputStream();
BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
- output.write(request.getBytes("UTF-8"));
+ output.write(request.getBytes(StandardCharsets.UTF_8));
output.flush();
// Expect 403 from the CONNECT request
@@ -209,7 +210,7 @@ public class ConnectHandlerTest extends AbstractConnectHandlerTest
OutputStream output = socket.getOutputStream();
BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
- output.write(request.getBytes("UTF-8"));
+ output.write(request.getBytes(StandardCharsets.UTF_8));
output.flush();
// Expect 200 from the CONNECT request
@@ -220,7 +221,7 @@ public class ConnectHandlerTest extends AbstractConnectHandlerTest
"GET /echo" + " HTTP/1.1\r\n" +
"Host: 127.0.0.1:" + port + "\r\n" +
"\r\n";
- output.write(request.getBytes("UTF-8"));
+ output.write(request.getBytes(StandardCharsets.UTF_8));
output.flush();
response = readResponse(input);
@@ -245,7 +246,7 @@ public class ConnectHandlerTest extends AbstractConnectHandlerTest
return false;
}
String b64 = proxyAuthorization.substring("Basic ".length());
- String credentials = B64Code.decode(b64, "UTF-8");
+ String credentials = B64Code.decode(b64, StandardCharsets.UTF_8);
return "test:test".equals(credentials);
}
};
@@ -265,7 +266,7 @@ public class ConnectHandlerTest extends AbstractConnectHandlerTest
OutputStream output = socket.getOutputStream();
BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
- output.write(request.getBytes("UTF-8"));
+ output.write(request.getBytes(StandardCharsets.UTF_8));
output.flush();
// Expect 407 from the CONNECT request
@@ -289,7 +290,7 @@ public class ConnectHandlerTest extends AbstractConnectHandlerTest
OutputStream output = socket.getOutputStream();
BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
- output.write(request.getBytes("UTF-8"));
+ output.write(request.getBytes(StandardCharsets.UTF_8));
output.flush();
// Expect 200 from the CONNECT request
@@ -300,7 +301,7 @@ public class ConnectHandlerTest extends AbstractConnectHandlerTest
"GET /echo" + " HTTP/1.1\r\n" +
"Host: " + hostPort + "\r\n" +
"\r\n";
- output.write(request.getBytes("UTF-8"));
+ output.write(request.getBytes(StandardCharsets.UTF_8));
output.flush();
response = readResponse(input);
@@ -342,7 +343,7 @@ public class ConnectHandlerTest extends AbstractConnectHandlerTest
OutputStream output = socket.getOutputStream();
BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
- output.write(request.getBytes("UTF-8"));
+ output.write(request.getBytes(StandardCharsets.UTF_8));
output.flush();
// Expect 500 OK from the CONNECT request
@@ -368,7 +369,7 @@ public class ConnectHandlerTest extends AbstractConnectHandlerTest
OutputStream output = socket.getOutputStream();
BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
- output.write(request.getBytes("UTF-8"));
+ output.write(request.getBytes(StandardCharsets.UTF_8));
output.flush();
// Expect 200 OK from the CONNECT request
@@ -379,7 +380,7 @@ public class ConnectHandlerTest extends AbstractConnectHandlerTest
"GET /echo" + " HTTP/1.1\r\n" +
"Host: " + hostPort + "\r\n" +
"\r\n";
- output.write(request.getBytes("UTF-8"));
+ output.write(request.getBytes(StandardCharsets.UTF_8));
output.flush();
response = readResponse(input);
@@ -404,7 +405,7 @@ public class ConnectHandlerTest extends AbstractConnectHandlerTest
OutputStream output = socket.getOutputStream();
BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
- output.write(request.getBytes("UTF-8"));
+ output.write(request.getBytes(StandardCharsets.UTF_8));
output.flush();
// Expect 200 OK from the CONNECT request
@@ -431,7 +432,7 @@ public class ConnectHandlerTest extends AbstractConnectHandlerTest
OutputStream output = socket.getOutputStream();
BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
- output.write(request.getBytes("UTF-8"));
+ output.write(request.getBytes(StandardCharsets.UTF_8));
output.flush();
// Expect 200 OK from the CONNECT request
@@ -444,7 +445,7 @@ public class ConnectHandlerTest extends AbstractConnectHandlerTest
"GET /echo" + " HTTP/1.1\r\n" +
"Host: " + hostPort + "\r\n" +
"\r\n";
- output.write(request.getBytes("UTF-8"));
+ output.write(request.getBytes(StandardCharsets.UTF_8));
output.flush();
response = readResponse(input);
@@ -467,7 +468,7 @@ public class ConnectHandlerTest extends AbstractConnectHandlerTest
OutputStream output = socket.getOutputStream();
BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
- output.write(request.getBytes("UTF-8"));
+ output.write(request.getBytes(StandardCharsets.UTF_8));
output.flush();
// Expect 200 OK from the CONNECT request
@@ -478,7 +479,7 @@ public class ConnectHandlerTest extends AbstractConnectHandlerTest
"GET /echo HTTP/1.1\r\n" +
"Host: " + hostPort + "\r\n" +
"\r\n";
- output.write(request.getBytes("UTF-8"));
+ output.write(request.getBytes(StandardCharsets.UTF_8));
output.flush();
response = readResponse(input);
@@ -506,7 +507,7 @@ public class ConnectHandlerTest extends AbstractConnectHandlerTest
OutputStream output = socket.getOutputStream();
BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
- output.write(request.getBytes("UTF-8"));
+ output.write(request.getBytes(StandardCharsets.UTF_8));
output.flush();
// Expect 200 OK from the CONNECT request
@@ -517,7 +518,7 @@ public class ConnectHandlerTest extends AbstractConnectHandlerTest
"GET /close HTTP/1.1\r\n" +
"Host: " + hostPort + "\r\n" +
"\r\n";
- output.write(request.getBytes("UTF-8"));
+ output.write(request.getBytes(StandardCharsets.UTF_8));
output.flush();
int read = input.read();
@@ -538,7 +539,7 @@ public class ConnectHandlerTest extends AbstractConnectHandlerTest
OutputStream output = socket.getOutputStream();
BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
- output.write(request.getBytes("UTF-8"));
+ output.write(request.getBytes(StandardCharsets.UTF_8));
output.flush();
// Expect 200 OK from the CONNECT request
@@ -551,7 +552,7 @@ public class ConnectHandlerTest extends AbstractConnectHandlerTest
"Content-Length: 5\r\n" +
"\r\n" +
"HELLO";
- output.write(request.getBytes("UTF-8"));
+ output.write(request.getBytes(StandardCharsets.UTF_8));
output.flush();
response = readResponse(input);
@@ -562,7 +563,7 @@ public class ConnectHandlerTest extends AbstractConnectHandlerTest
"GET /echo" + " HTTP/1.1\r\n" +
"Host: " + hostPort + "\r\n" +
"\r\n";
- output.write(request.getBytes("UTF-8"));
+ output.write(request.getBytes(StandardCharsets.UTF_8));
output.flush();
response = readResponse(input);
@@ -585,7 +586,7 @@ public class ConnectHandlerTest extends AbstractConnectHandlerTest
OutputStream output = socket.getOutputStream();
BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
- output.write(request.getBytes("UTF-8"));
+ output.write(request.getBytes(StandardCharsets.UTF_8));
output.flush();
// Expect 200 OK from the CONNECT request
@@ -603,7 +604,7 @@ public class ConnectHandlerTest extends AbstractConnectHandlerTest
"Content-Length: " + body.length() + "\r\n" +
"\r\n" +
body;
- output.write(request.getBytes("UTF-8"));
+ output.write(request.getBytes(StandardCharsets.UTF_8));
output.flush();
response = readResponse(input);
@@ -649,7 +650,7 @@ public class ConnectHandlerTest extends AbstractConnectHandlerTest
OutputStream output = socket.getOutputStream();
BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
- output.write(request.getBytes("UTF-8"));
+ output.write(request.getBytes(StandardCharsets.UTF_8));
output.flush();
// Expect 200 OK from the CONNECT request
@@ -663,7 +664,7 @@ public class ConnectHandlerTest extends AbstractConnectHandlerTest
"Content-Length: " + body.length() + "\r\n" +
"\r\n" +
body;
- output.write(request.getBytes("UTF-8"));
+ output.write(request.getBytes(StandardCharsets.UTF_8));
output.flush();
response = readResponse(input);
@@ -688,7 +689,7 @@ public class ConnectHandlerTest extends AbstractConnectHandlerTest
OutputStream output = socket.getOutputStream();
BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
- output.write(request.getBytes("UTF-8"));
+ output.write(request.getBytes(StandardCharsets.UTF_8));
output.flush();
socket.shutdownOutput();
@@ -716,7 +717,7 @@ public class ConnectHandlerTest extends AbstractConnectHandlerTest
OutputStream output = socket.getOutputStream();
BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
- output.write(request.getBytes("UTF-8"));
+ output.write(request.getBytes(StandardCharsets.UTF_8));
output.flush();
// Expect 200 OK from the CONNECT request
@@ -727,7 +728,7 @@ public class ConnectHandlerTest extends AbstractConnectHandlerTest
"GET /echo" + " HTTP/1.1\r\n" +
"Host: " + hostPort + "\r\n" +
"\r\n";
- output.write(request.getBytes("UTF-8"));
+ output.write(request.getBytes(StandardCharsets.UTF_8));
output.flush();
socket.shutdownOutput();
diff --git a/jetty-rewrite/src/test/java/org/eclipse/jetty/rewrite/handler/RewriteRegexRuleTest.java b/jetty-rewrite/src/test/java/org/eclipse/jetty/rewrite/handler/RewriteRegexRuleTest.java
index e3dfe5c..58357fd 100644
--- a/jetty-rewrite/src/test/java/org/eclipse/jetty/rewrite/handler/RewriteRegexRuleTest.java
+++ b/jetty-rewrite/src/test/java/org/eclipse/jetty/rewrite/handler/RewriteRegexRuleTest.java
@@ -21,6 +21,7 @@ package org.eclipse.jetty.rewrite.handler;
import static org.junit.Assert.assertEquals;
import java.io.IOException;
+import java.nio.charset.StandardCharsets;
import org.eclipse.jetty.http.HttpURI;
import org.eclipse.jetty.util.MultiMap;
@@ -87,7 +88,7 @@ public class RewriteRegexRuleTest extends AbstractRuleTestCase
if (test[5]!=null)
{
MultiMap<String> params=new MultiMap<String>();
- UrlEncoded.decodeTo(test[5],params,StringUtil.__UTF8_CHARSET,-1);
+ UrlEncoded.decodeTo(test[5],params, StandardCharsets.UTF_8,-1);
for (String n:params.keySet())
assertEquals(params.getString(n),_request.getParameter(n));
diff --git a/jetty-security/src/main/java/org/eclipse/jetty/security/authentication/BasicAuthenticator.java b/jetty-security/src/main/java/org/eclipse/jetty/security/authentication/BasicAuthenticator.java
index 56d3fe4..4eeeec8 100644
--- a/jetty-security/src/main/java/org/eclipse/jetty/security/authentication/BasicAuthenticator.java
+++ b/jetty-security/src/main/java/org/eclipse/jetty/security/authentication/BasicAuthenticator.java
@@ -19,6 +19,7 @@
package org.eclipse.jetty.security.authentication;
import java.io.IOException;
+import java.nio.charset.StandardCharsets;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
@@ -82,7 +83,7 @@ public class BasicAuthenticator extends LoginAuthenticator
if ("basic".equalsIgnoreCase(method))
{
credentials = credentials.substring(space+1);
- credentials = B64Code.decode(credentials,StringUtil.__ISO_8859_1);
+ credentials = B64Code.decode(credentials, StandardCharsets.ISO_8859_1);
int i = credentials.indexOf(':');
if (i>0)
{
diff --git a/jetty-security/src/main/java/org/eclipse/jetty/security/authentication/DigestAuthenticator.java b/jetty-security/src/main/java/org/eclipse/jetty/security/authentication/DigestAuthenticator.java
index 0fe3747..49f924a 100644
--- a/jetty-security/src/main/java/org/eclipse/jetty/security/authentication/DigestAuthenticator.java
+++ b/jetty-security/src/main/java/org/eclipse/jetty/security/authentication/DigestAuthenticator.java
@@ -19,6 +19,7 @@
package org.eclipse.jetty.security.authentication;
import java.io.IOException;
+import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.security.SecureRandom;
import java.util.BitSet;
@@ -367,18 +368,18 @@ public class DigestAuthenticator extends LoginAuthenticator
else
{
// calc A1 digest
- md.update(username.getBytes(StringUtil.__ISO_8859_1));
+ md.update(username.getBytes(StandardCharsets.ISO_8859_1));
md.update((byte) ':');
- md.update(realm.getBytes(StringUtil.__ISO_8859_1));
+ md.update(realm.getBytes(StandardCharsets.ISO_8859_1));
md.update((byte) ':');
- md.update(password.getBytes(StringUtil.__ISO_8859_1));
+ md.update(password.getBytes(StandardCharsets.ISO_8859_1));
ha1 = md.digest();
}
// calc A2 digest
md.reset();
- md.update(method.getBytes(StringUtil.__ISO_8859_1));
+ md.update(method.getBytes(StandardCharsets.ISO_8859_1));
md.update((byte) ':');
- md.update(uri.getBytes(StringUtil.__ISO_8859_1));
+ md.update(uri.getBytes(StandardCharsets.ISO_8859_1));
byte[] ha2 = md.digest();
// calc digest
@@ -388,17 +389,17 @@ public class DigestAuthenticator extends LoginAuthenticator
// request-digest = <"> < KD ( H(A1), unq(nonce-value) ":" H(A2)
// ) > <">
- md.update(TypeUtil.toString(ha1, 16).getBytes(StringUtil.__ISO_8859_1));
+ md.update(TypeUtil.toString(ha1, 16).getBytes(StandardCharsets.ISO_8859_1));
md.update((byte) ':');
- md.update(nonce.getBytes(StringUtil.__ISO_8859_1));
+ md.update(nonce.getBytes(StandardCharsets.ISO_8859_1));
md.update((byte) ':');
- md.update(nc.getBytes(StringUtil.__ISO_8859_1));
+ md.update(nc.getBytes(StandardCharsets.ISO_8859_1));
md.update((byte) ':');
- md.update(cnonce.getBytes(StringUtil.__ISO_8859_1));
+ md.update(cnonce.getBytes(StandardCharsets.ISO_8859_1));
md.update((byte) ':');
- md.update(qop.getBytes(StringUtil.__ISO_8859_1));
+ md.update(qop.getBytes(StandardCharsets.ISO_8859_1));
md.update((byte) ':');
- md.update(TypeUtil.toString(ha2, 16).getBytes(StringUtil.__ISO_8859_1));
+ md.update(TypeUtil.toString(ha2, 16).getBytes(StandardCharsets.ISO_8859_1));
byte[] digest = md.digest();
// check digest
diff --git a/jetty-security/src/test/java/org/eclipse/jetty/security/ConstraintTest.java b/jetty-security/src/test/java/org/eclipse/jetty/security/ConstraintTest.java
index a1480b4..8b211fb 100644
--- a/jetty-security/src/test/java/org/eclipse/jetty/security/ConstraintTest.java
+++ b/jetty-security/src/test/java/org/eclipse/jetty/security/ConstraintTest.java
@@ -25,6 +25,7 @@ import static org.junit.Assert.assertTrue;
import static org.junit.matchers.JUnitMatchers.containsString;
import java.io.IOException;
+import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.util.ArrayList;
import java.util.Arrays;
@@ -334,17 +335,17 @@ public class ConstraintTest
MessageDigest md = MessageDigest.getInstance("MD5");
byte[] ha1;
// calc A1 digest
- md.update(username.getBytes(StringUtil.__ISO_8859_1));
+ md.update(username.getBytes(StandardCharsets.ISO_8859_1));
md.update((byte) ':');
- md.update("TestRealm".getBytes(StringUtil.__ISO_8859_1));
+ md.update("TestRealm".getBytes(StandardCharsets.ISO_8859_1));
md.update((byte) ':');
- md.update(password.getBytes(StringUtil.__ISO_8859_1));
+ md.update(password.getBytes(StandardCharsets.ISO_8859_1));
ha1 = md.digest();
// calc A2 digest
md.reset();
- md.update("GET".getBytes(StringUtil.__ISO_8859_1));
+ md.update("GET".getBytes(StandardCharsets.ISO_8859_1));
md.update((byte) ':');
- md.update(uri.getBytes(StringUtil.__ISO_8859_1));
+ md.update(uri.getBytes(StandardCharsets.ISO_8859_1));
byte[] ha2 = md.digest();
// calc digest
@@ -354,17 +355,17 @@ public class ConstraintTest
// request-digest = <"> < KD ( H(A1), unq(nonce-value) ":" H(A2)
// ) > <">
- md.update(TypeUtil.toString(ha1, 16).getBytes(StringUtil.__ISO_8859_1));
+ md.update(TypeUtil.toString(ha1, 16).getBytes(StandardCharsets.ISO_8859_1));
md.update((byte) ':');
- md.update(nonce.getBytes(StringUtil.__ISO_8859_1));
+ md.update(nonce.getBytes(StandardCharsets.ISO_8859_1));
md.update((byte) ':');
- md.update(nc.getBytes(StringUtil.__ISO_8859_1));
+ md.update(nc.getBytes(StandardCharsets.ISO_8859_1));
md.update((byte) ':');
- md.update(CNONCE.getBytes(StringUtil.__ISO_8859_1));
+ md.update(CNONCE.getBytes(StandardCharsets.ISO_8859_1));
md.update((byte) ':');
- md.update("auth".getBytes(StringUtil.__ISO_8859_1));
+ md.update("auth".getBytes(StandardCharsets.ISO_8859_1));
md.update((byte) ':');
- md.update(TypeUtil.toString(ha2, 16).getBytes(StringUtil.__ISO_8859_1));
+ md.update(TypeUtil.toString(ha2, 16).getBytes(StandardCharsets.ISO_8859_1));
byte[] digest = md.digest();
// check digest
diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/HttpChannel.java b/jetty-server/src/main/java/org/eclipse/jetty/server/HttpChannel.java
index 47ab433..d44710f 100644
--- a/jetty-server/src/main/java/org/eclipse/jetty/server/HttpChannel.java
+++ b/jetty-server/src/main/java/org/eclipse/jetty/server/HttpChannel.java
@@ -22,6 +22,7 @@ import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.ByteBuffer;
import java.nio.channels.ClosedChannelException;
+import java.nio.charset.StandardCharsets;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
@@ -451,7 +452,7 @@ public class HttpChannel<T> implements HttpParser.RequestHandler<T>, Runnable
{
LOG.warn("Failed UTF-8 decode for request path, trying ISO-8859-1");
LOG.ignore(e);
- path = _uri.getDecodedPath(StringUtil.__ISO_8859_1);
+ path = _uri.getDecodedPath(StandardCharsets.ISO_8859_1);
}
String info = URIUtil.canonicalPath(path);
diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/LocalConnector.java b/jetty-server/src/main/java/org/eclipse/jetty/server/LocalConnector.java
index 6d161de..ffdb5b9 100644
--- a/jetty-server/src/main/java/org/eclipse/jetty/server/LocalConnector.java
+++ b/jetty-server/src/main/java/org/eclipse/jetty/server/LocalConnector.java
@@ -20,6 +20,7 @@ package org.eclipse.jetty.server;
import java.io.IOException;
import java.nio.ByteBuffer;
+import java.nio.charset.StandardCharsets;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.Executor;
@@ -100,8 +101,8 @@ public class LocalConnector extends AbstractConnector
*/
public String getResponses(String requests,long idleFor,TimeUnit units) throws Exception
{
- ByteBuffer result = getResponses(BufferUtil.toBuffer(requests,StringUtil.__UTF8_CHARSET),idleFor,units);
- return result==null?null:BufferUtil.toString(result,StringUtil.__UTF8_CHARSET);
+ ByteBuffer result = getResponses(BufferUtil.toBuffer(requests,StandardCharsets.UTF_8),idleFor,units);
+ return result==null?null:BufferUtil.toString(result,StandardCharsets.UTF_8);
}
/** Sends requests and get's responses based on thread activity.
@@ -150,7 +151,7 @@ public class LocalConnector extends AbstractConnector
*/
public LocalEndPoint executeRequest(String rawRequest)
{
- return executeRequest(BufferUtil.toBuffer(rawRequest,StringUtil.__UTF8_CHARSET));
+ return executeRequest(BufferUtil.toBuffer(rawRequest, StandardCharsets.UTF_8));
}
private LocalEndPoint executeRequest(ByteBuffer rawRequest)
@@ -191,7 +192,7 @@ public class LocalConnector extends AbstractConnector
// TODO this is a busy wait
while(getIn()==null || BufferUtil.hasContent(getIn()))
Thread.yield();
- setInput(BufferUtil.toBuffer(s, StringUtil.__UTF8_CHARSET));
+ setInput(BufferUtil.toBuffer(s, StandardCharsets.UTF_8));
}
@Override
diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/Request.java b/jetty-server/src/main/java/org/eclipse/jetty/server/Request.java
index f2cfe17..5283fbf 100644
--- a/jetty-server/src/main/java/org/eclipse/jetty/server/Request.java
+++ b/jetty-server/src/main/java/org/eclipse/jetty/server/Request.java
@@ -28,6 +28,7 @@ import java.io.UnsupportedEncodingException;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
import java.nio.charset.UnsupportedCharsetException;
import java.security.Principal;
import java.util.ArrayList;
@@ -1853,7 +1854,7 @@ public class Request implements HttpServletRequest
/* ------------------------------------------------------------ */
/**
* Set the character encoding used for the query string. This call will effect the return of getQueryString and getParamaters. It must be called before any
- * geParameter methods.
+ * getParameter methods.
*
* The request attribute "org.eclipse.jetty.server.server.Request.queryEncoding" may be set as an alternate method of calling setQueryEncoding.
*
@@ -2080,6 +2081,7 @@ public class Request implements HttpServletRequest
setAttribute(__MULTIPART_INPUT_STREAM, _multiPartInputStream);
setAttribute(__MULTIPART_CONTEXT, _context);
Collection<Part> parts = _multiPartInputStream.getParts(); //causes parsing
+ ByteArrayOutputStream os = null;
for (Part p:parts)
{
MultiPartInputStreamParser.MultiPart mp = (MultiPartInputStreamParser.MultiPart)p;
@@ -2090,21 +2092,17 @@ public class Request implements HttpServletRequest
if (mp.getContentType() != null)
charset = MimeTypes.getCharsetFromContentType(mp.getContentType());
- ByteArrayOutputStream os = null;
- InputStream is = mp.getInputStream(); //get the bytes regardless of being in memory or in temp file
- try
+ //get the bytes regardless of being in memory or in temp file
+ try (InputStream is = mp.getInputStream())
{
- os = new ByteArrayOutputStream();
+ if (os == null)
+ os = new ByteArrayOutputStream();
IO.copy(is, os);
- String content=new String(os.toByteArray(),charset==null?StringUtil.__UTF8:charset);
+ String content=new String(os.toByteArray(),charset==null?StandardCharsets.UTF_8:Charset.forName(charset));
getParameter(""); //cause params to be evaluated
getParameters().add(mp.getName(), content);
}
- finally
- {
- IO.close(os);
- IO.close(is);
- }
+ os.reset();
}
}
}
@@ -2149,7 +2147,7 @@ public class Request implements HttpServletRequest
{
// extract parameters from dispatch query
MultiMap<String> parameters = new MultiMap<>();
- UrlEncoded.decodeTo(query,parameters, StringUtil.__UTF8_CHARSET,-1); //have to assume UTF-8 because we can't know otherwise
+ UrlEncoded.decodeTo(query,parameters, StandardCharsets.UTF_8,-1); //have to assume UTF-8 because we can't know otherwise
boolean merge_old_query = false;
@@ -2174,7 +2172,7 @@ public class Request implements HttpServletRequest
MultiMap<String> overridden_new_query = new MultiMap<>();
- UrlEncoded.decodeTo(query,overridden_new_query,StringUtil.__UTF8_CHARSET,-1); //have to assume utf8 as we cannot know otherwise
+ UrlEncoded.decodeTo(query,overridden_new_query,StandardCharsets.UTF_8,-1); //have to assume utf8 as we cannot know otherwise
for(String name: overridden_old_query.keySet())
{
diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/ShutdownMonitor.java b/jetty-server/src/main/java/org/eclipse/jetty/server/ShutdownMonitor.java
index ded5bdc..5e590dd 100644
--- a/jetty-server/src/main/java/org/eclipse/jetty/server/ShutdownMonitor.java
+++ b/jetty-server/src/main/java/org/eclipse/jetty/server/ShutdownMonitor.java
@@ -25,6 +25,7 @@ import java.io.OutputStream;
import java.net.InetAddress;
import java.net.ServerSocket;
import java.net.Socket;
+import java.nio.charset.StandardCharsets;
import java.util.Properties;
import org.eclipse.jetty.util.StringUtil;
@@ -112,7 +113,7 @@ public class ShutdownMonitor
// Reply to client
debug("Informing client that we are stopped.");
- out.write("Stopped\r\n".getBytes(StringUtil.__UTF8));
+ out.write("Stopped\r\n".getBytes(StandardCharsets.UTF_8));
out.flush();
// Shutdown Monitor
@@ -131,7 +132,7 @@ public class ShutdownMonitor
else if ("status".equals(cmd))
{
// Reply to client
- out.write("OK\r\n".getBytes(StringUtil.__UTF8));
+ out.write("OK\r\n".getBytes(StandardCharsets.UTF_8));
out.flush();
}
}
diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/AbstractHttpTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/AbstractHttpTest.java
index 323e16a..3a81922 100644
--- a/jetty-server/src/test/java/org/eclipse/jetty/server/AbstractHttpTest.java
+++ b/jetty-server/src/test/java/org/eclipse/jetty/server/AbstractHttpTest.java
@@ -28,6 +28,7 @@ import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.net.Socket;
import java.net.URISyntaxException;
+import java.nio.charset.StandardCharsets;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
@@ -75,7 +76,7 @@ public abstract class AbstractHttpTest
{
Socket socket = new Socket("localhost", connector.getLocalPort());
socket.setSoTimeout((int)connector.getIdleTimeout());
- BufferedReader reader = new BufferedReader(new InputStreamReader(socket.getInputStream(), "UTF-8"));
+ BufferedReader reader = new BufferedReader(new InputStreamReader(socket.getInputStream(), StandardCharsets.UTF_8));
PrintWriter writer = new PrintWriter(new OutputStreamWriter(socket.getOutputStream()));
String request = "GET / " + httpVersion + "\r\n";
diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/AsyncRequestReadTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/AsyncRequestReadTest.java
index a1b673d..f0ca3ac 100644
--- a/jetty-server/src/test/java/org/eclipse/jetty/server/AsyncRequestReadTest.java
+++ b/jetty-server/src/test/java/org/eclipse/jetty/server/AsyncRequestReadTest.java
@@ -30,6 +30,7 @@ import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.net.Socket;
+import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.Exchanger;
@@ -96,7 +97,7 @@ public class AsyncRequestReadTest
"Content-Length: "+content.length+"\r\n"+
"Content-Type: bytes\r\n"+
"\r\n";
- byte[] h=header.getBytes(StringUtil.__ISO_8859_1);
+ byte[] h=header.getBytes(StandardCharsets.ISO_8859_1);
out.write(h);
out.write(content);
@@ -108,7 +109,7 @@ public class AsyncRequestReadTest
"Content-Type: bytes\r\n"+
"Connection: close\r\n"+
"\r\n";
- h=header.getBytes(StringUtil.__ISO_8859_1);
+ h=header.getBytes(StandardCharsets.ISO_8859_1);
out.write(h);
out.write(content);
out.flush();
@@ -244,7 +245,7 @@ public class AsyncRequestReadTest
"Content-Length: "+content.length+"\r\n"+
"Content-Type: bytes\r\n"+
"\r\n";
- byte[] h=header.getBytes(StringUtil.__ISO_8859_1);
+ byte[] h=header.getBytes(StandardCharsets.ISO_8859_1);
out.write(h);
out.write(content);
@@ -254,7 +255,7 @@ public class AsyncRequestReadTest
"Content-Type: bytes\r\n"+
"Connection: close\r\n"+
"\r\n";
- h=header.getBytes(StringUtil.__ISO_8859_1);
+ h=header.getBytes(StandardCharsets.ISO_8859_1);
out.write(h);
out.write(content);
out.flush();
@@ -294,7 +295,7 @@ public class AsyncRequestReadTest
"Content-Length: "+content.length+"\r\n"+
"Content-Type: bytes\r\n"+
"\r\n";
- byte[] h=header.getBytes(StringUtil.__ISO_8859_1);
+ byte[] h=header.getBytes(StandardCharsets.ISO_8859_1);
out.write(h);
out.write(content,0,4096);
out.flush();
@@ -329,7 +330,7 @@ public class AsyncRequestReadTest
"Content-Length: "+content.length+"\r\n"+
"Content-Type: bytes\r\n"+
"\r\n";
- byte[] h=header.getBytes(StringUtil.__ISO_8859_1);
+ byte[] h=header.getBytes(StandardCharsets.ISO_8859_1);
out.write(h);
out.write(content,0,4096);
out.flush();
diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/AsyncStressTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/AsyncStressTest.java
index 00358ca..ec929a3 100644
--- a/jetty-server/src/test/java/org/eclipse/jetty/server/AsyncStressTest.java
+++ b/jetty-server/src/test/java/org/eclipse/jetty/server/AsyncStressTest.java
@@ -24,6 +24,7 @@ import java.io.IOException;
import java.io.InputStream;
import java.net.InetAddress;
import java.net.Socket;
+import java.nio.charset.StandardCharsets;
import java.util.Random;
import java.util.Timer;
import java.util.TimerTask;
@@ -140,7 +141,7 @@ public class AsyncStressTest
"result: "+__paths[p][1]+"\r\n"+
((l+1<loops)?"":"Connection: close\r\n")+
"\r\n";
- socket[i].getOutputStream().write(request.getBytes("UTF-8"));
+ socket[i].getOutputStream().write(request.getBytes(StandardCharsets.UTF_8));
socket[i].getOutputStream().flush();
}
if (l%80==0)
@@ -155,7 +156,7 @@ public class AsyncStressTest
String[] results=new String[connections];
for (int i=0;i<connections;i++)
{
- results[i]=IO.toString(socket[i].getInputStream(),"UTF-8");
+ results[i]=IO.toString(socket[i].getInputStream(),StandardCharsets.UTF_8);
if (i%80==0)
System.err.println();
System.err.print('-');
diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/ConnectionOpenCloseTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/ConnectionOpenCloseTest.java
index 51d1326..ceabcf0 100644
--- a/jetty-server/src/test/java/org/eclipse/jetty/server/ConnectionOpenCloseTest.java
+++ b/jetty-server/src/test/java/org/eclipse/jetty/server/ConnectionOpenCloseTest.java
@@ -24,6 +24,7 @@ import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.Socket;
+import java.nio.charset.StandardCharsets;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
@@ -91,7 +92,7 @@ public class ConnectionOpenCloseTest extends AbstractHttpTest
"GET / HTTP/1.1\r\n" +
"Host: localhost:" + connector.getLocalPort() + "\r\n" +
"Connection: close\r\n" +
- "\r\n").getBytes("UTF-8"));
+ "\r\n").getBytes(StandardCharsets.UTF_8));
output.flush();
BufferedReader reader = new BufferedReader(new InputStreamReader(socket.getInputStream()));
@@ -162,7 +163,7 @@ public class ConnectionOpenCloseTest extends AbstractHttpTest
"GET / HTTP/1.1\r\n" +
"Host: localhost:" + connector.getLocalPort() + "\r\n" +
"Connection: close\r\n" +
- "\r\n").getBytes("UTF-8"));
+ "\r\n").getBytes(StandardCharsets.UTF_8));
output.flush();
BufferedReader reader = new BufferedReader(new InputStreamReader(socket.getInputStream()));
diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/DumpHandler.java b/jetty-server/src/test/java/org/eclipse/jetty/server/DumpHandler.java
index 0f86e01..69720d9 100644
--- a/jetty-server/src/test/java/org/eclipse/jetty/server/DumpHandler.java
+++ b/jetty-server/src/test/java/org/eclipse/jetty/server/DumpHandler.java
@@ -24,6 +24,7 @@ import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.Reader;
import java.io.Writer;
+import java.nio.charset.StandardCharsets;
import java.util.Enumeration;
import javax.servlet.ServletException;
@@ -97,7 +98,7 @@ public class DumpHandler extends AbstractHandler
OutputStream out = response.getOutputStream();
ByteArrayOutputStream buf = new ByteArrayOutputStream(2048);
- Writer writer = new OutputStreamWriter(buf,StringUtil.__ISO_8859_1);
+ Writer writer = new OutputStreamWriter(buf,StandardCharsets.ISO_8859_1);
writer.write("<html><h1>"+label+"</h1>");
writer.write("<pre>\npathInfo="+request.getPathInfo()+"\n</pre>\n");
writer.write("<pre>\ncontentType="+request.getContentType()+"\n</pre>\n");
diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/GracefulStopTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/GracefulStopTest.java
index 0c11502..37021b5 100644
--- a/jetty-server/src/test/java/org/eclipse/jetty/server/GracefulStopTest.java
+++ b/jetty-server/src/test/java/org/eclipse/jetty/server/GracefulStopTest.java
@@ -20,6 +20,7 @@ package org.eclipse.jetty.server;
import java.io.IOException;
import java.net.Socket;
+import java.nio.charset.StandardCharsets;
import java.util.concurrent.TimeUnit;
import javax.servlet.ServletException;
@@ -76,7 +77,7 @@ public class GracefulStopTest
try(Socket socket = new Socket("localhost",server.getBean(NetworkConnector.class).getLocalPort());)
{
- socket.getOutputStream().write("GET / HTTP/1.0\r\n\r\n".getBytes(StringUtil.__ISO_8859_1_CHARSET));
+ socket.getOutputStream().write("GET / HTTP/1.0\r\n\r\n".getBytes(StandardCharsets.ISO_8859_1));
String out = IO.toString(socket.getInputStream());
Assert.assertThat(out,Matchers.containsString("200 OK"));
}
diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/HostHeaderCustomizerTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/HostHeaderCustomizerTest.java
index 666ebfb..56bd076 100644
--- a/jetty-server/src/test/java/org/eclipse/jetty/server/HostHeaderCustomizerTest.java
+++ b/jetty-server/src/test/java/org/eclipse/jetty/server/HostHeaderCustomizerTest.java
@@ -23,6 +23,7 @@ import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.Socket;
+import java.nio.charset.StandardCharsets;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@@ -71,10 +72,10 @@ public class HostHeaderCustomizerTest
String request = "" +
"GET / HTTP/1.0\r\n" +
"\r\n";
- output.write(request.getBytes("UTF-8"));
+ output.write(request.getBytes(StandardCharsets.UTF_8));
output.flush();
- BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream(), "UTF-8"));
+ BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream(), StandardCharsets.UTF_8));
SimpleHttpParser parser = new SimpleHttpParser();
SimpleHttpResponse response = parser.readResponse(input);
diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/HttpServerTestBase.java b/jetty-server/src/test/java/org/eclipse/jetty/server/HttpServerTestBase.java
index a549d3b..075e632 100644
--- a/jetty-server/src/test/java/org/eclipse/jetty/server/HttpServerTestBase.java
+++ b/jetty-server/src/test/java/org/eclipse/jetty/server/HttpServerTestBase.java
@@ -37,6 +37,7 @@ import java.io.OutputStream;
import java.net.Socket;
import java.net.URI;
import java.net.URL;
+import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.Random;
import java.util.concurrent.CountDownLatch;
@@ -966,12 +967,12 @@ public abstract class HttpServerTestBase extends HttpServerTestFixture
}
}
- String in = new String(b, 0, i, "utf-8");
+ String in = new String(b, 0, i, StandardCharsets.UTF_8);
assertTrue(in.contains("123456789"));
assertTrue(in.contains("abcdefghZ"));
assertFalse(in.contains("Wibble"));
- in = new String(b, i, b.length - i, "utf-16");
+ in = new String(b, i, b.length - i, StandardCharsets.UTF_16);
assertEquals("Wibble\n", in);
}
}
@@ -1416,11 +1417,11 @@ public abstract class HttpServerTestBase extends HttpServerTestFixture
{
for (int i = 0; i < REQS; i++)
{
- out.write("GET / HTTP/1.1\r\nHost: localhost\r\n".getBytes(StringUtil.__ISO_8859_1));
- out.write(("Content-Length: " + bytes.length + "\r\n" + "\r\n").getBytes(StringUtil.__ISO_8859_1));
+ out.write("GET / HTTP/1.1\r\nHost: localhost\r\n".getBytes(StandardCharsets.ISO_8859_1));
+ out.write(("Content-Length: " + bytes.length + "\r\n" + "\r\n").getBytes(StandardCharsets.ISO_8859_1));
out.write(bytes, 0, bytes.length);
}
- out.write("GET / HTTP/1.1\r\nHost: last\r\nConnection: close\r\n\r\n".getBytes(StringUtil.__ISO_8859_1));
+ out.write("GET / HTTP/1.1\r\nHost: last\r\nConnection: close\r\n\r\n".getBytes(StandardCharsets.ISO_8859_1));
out.flush();
}
catch (Exception e)
diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/HttpURITest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/HttpURITest.java
index 05958cc..bcb92ca 100644
--- a/jetty-server/src/test/java/org/eclipse/jetty/server/HttpURITest.java
+++ b/jetty-server/src/test/java/org/eclipse/jetty/server/HttpURITest.java
@@ -28,6 +28,7 @@ import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
import org.eclipse.jetty.http.HttpURI;
import org.eclipse.jetty.util.MultiMap;
@@ -330,7 +331,7 @@ public class HttpURITest
huri=new HttpURI(uri);
params = new MultiMap<>();
- huri.decodeQueryTo(params,"UTF-8");
+ huri.decodeQueryTo(params,StandardCharsets.UTF_8);
assertEquals("data"+Utf8Appendable.REPLACEMENT+"here"+Utf8Appendable.REPLACEMENT,params.getValue("invalid",0));
}
@@ -343,7 +344,7 @@ public class HttpURITest
HttpURI uri = new HttpURI("/path?value="+URLEncoder.encode(value,"UTF-8"));
MultiMap<String> parameters = new MultiMap<>();
- uri.decodeQueryTo(parameters,"UTF-8");
+ uri.decodeQueryTo(parameters,StandardCharsets.UTF_8);
assertEquals(value,parameters.getString("value"));
}
}
@@ -366,7 +367,7 @@ public class HttpURITest
{
try
{
- byte[] buf = connect_tests[i][0].getBytes(StringUtil.__UTF8);
+ byte[] buf = connect_tests[i][0].getBytes(StandardCharsets.UTF_8);
uri.parseConnect(buf,2,buf.length-4);
assertEquals("path"+i,connect_tests[i][0].trim(),uri.getPath());
@@ -384,13 +385,13 @@ public class HttpURITest
public void testNonURIAscii() throws Exception
{
String url = "http://www.foo.com/ma\u00F1ana";
- byte[] asISO = url.getBytes("ISO-8859-1");
- new String(asISO, "ISO-8859-1");
+ byte[] asISO = url.getBytes(StandardCharsets.ISO_8859_1);
+ new String(asISO, StandardCharsets.ISO_8859_1);
//use a non UTF-8 charset as the encoding and url-escape as per
//http://www.w3.org/TR/html40/appendix/notes.html#non-ascii-chars
String s = URLEncoder.encode(url, "ISO-8859-1");
- HttpURI uri = new HttpURI(Charset.forName("ISO-8859-1"));
+ HttpURI uri = new HttpURI(StandardCharsets.ISO_8859_1);
//parse it, using the same encoding
uri.parse(s);
diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/HttpWriterTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/HttpWriterTest.java
index 1b30841..fea92eb 100644
--- a/jetty-server/src/test/java/org/eclipse/jetty/server/HttpWriterTest.java
+++ b/jetty-server/src/test/java/org/eclipse/jetty/server/HttpWriterTest.java
@@ -22,6 +22,7 @@ import static org.junit.Assert.assertEquals;
import java.io.IOException;
import java.nio.ByteBuffer;
+import java.nio.charset.StandardCharsets;
import org.eclipse.jetty.io.ByteBufferPool;
import org.eclipse.jetty.io.MappedByteBufferPool;
@@ -67,7 +68,7 @@ public class HttpWriterTest
{
HttpWriter _writer = new Utf8HttpWriter(_httpOut);
_writer.write("Now is the time");
- assertArrayEquals("Now is the time".getBytes(StringUtil.__UTF8),BufferUtil.toArray(_bytes));
+ assertArrayEquals("Now is the time".getBytes(StandardCharsets.UTF_8),BufferUtil.toArray(_bytes));
}
@Test
@@ -75,7 +76,7 @@ public class HttpWriterTest
{
HttpWriter _writer = new Utf8HttpWriter(_httpOut);
_writer.write("How now \uFF22rown cow");
- assertArrayEquals("How now \uFF22rown cow".getBytes(StringUtil.__UTF8),BufferUtil.toArray(_bytes));
+ assertArrayEquals("How now \uFF22rown cow".getBytes(StandardCharsets.UTF_8),BufferUtil.toArray(_bytes));
}
@Test
@@ -83,7 +84,7 @@ public class HttpWriterTest
{
HttpWriter _writer = new EncodingHttpWriter(_httpOut,StringUtil.__UTF16);
_writer.write("How now \uFF22rown cow");
- assertArrayEquals("How now \uFF22rown cow".getBytes(StringUtil.__UTF16),BufferUtil.toArray(_bytes));
+ assertArrayEquals("How now \uFF22rown cow".getBytes(StandardCharsets.UTF_16),BufferUtil.toArray(_bytes));
}
@Test
@@ -93,7 +94,7 @@ public class HttpWriterTest
String data="xxx\uD801\uDC00xxx";
_writer.write(data);
assertEquals("787878F0909080787878",TypeUtil.toHexString(BufferUtil.toArray(_bytes)));
- assertArrayEquals(data.getBytes(StringUtil.__UTF8),BufferUtil.toArray(_bytes));
+ assertArrayEquals(data.getBytes(StandardCharsets.UTF_8),BufferUtil.toArray(_bytes));
assertEquals(3+4+3,_bytes.remaining());
Utf8StringBuilder buf = new Utf8StringBuilder();
@@ -109,7 +110,7 @@ public class HttpWriterTest
final String multiByteDuplicateStr = "\uFF22";
int remainSize = 1;
- int multiByteStrByteLength = multiByteDuplicateStr.getBytes("UTF-8").length;
+ int multiByteStrByteLength = multiByteDuplicateStr.getBytes(StandardCharsets.UTF_8).length;
StringBuilder sb = new StringBuilder();
for (int i = 0; i < HttpWriter.MAX_OUTPUT_CHARS - multiByteStrByteLength; i++) {
sb.append(singleByteStr);
@@ -125,7 +126,7 @@ public class HttpWriterTest
_writer.write(buf, 0, length);
- assertEquals(sb.toString(),new String(BufferUtil.toArray(_bytes),StringUtil.__UTF8));
+ assertEquals(sb.toString(),new String(BufferUtil.toArray(_bytes),StandardCharsets.UTF_8));
}
@Test
@@ -133,7 +134,7 @@ public class HttpWriterTest
{
HttpWriter _writer = new Iso88591HttpWriter(_httpOut);
_writer.write("How now \uFF22rown cow");
- assertEquals("How now ?rown cow",new String(BufferUtil.toArray(_bytes),StringUtil.__ISO_8859_1));
+ assertEquals("How now ?rown cow",new String(BufferUtil.toArray(_bytes),StandardCharsets.ISO_8859_1));
}
@Test
@@ -143,11 +144,11 @@ public class HttpWriterTest
String source = "\uD842\uDF9F";
- byte[] bytes = source.getBytes(StringUtil.__UTF8);
+ byte[] bytes = source.getBytes(StandardCharsets.UTF_8);
_writer.write(source.toCharArray(),0,source.toCharArray().length);
java.io.ByteArrayOutputStream baos = new java.io.ByteArrayOutputStream();
- java.io.OutputStreamWriter osw = new java.io.OutputStreamWriter(baos ,StringUtil.__UTF8 );
+ java.io.OutputStreamWriter osw = new java.io.OutputStreamWriter(baos, StandardCharsets.UTF_8);
osw.write(source.toCharArray(),0,source.toCharArray().length);
osw.flush();
@@ -181,11 +182,11 @@ public class HttpWriterTest
}
String source = sb.toString();
- byte[] bytes = source.getBytes(StringUtil.__UTF8);
+ byte[] bytes = source.getBytes(StandardCharsets.UTF_8);
_writer.write(source.toCharArray(),0,source.toCharArray().length);
java.io.ByteArrayOutputStream baos = new java.io.ByteArrayOutputStream();
- java.io.OutputStreamWriter osw = new java.io.OutputStreamWriter(baos ,StringUtil.__UTF8);
+ java.io.OutputStreamWriter osw = new java.io.OutputStreamWriter(baos, StandardCharsets.UTF_8);
osw.write(source.toCharArray(),0,source.toCharArray().length);
osw.flush();
@@ -219,11 +220,11 @@ public class HttpWriterTest
}
String source = sb.toString();
- byte[] bytes = source.getBytes(StringUtil.__UTF8);
+ byte[] bytes = source.getBytes(StandardCharsets.UTF_8);
_writer.write(source.toCharArray(),0,source.toCharArray().length);
java.io.ByteArrayOutputStream baos = new java.io.ByteArrayOutputStream();
- java.io.OutputStreamWriter osw = new java.io.OutputStreamWriter(baos,StringUtil.__UTF8);
+ java.io.OutputStreamWriter osw = new java.io.OutputStreamWriter(baos,StandardCharsets.UTF_8);
osw.write(source.toCharArray(),0,source.toCharArray().length);
osw.flush();
diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/LowResourcesMonitorTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/LowResourcesMonitorTest.java
index eac1057..b3695ba 100644
--- a/jetty-server/src/test/java/org/eclipse/jetty/server/LowResourcesMonitorTest.java
+++ b/jetty-server/src/test/java/org/eclipse/jetty/server/LowResourcesMonitorTest.java
@@ -24,6 +24,7 @@ import static org.hamcrest.Matchers.not;
import static org.junit.Assert.assertThat;
import java.net.Socket;
+import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.concurrent.CountDownLatch;
@@ -161,7 +162,7 @@ public class LowResourcesMonitorTest
for (int i=0;i<socket.length;i++)
Assert.assertEquals(-1,socket[i].getInputStream().read());
- newSocket.getOutputStream().write("GET / HTTP/1.0\r\n\r\n".getBytes(StringUtil.__UTF8_CHARSET));
+ newSocket.getOutputStream().write("GET / HTTP/1.0\r\n\r\n".getBytes(StandardCharsets.UTF_8));
Assert.assertEquals('H',newSocket.getInputStream().read());
}
@@ -183,11 +184,11 @@ public class LowResourcesMonitorTest
Thread.sleep(1200);
Assert.assertTrue(_lowResourcesMonitor.isLowOnResources());
Assert.assertEquals(-1,socket0.getInputStream().read());
- socket1.getOutputStream().write("G".getBytes(StringUtil.__UTF8_CHARSET));
+ socket1.getOutputStream().write("G".getBytes(StandardCharsets.UTF_8));
Thread.sleep(1200);
Assert.assertTrue(_lowResourcesMonitor.isLowOnResources());
- socket1.getOutputStream().write("E".getBytes(StringUtil.__UTF8_CHARSET));
+ socket1.getOutputStream().write("E".getBytes(StandardCharsets.UTF_8));
Thread.sleep(1200);
Assert.assertTrue(_lowResourcesMonitor.isLowOnResources());
diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/NetworkTrafficListenerTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/NetworkTrafficListenerTest.java
index 1f50727..dbd9976 100644
--- a/jetty-server/src/test/java/org/eclipse/jetty/server/NetworkTrafficListenerTest.java
+++ b/jetty-server/src/test/java/org/eclipse/jetty/server/NetworkTrafficListenerTest.java
@@ -27,6 +27,7 @@ import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;
import java.nio.ByteBuffer;
+import java.nio.charset.StandardCharsets;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;
@@ -130,14 +131,14 @@ public class NetworkTrafficListenerTest
@Override
public void incoming(Socket socket, ByteBuffer bytes)
{
- incomingData.set(BufferUtil.toString(bytes,StringUtil.__UTF8_CHARSET));
+ incomingData.set(BufferUtil.toString(bytes,StandardCharsets.UTF_8));
incomingLatch.countDown();
}
@Override
public void outgoing(Socket socket, ByteBuffer bytes)
{
- outgoingData.set(outgoingData.get() + BufferUtil.toString(bytes,StringUtil.__UTF8_CHARSET));
+ outgoingData.set(outgoingData.get() + BufferUtil.toString(bytes,StandardCharsets.UTF_8));
outgoingLatch.countDown();
}
});
@@ -155,7 +156,7 @@ public class NetworkTrafficListenerTest
Socket socket = new Socket("localhost", port);
OutputStream output = socket.getOutputStream();
- output.write(request.getBytes("UTF-8"));
+ output.write(request.getBytes(StandardCharsets.UTF_8));
output.flush();
assertTrue(incomingLatch.await(1, TimeUnit.SECONDS));
@@ -165,7 +166,7 @@ public class NetworkTrafficListenerTest
assertEquals(expectedResponse, outgoingData.get());
byte[] responseBytes = readResponse(socket);
- String response = new String(responseBytes, "UTF-8");
+ String response = new String(responseBytes, StandardCharsets.UTF_8);
assertEquals(expectedResponse, response);
socket.close();
@@ -181,7 +182,7 @@ public class NetworkTrafficListenerTest
{
request.setHandled(true);
ServletOutputStream output = servletResponse.getOutputStream();
- output.write(responseContent.getBytes("UTF-8"));
+ output.write(responseContent.getBytes(StandardCharsets.UTF_8));
output.write(END_OF_CONTENT);
}
});
@@ -194,13 +195,13 @@ public class NetworkTrafficListenerTest
{
public void incoming(Socket socket, ByteBuffer bytes)
{
- incomingData.set(BufferUtil.toString(bytes,StringUtil.__UTF8_CHARSET));
+ incomingData.set(BufferUtil.toString(bytes,StandardCharsets.UTF_8));
incomingLatch.countDown();
}
public void outgoing(Socket socket, ByteBuffer bytes)
{
- outgoingData.set(outgoingData.get() + BufferUtil.toString(bytes,StringUtil.__UTF8_CHARSET));
+ outgoingData.set(outgoingData.get() + BufferUtil.toString(bytes,StandardCharsets.UTF_8));
outgoingLatch.countDown();
}
});
@@ -218,7 +219,7 @@ public class NetworkTrafficListenerTest
Socket socket = new Socket("localhost", port);
OutputStream output = socket.getOutputStream();
- output.write(request.getBytes("UTF-8"));
+ output.write(request.getBytes(StandardCharsets.UTF_8));
output.flush();
assertTrue(incomingLatch.await(1, TimeUnit.SECONDS));
@@ -228,7 +229,7 @@ public class NetworkTrafficListenerTest
assertEquals(expectedResponse, outgoingData.get());
byte[] responseBytes = readResponse(socket);
- String response = new String(responseBytes, "UTF-8");
+ String response = new String(responseBytes, StandardCharsets.UTF_8);
assertEquals(expectedResponse, response);
socket.close();
@@ -246,9 +247,9 @@ public class NetworkTrafficListenerTest
{
request.setHandled(true);
ServletOutputStream output = servletResponse.getOutputStream();
- output.write(responseChunk1.getBytes("UTF-8"));
+ output.write(responseChunk1.getBytes(StandardCharsets.UTF_8));
output.flush();
- output.write(responseChunk2.getBytes("UTF-8"));
+ output.write(responseChunk2.getBytes(StandardCharsets.UTF_8));
output.flush();
}
});
@@ -261,13 +262,13 @@ public class NetworkTrafficListenerTest
{
public void incoming(Socket socket, ByteBuffer bytes)
{
- incomingData.set(BufferUtil.toString(bytes,StringUtil.__UTF8_CHARSET));
+ incomingData.set(BufferUtil.toString(bytes,StandardCharsets.UTF_8));
incomingLatch.countDown();
}
public void outgoing(Socket socket, ByteBuffer bytes)
{
- outgoingData.set(outgoingData.get() + BufferUtil.toString(bytes,StringUtil.__UTF8_CHARSET));
+ outgoingData.set(outgoingData.get() + BufferUtil.toString(bytes,StandardCharsets.UTF_8));
outgoingLatch.countDown();
}
});
@@ -290,7 +291,7 @@ public class NetworkTrafficListenerTest
Socket socket = new Socket("localhost", port);
OutputStream output = socket.getOutputStream();
- output.write(request.getBytes("UTF-8"));
+ output.write(request.getBytes(StandardCharsets.UTF_8));
output.flush();
assertTrue(incomingLatch.await(1, TimeUnit.SECONDS));
@@ -300,7 +301,7 @@ public class NetworkTrafficListenerTest
assertEquals(expectedResponse, outgoingData.get());
byte[] responseBytes = readResponse(socket);
- String response = new String(responseBytes, "UTF-8");
+ String response = new String(responseBytes, StandardCharsets.UTF_8);
assertEquals(expectedResponse, response);
socket.close();
@@ -327,13 +328,13 @@ public class NetworkTrafficListenerTest
{
public void incoming(Socket socket, ByteBuffer bytes)
{
- incomingData.set(BufferUtil.toString(bytes,StringUtil.__UTF8_CHARSET));
+ incomingData.set(BufferUtil.toString(bytes,StandardCharsets.UTF_8));
incomingLatch.countDown();
}
public void outgoing(Socket socket, ByteBuffer bytes)
{
- outgoingData.set(outgoingData.get() + BufferUtil.toString(bytes,StringUtil.__UTF8_CHARSET));
+ outgoingData.set(outgoingData.get() + BufferUtil.toString(bytes,StandardCharsets.UTF_8));
outgoingLatch.countDown();
}
});
@@ -355,7 +356,7 @@ public class NetworkTrafficListenerTest
Socket socket = new Socket("localhost", port);
OutputStream output = socket.getOutputStream();
- output.write(request.getBytes("UTF-8"));
+ output.write(request.getBytes(StandardCharsets.UTF_8));
output.flush();
assertTrue(incomingLatch.await(1, TimeUnit.SECONDS));
@@ -365,7 +366,7 @@ public class NetworkTrafficListenerTest
assertEquals(expectedResponse, outgoingData.get());
byte[] responseBytes = readResponse(socket);
- String response = new String(responseBytes, "UTF-8");
+ String response = new String(responseBytes, StandardCharsets.UTF_8);
assertEquals(expectedResponse, response);
socket.close();
@@ -400,12 +401,12 @@ public class NetworkTrafficListenerTest
{
public void incoming(Socket socket, ByteBuffer bytes)
{
- incomingData.set(incomingData.get() + BufferUtil.toString(bytes,StringUtil.__UTF8_CHARSET));
+ incomingData.set(incomingData.get() + BufferUtil.toString(bytes,StandardCharsets.UTF_8));
}
public void outgoing(Socket socket, ByteBuffer bytes)
{
- outgoingData.set(outgoingData.get() + BufferUtil.toString(bytes,StringUtil.__UTF8_CHARSET));
+ outgoingData.set(outgoingData.get() + BufferUtil.toString(bytes,StandardCharsets.UTF_8));
outgoingLatch.countDown();
}
});
@@ -429,14 +430,14 @@ public class NetworkTrafficListenerTest
Socket socket = new Socket("localhost", port);
OutputStream output = socket.getOutputStream();
- output.write(request.getBytes("UTF-8"));
+ output.write(request.getBytes(StandardCharsets.UTF_8));
output.flush();
assertTrue(outgoingLatch.await(1, TimeUnit.SECONDS));
assertEquals(expectedResponse, outgoingData.get());
byte[] responseBytes = readResponse(socket);
- String response = new String(responseBytes, "UTF-8");
+ String response = new String(responseBytes, StandardCharsets.UTF_8);
assertEquals(expectedResponse, response);
assertEquals(request, incomingData.get());
diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/RequestTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/RequestTest.java
index c887876..ba1f065 100644
--- a/jetty-server/src/test/java/org/eclipse/jetty/server/RequestTest.java
+++ b/jetty-server/src/test/java/org/eclipse/jetty/server/RequestTest.java
@@ -25,6 +25,7 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.Reader;
import java.io.UnsupportedEncodingException;
+import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Map;
@@ -553,7 +554,7 @@ public class RequestTest
{
baseRequest.setHandled(true);
Reader reader=request.getReader();
- byte[] b=("read="+reader.read()+"\n").getBytes(StringUtil.__UTF8);
+ byte[] b=("read="+reader.read()+"\n").getBytes(StandardCharsets.UTF_8);
response.setContentLength(b.length);
response.getOutputStream().write(b);
response.flushBuffer();
@@ -602,7 +603,7 @@ public class RequestTest
String in = IO.toString(reader);
String param = request.getParameter("param");
- byte[] b=("read='"+in+"' param="+param+"\n").getBytes(StringUtil.__UTF8);
+ byte[] b=("read='"+in+"' param="+param+"\n").getBytes(StandardCharsets.UTF_8);
response.setContentLength(b.length);
response.getOutputStream().write(b);
response.flushBuffer();
@@ -637,7 +638,7 @@ public class RequestTest
{
baseRequest.setHandled(true);
InputStream in=request.getInputStream();
- byte[] b=("read="+in.read()+"\n").getBytes(StringUtil.__UTF8);
+ byte[] b=("read="+in.read()+"\n").getBytes(StandardCharsets.UTF_8);
response.setContentLength(b.length);
response.getOutputStream().write(b);
response.flushBuffer();
diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/SelectChannelAsyncContextTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/SelectChannelAsyncContextTest.java
index 3da12ef..9d524a8 100644
--- a/jetty-server/src/test/java/org/eclipse/jetty/server/SelectChannelAsyncContextTest.java
+++ b/jetty-server/src/test/java/org/eclipse/jetty/server/SelectChannelAsyncContextTest.java
@@ -19,6 +19,7 @@
package org.eclipse.jetty.server;
import java.net.Socket;
+import java.nio.charset.StandardCharsets;
import org.eclipse.jetty.util.IO;
@@ -35,7 +36,7 @@ public class SelectChannelAsyncContextTest extends LocalAsyncContextTest
{
ServerConnector connector = (ServerConnector)_connector;
Socket socket = new Socket((String)null,connector.getLocalPort());
- socket.getOutputStream().write(request.getBytes("UTF-8"));
+ socket.getOutputStream().write(request.getBytes(StandardCharsets.UTF_8));
return IO.toString(socket.getInputStream());
}
}
diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/SelectChannelTimeoutTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/SelectChannelTimeoutTest.java
index 0e04222..d51592d 100644
--- a/jetty-server/src/test/java/org/eclipse/jetty/server/SelectChannelTimeoutTest.java
+++ b/jetty-server/src/test/java/org/eclipse/jetty/server/SelectChannelTimeoutTest.java
@@ -24,6 +24,7 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.net.Socket;
+import java.nio.charset.StandardCharsets;
import java.util.Locale;
import org.eclipse.jetty.server.session.SessionHandler;
@@ -101,7 +102,7 @@ public class SelectChannelTimeoutTest extends ConnectorTimeoutTest
ServerConnector connector = (ServerConnector)_connector;
Socket socket = new Socket((String)null,connector.getLocalPort());
socket.setSoTimeout(10 * MAX_IDLE_TIME);
- socket.getOutputStream().write(request.getBytes("UTF-8"));
+ socket.getOutputStream().write(request.getBytes(StandardCharsets.UTF_8));
InputStream inputStream = socket.getInputStream();
long start = System.currentTimeMillis();
String response = IO.toString(inputStream);
diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/SlowClientWithPipelinedRequestTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/SlowClientWithPipelinedRequestTest.java
index 1628718..93dae66 100644
--- a/jetty-server/src/test/java/org/eclipse/jetty/server/SlowClientWithPipelinedRequestTest.java
+++ b/jetty-server/src/test/java/org/eclipse/jetty/server/SlowClientWithPipelinedRequestTest.java
@@ -25,6 +25,7 @@ import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;
import java.nio.ByteBuffer;
+import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.concurrent.atomic.AtomicInteger;
@@ -118,7 +119,7 @@ public class SlowClientWithPipelinedRequestTest
"GET /content HTTP/1.1\r\n" +
"Host: localhost:" + connector.getLocalPort() + "\r\n" +
"\r\n" +
- "").getBytes("UTF-8"));
+ "").getBytes(StandardCharsets.UTF_8));
output.flush();
InputStream input = client.getInputStream();
@@ -131,7 +132,7 @@ public class SlowClientWithPipelinedRequestTest
"GET /pipelined HTTP/1.1\r\n" +
"Host: localhost:" + connector.getLocalPort() + "\r\n" +
"\r\n" +
- "").getBytes("UTF-8"));
+ "").getBytes(StandardCharsets.UTF_8));
output.flush();
// Simulate a slow reader
diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/handler/IPAccessHandlerTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/handler/IPAccessHandlerTest.java
index 6b8d90b..58dc380 100644
--- a/jetty-server/src/test/java/org/eclipse/jetty/server/handler/IPAccessHandlerTest.java
+++ b/jetty-server/src/test/java/org/eclipse/jetty/server/handler/IPAccessHandlerTest.java
@@ -27,6 +27,7 @@ import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.Socket;
+import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.Collection;
import java.util.LinkedHashMap;
@@ -124,7 +125,7 @@ public class IPAccessHandlerTest
OutputStream output = socket.getOutputStream();
BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
- output.write(request.getBytes("UTF-8"));
+ output.write(request.getBytes(StandardCharsets.UTF_8));
output.flush();
Response response = readResponse(input);
diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/ssl/SSLCloseTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/ssl/SSLCloseTest.java
index ba6c2b1..4bdbf2b 100644
--- a/jetty-server/src/test/java/org/eclipse/jetty/server/ssl/SSLCloseTest.java
+++ b/jetty-server/src/test/java/org/eclipse/jetty/server/ssl/SSLCloseTest.java
@@ -24,6 +24,7 @@ import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.Socket;
+import java.nio.charset.StandardCharsets;
import javax.net.ssl.SSLContext;
import javax.servlet.ServletException;
@@ -105,7 +106,7 @@ public class SSLCloseTest
// data=data+data+data+data+data+data+data+data+data+data+data+data+data;
// data=data+data+data+data+data+data+data+data+data+data+data+data+data;
data=data+data+data+data;
- byte[] bytes=data.getBytes("UTF-8");
+ byte[] bytes=data.getBytes(StandardCharsets.UTF_8);
for (int i=0;i<2;i++)
{
diff --git a/jetty-servlet/src/test/java/org/eclipse/jetty/servlet/AsyncContextListenersTest.java b/jetty-servlet/src/test/java/org/eclipse/jetty/servlet/AsyncContextListenersTest.java
index 1df7213..f0b4c5e 100644
--- a/jetty-servlet/src/test/java/org/eclipse/jetty/servlet/AsyncContextListenersTest.java
+++ b/jetty-servlet/src/test/java/org/eclipse/jetty/servlet/AsyncContextListenersTest.java
@@ -23,6 +23,7 @@ import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.Socket;
+import java.nio.charset.StandardCharsets;
import java.util.concurrent.atomic.AtomicInteger;
import javax.servlet.AsyncContext;
import javax.servlet.AsyncEvent;
@@ -109,10 +110,10 @@ public class AsyncContextListenersTest
"GET " + path + " HTTP/1.1\r\n" +
"Host: localhost\r\n" +
"\r\n";
- output.write(request.getBytes("UTF-8"));
+ output.write(request.getBytes(StandardCharsets.UTF_8));
output.flush();
- BufferedReader reader = new BufferedReader(new InputStreamReader(socket.getInputStream(), "UTF-8"));
+ BufferedReader reader = new BufferedReader(new InputStreamReader(socket.getInputStream(), StandardCharsets.UTF_8));
SimpleHttpParser parser = new SimpleHttpParser();
SimpleHttpResponse response = parser.readResponse(reader);
Assert.assertEquals("200", response.getCode());
@@ -120,7 +121,7 @@ public class AsyncContextListenersTest
// Send a second request
completes.set(0);
- output.write(request.getBytes("UTF-8"));
+ output.write(request.getBytes(StandardCharsets.UTF_8));
output.flush();
response = parser.readResponse(reader);
@@ -180,10 +181,10 @@ public class AsyncContextListenersTest
"GET " + path + " HTTP/1.1\r\n" +
"Host: localhost\r\n" +
"\r\n";
- output.write(request.getBytes("UTF-8"));
+ output.write(request.getBytes(StandardCharsets.UTF_8));
output.flush();
- BufferedReader reader = new BufferedReader(new InputStreamReader(socket.getInputStream(), "UTF-8"));
+ BufferedReader reader = new BufferedReader(new InputStreamReader(socket.getInputStream(), StandardCharsets.UTF_8));
SimpleHttpParser parser = new SimpleHttpParser();
SimpleHttpResponse response = parser.readResponse(reader);
Assert.assertEquals("200", response.getCode());
@@ -191,7 +192,7 @@ public class AsyncContextListenersTest
// Send a second request
completes.set(0);
- output.write(request.getBytes("UTF-8"));
+ output.write(request.getBytes(StandardCharsets.UTF_8));
output.flush();
response = parser.readResponse(reader);
@@ -258,10 +259,10 @@ public class AsyncContextListenersTest
"GET " + path + "/one HTTP/1.1\r\n" +
"Host: localhost\r\n" +
"\r\n";
- output.write(request.getBytes("UTF-8"));
+ output.write(request.getBytes(StandardCharsets.UTF_8));
output.flush();
- BufferedReader reader = new BufferedReader(new InputStreamReader(socket.getInputStream(), "UTF-8"));
+ BufferedReader reader = new BufferedReader(new InputStreamReader(socket.getInputStream(), StandardCharsets.UTF_8));
SimpleHttpParser parser = new SimpleHttpParser();
SimpleHttpResponse response = parser.readResponse(reader);
Assert.assertEquals("200", response.getCode());
@@ -269,7 +270,7 @@ public class AsyncContextListenersTest
// Send a second request
completes.set(0);
- output.write(request.getBytes("UTF-8"));
+ output.write(request.getBytes(StandardCharsets.UTF_8));
output.flush();
response = parser.readResponse(reader);
diff --git a/jetty-servlet/src/test/java/org/eclipse/jetty/servlet/AsyncServletLongPollTest.java b/jetty-servlet/src/test/java/org/eclipse/jetty/servlet/AsyncServletLongPollTest.java
index 2b61740..383d059 100644
--- a/jetty-servlet/src/test/java/org/eclipse/jetty/servlet/AsyncServletLongPollTest.java
+++ b/jetty-servlet/src/test/java/org/eclipse/jetty/servlet/AsyncServletLongPollTest.java
@@ -23,6 +23,7 @@ import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.Socket;
+import java.nio.charset.StandardCharsets;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import javax.servlet.AsyncContext;
@@ -122,7 +123,7 @@ public class AsyncServletLongPollTest
"Host: localhost:" + connector.getLocalPort() + "\r\n" +
"\r\n";
OutputStream output1 = socket1.getOutputStream();
- output1.write(request1.getBytes("UTF-8"));
+ output1.write(request1.getBytes(StandardCharsets.UTF_8));
output1.flush();
Assert.assertTrue(asyncLatch.await(5, TimeUnit.SECONDS));
@@ -134,18 +135,18 @@ public class AsyncServletLongPollTest
"Host: localhost:" + connector.getLocalPort() + "\r\n" +
"\r\n";
OutputStream output2 = socket2.getOutputStream();
- output2.write(request2.getBytes("UTF-8"));
+ output2.write(request2.getBytes(StandardCharsets.UTF_8));
output2.flush();
SimpleHttpParser parser2 = new SimpleHttpParser();
- BufferedReader input2 = new BufferedReader(new InputStreamReader(socket2.getInputStream(), "UTF-8"));
+ BufferedReader input2 = new BufferedReader(new InputStreamReader(socket2.getInputStream(), StandardCharsets.UTF_8));
SimpleHttpResponse response2 = parser2.readResponse(input2);
Assert.assertEquals("200", response2.getCode());
}
socket1.setSoTimeout(2 * wait);
SimpleHttpParser parser1 = new SimpleHttpParser();
- BufferedReader input1 = new BufferedReader(new InputStreamReader(socket1.getInputStream(), "UTF-8"));
+ BufferedReader input1 = new BufferedReader(new InputStreamReader(socket1.getInputStream(), StandardCharsets.UTF_8));
SimpleHttpResponse response1 = parser1.readResponse(input1);
Assert.assertEquals(error, response1.getCode());
@@ -154,7 +155,7 @@ public class AsyncServletLongPollTest
String request3 = "GET " + uri + " HTTP/1.1\r\n" +
"Host: localhost:" + connector.getLocalPort() + "\r\n" +
"\r\n";
- output1.write(request3.getBytes("UTF-8"));
+ output1.write(request3.getBytes(StandardCharsets.UTF_8));
output1.flush();
SimpleHttpResponse response3 = parser1.readResponse(input1);
diff --git a/jetty-servlet/src/test/java/org/eclipse/jetty/servlet/AsyncServletTest.java b/jetty-servlet/src/test/java/org/eclipse/jetty/servlet/AsyncServletTest.java
index 8d2e453..6b707fc 100644
--- a/jetty-servlet/src/test/java/org/eclipse/jetty/servlet/AsyncServletTest.java
+++ b/jetty-servlet/src/test/java/org/eclipse/jetty/servlet/AsyncServletTest.java
@@ -21,6 +21,7 @@ package org.eclipse.jetty.servlet;
import java.io.IOException;
import java.io.InputStream;
import java.net.Socket;
+import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;
import java.util.Timer;
@@ -416,7 +417,7 @@ public class AsyncServletTest
try (Socket socket = new Socket("localhost",port))
{
socket.setSoTimeout(1000000);
- socket.getOutputStream().write(request.getBytes("UTF-8"));
+ socket.getOutputStream().write(request.getBytes(StandardCharsets.UTF_8));
return IO.toString(socket.getInputStream());
}
catch(Exception e)
diff --git a/jetty-servlet/src/test/java/org/eclipse/jetty/servlet/DefaultServletRangesTest.java b/jetty-servlet/src/test/java/org/eclipse/jetty/servlet/DefaultServletRangesTest.java
index 62a787f..aa0c366 100644
--- a/jetty-servlet/src/test/java/org/eclipse/jetty/servlet/DefaultServletRangesTest.java
+++ b/jetty-servlet/src/test/java/org/eclipse/jetty/servlet/DefaultServletRangesTest.java
@@ -23,6 +23,7 @@ import static org.junit.Assert.assertTrue;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
+import java.nio.charset.StandardCharsets;
import org.eclipse.jetty.server.HttpConfiguration;
import org.eclipse.jetty.server.LocalConnector;
@@ -220,7 +221,7 @@ public class DefaultServletRangesTest
try
{
out = new FileOutputStream(file);
- out.write(str.getBytes(StringUtil.__UTF8));
+ out.write(str.getBytes(StandardCharsets.UTF_8));
out.flush();
}
finally
diff --git a/jetty-servlet/src/test/java/org/eclipse/jetty/servlet/DefaultServletTest.java b/jetty-servlet/src/test/java/org/eclipse/jetty/servlet/DefaultServletTest.java
index fae82c6..7c2d2d1 100644
--- a/jetty-servlet/src/test/java/org/eclipse/jetty/servlet/DefaultServletTest.java
+++ b/jetty-servlet/src/test/java/org/eclipse/jetty/servlet/DefaultServletTest.java
@@ -23,6 +23,7 @@ import static org.junit.Assert.assertTrue;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
+import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.util.EnumSet;
import java.util.regex.Matcher;
@@ -882,7 +883,7 @@ public class DefaultServletTest
try
{
out = new FileOutputStream(file);
- out.write(str.getBytes(StringUtil.__UTF8));
+ out.write(str.getBytes(StandardCharsets.UTF_8));
out.flush();
}
finally
diff --git a/jetty-servlet/src/test/java/org/eclipse/jetty/servlet/RequestHeadersTest.java b/jetty-servlet/src/test/java/org/eclipse/jetty/servlet/RequestHeadersTest.java
index 3010911..ae5250c 100644
--- a/jetty-servlet/src/test/java/org/eclipse/jetty/servlet/RequestHeadersTest.java
+++ b/jetty-servlet/src/test/java/org/eclipse/jetty/servlet/RequestHeadersTest.java
@@ -25,6 +25,7 @@ import java.io.InputStream;
import java.io.PrintWriter;
import java.net.HttpURLConnection;
import java.net.URI;
+import java.nio.charset.StandardCharsets;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
@@ -109,7 +110,7 @@ public class RequestHeadersTest
try (InputStream in = http.getInputStream())
{
- String resp = IO.toString(in, "UTF-8");
+ String resp = IO.toString(in, StandardCharsets.UTF_8);
Assert.assertThat("Response", resp, is("X-Camel-Type = bactrian"));
}
}
diff --git a/jetty-servlets/src/main/java/org/eclipse/jetty/servlets/EventSourceServlet.java b/jetty-servlets/src/main/java/org/eclipse/jetty/servlets/EventSourceServlet.java
index ebabd68..697d329 100644
--- a/jetty-servlets/src/main/java/org/eclipse/jetty/servlets/EventSourceServlet.java
+++ b/jetty-servlets/src/main/java/org/eclipse/jetty/servlets/EventSourceServlet.java
@@ -22,8 +22,7 @@ package org.eclipse.jetty.servlets;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.StringReader;
-import java.io.UnsupportedEncodingException;
-import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
import java.util.Enumeration;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
@@ -54,24 +53,10 @@ import javax.servlet.http.HttpServletResponse;
*/
public abstract class EventSourceServlet extends HttpServlet
{
- private static final Charset UTF_8 = Charset.forName("UTF-8");
private static final byte[] CRLF = new byte[]{'\r', '\n'};
- private static final byte[] EVENT_FIELD;
- private static final byte[] DATA_FIELD;
- private static final byte[] COMMENT_FIELD;
- static
- {
- try
- {
- EVENT_FIELD = "event: ".getBytes(UTF_8.name());
- DATA_FIELD = "data: ".getBytes(UTF_8.name());
- COMMENT_FIELD = ": ".getBytes(UTF_8.name());
- }
- catch (UnsupportedEncodingException x)
- {
- throw new RuntimeException(x);
- }
- }
+ private static final byte[] EVENT_FIELD = "event: ".getBytes(StandardCharsets.UTF_8);
+ private static final byte[] DATA_FIELD = "data: ".getBytes(StandardCharsets.UTF_8);
+ private static final byte[] COMMENT_FIELD = ": ".getBytes(StandardCharsets.UTF_8);
private ScheduledExecutorService scheduler;
private int heartBeatPeriod = 10;
@@ -129,7 +114,7 @@ public abstract class EventSourceServlet extends HttpServlet
protected void respond(HttpServletRequest request, HttpServletResponse response) throws IOException
{
response.setStatus(HttpServletResponse.SC_OK);
- response.setCharacterEncoding(UTF_8.name());
+ response.setCharacterEncoding(StandardCharsets.UTF_8.name());
response.setContentType("text/event-stream");
// By adding this header, and not closing the connection,
// we disable HTTP chunking, and we can use write()+flush()
@@ -164,7 +149,7 @@ public abstract class EventSourceServlet extends HttpServlet
synchronized (this)
{
output.write(EVENT_FIELD);
- output.write(name.getBytes(UTF_8.name()));
+ output.write(name.getBytes(StandardCharsets.UTF_8));
output.write(CRLF);
data(data);
}
@@ -180,7 +165,7 @@ public abstract class EventSourceServlet extends HttpServlet
while ((line = reader.readLine()) != null)
{
output.write(DATA_FIELD);
- output.write(line.getBytes(UTF_8.name()));
+ output.write(line.getBytes(StandardCharsets.UTF_8));
output.write(CRLF);
}
output.write(CRLF);
@@ -194,7 +179,7 @@ public abstract class EventSourceServlet extends HttpServlet
synchronized (this)
{
output.write(COMMENT_FIELD);
- output.write(comment.getBytes(UTF_8.name()));
+ output.write(comment.getBytes(StandardCharsets.UTF_8));
output.write(CRLF);
output.write(CRLF);
flush();
diff --git a/jetty-servlets/src/main/java/org/eclipse/jetty/servlets/MultiPartFilter.java b/jetty-servlets/src/main/java/org/eclipse/jetty/servlets/MultiPartFilter.java
index 253d6d5..8501373 100644
--- a/jetty-servlets/src/main/java/org/eclipse/jetty/servlets/MultiPartFilter.java
+++ b/jetty-servlets/src/main/java/org/eclipse/jetty/servlets/MultiPartFilter.java
@@ -24,6 +24,9 @@ import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
+import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
+import java.nio.charset.UnsupportedCharsetException;
import java.util.Collection;
import java.util.Collections;
import java.util.Enumeration;
@@ -223,7 +226,7 @@ public class MultiPartFilter implements Filter
/* ------------------------------------------------------------------------------- */
private static class Wrapper extends HttpServletRequestWrapper
{
- String _encoding=StringUtil.__UTF8;
+ Charset _encoding=StandardCharsets.UTF_8;
MultiMap<Object> _params;
/* ------------------------------------------------------------------------------- */
@@ -339,7 +342,14 @@ public class MultiPartFilter implements Filter
public void setCharacterEncoding(String enc)
throws UnsupportedEncodingException
{
- _encoding=enc;
+ try
+ {
+ _encoding=Charset.forName(enc);
+ }
+ catch (UnsupportedCharsetException e)
+ {
+ throw new UnsupportedEncodingException(e.getMessage());
+ }
}
@@ -350,11 +360,18 @@ public class MultiPartFilter implements Filter
//check if there is a specific encoding for the parameter
Object ct = _params.getValue(name+CONTENT_TYPE_SUFFIX,0);
//use default if not
- String contentType = _encoding;
+ Charset contentType = _encoding;
if (ct != null)
{
String tmp = MimeTypes.getCharsetFromContentType((String)ct);
- contentType = (tmp == null?_encoding:tmp);
+ try
+ {
+ contentType = (tmp == null?_encoding:Charset.forName(tmp));
+ }
+ catch (UnsupportedCharsetException e)
+ {
+ throw new UnsupportedEncodingException(e.getMessage());
+ }
}
return new String(bytes,contentType);
diff --git a/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/AbstractDoSFilterTest.java b/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/AbstractDoSFilterTest.java
index b81a1e4..4c4e9cd 100644
--- a/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/AbstractDoSFilterTest.java
+++ b/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/AbstractDoSFilterTest.java
@@ -25,6 +25,7 @@ import static org.junit.Assert.assertTrue;
import java.io.IOException;
import java.net.Socket;
+import java.nio.charset.StandardCharsets;
import java.util.EnumSet;
import javax.servlet.DispatcherType;
@@ -117,14 +118,14 @@ public abstract class AbstractDoSFilterTest
for (int i=loops;i-->0;)
{
- socket.getOutputStream().write(loopRequests.getBytes("UTF-8"));
+ socket.getOutputStream().write(loopRequests.getBytes(StandardCharsets.UTF_8));
socket.getOutputStream().flush();
if (i>0 && pauseBetweenLoops>0)
Thread.sleep(pauseBetweenLoops);
}
if (pauseBeforeLast>0)
Thread.sleep(pauseBeforeLast);
- socket.getOutputStream().write(lastRequest.getBytes("UTF-8"));
+ socket.getOutputStream().write(lastRequest.getBytes(StandardCharsets.UTF_8));
socket.getOutputStream().flush();
@@ -133,11 +134,11 @@ public abstract class AbstractDoSFilterTest
{
// don't read in anything, forcing the request to time out
Thread.sleep(_requestMaxTime * 2);
- response = IO.toString(socket.getInputStream(),"UTF-8");
+ response = IO.toString(socket.getInputStream(),StandardCharsets.UTF_8);
}
else
{
- response = IO.toString(socket.getInputStream(),"UTF-8");
+ response = IO.toString(socket.getInputStream(),StandardCharsets.UTF_8);
}
socket.close();
return response;
diff --git a/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/EventSourceServletTest.java b/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/EventSourceServletTest.java
index 6f2d6ab..75fc4b7 100644
--- a/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/EventSourceServletTest.java
+++ b/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/EventSourceServletTest.java
@@ -24,6 +24,7 @@ import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.Socket;
+import java.nio.charset.StandardCharsets;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;
@@ -326,7 +327,7 @@ public class EventSourceServletTest
handshake += "Host: localhost:" + serverPort + "\r\n";
handshake += "Accept: text/event-stream\r\n";
handshake += "\r\n";
- output.write(handshake.getBytes("UTF-8"));
+ output.write(handshake.getBytes(StandardCharsets.UTF_8));
output.flush();
}
@@ -334,7 +335,7 @@ public class EventSourceServletTest
{
// Read and discard the HTTP response
InputStream input = socket.getInputStream();
- BufferedReader reader = new BufferedReader(new InputStreamReader(input, "UTF-8"));
+ BufferedReader reader = new BufferedReader(new InputStreamReader(input, StandardCharsets.UTF_8));
String line = reader.readLine();
while (line != null)
{
diff --git a/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/MultipartFilterTest.java b/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/MultipartFilterTest.java
index 9098ea3..ba43429 100644
--- a/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/MultipartFilterTest.java
+++ b/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/MultipartFilterTest.java
@@ -31,6 +31,7 @@ import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.PrintWriter;
+import java.nio.charset.StandardCharsets;
import java.util.EnumSet;
import java.util.Map;
@@ -867,7 +868,7 @@ public class MultipartFilterTest
baos.write(("--" + boundary + "\r\n"+
"Content-Disposition: form-data; name=\"ttt\"\r\n"+
"Content-Type: application/octet-stream; charset=UTF-8\r\n\r\n").getBytes());
- baos.write("ttt\u01FCzzz".getBytes(StringUtil.__UTF8));
+ baos.write("ttt\u01FCzzz".getBytes(StandardCharsets.UTF_8));
baos.write(("\r\n--" + boundary + "--\r\n\r\n").getBytes());
diff --git a/jetty-spdy/spdy-core/src/main/java/org/eclipse/jetty/spdy/api/DataInfo.java b/jetty-spdy/spdy-core/src/main/java/org/eclipse/jetty/spdy/api/DataInfo.java
index 4949b98..d0d66b4 100644
--- a/jetty-spdy/spdy-core/src/main/java/org/eclipse/jetty/spdy/api/DataInfo.java
+++ b/jetty-spdy/spdy-core/src/main/java/org/eclipse/jetty/spdy/api/DataInfo.java
@@ -209,8 +209,19 @@ public abstract class DataInfo extends Info
*/
public String asString(String charset, boolean consume)
{
+ return asString(Charset.forName(charset), consume);
+ }
+
+ /**
+ *
+ * @param charset the charset used to convert the bytes
+ * @param consume whether to consume the content
+ * @return a String with the content of this {@link DataInfo}
+ */
+ public String asString(Charset charset, boolean consume)
+ {
ByteBuffer buffer = asByteBuffer(consume);
- return Charset.forName(charset).decode(buffer).toString();
+ return charset.decode(buffer).toString();
}
/**
diff --git a/jetty-spdy/spdy-core/src/main/java/org/eclipse/jetty/spdy/api/StringDataInfo.java b/jetty-spdy/spdy-core/src/main/java/org/eclipse/jetty/spdy/api/StringDataInfo.java
index 6a114d1..0a4eac2 100644
--- a/jetty-spdy/spdy-core/src/main/java/org/eclipse/jetty/spdy/api/StringDataInfo.java
+++ b/jetty-spdy/spdy-core/src/main/java/org/eclipse/jetty/spdy/api/StringDataInfo.java
@@ -18,7 +18,7 @@
package org.eclipse.jetty.spdy.api;
-import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
import java.util.concurrent.TimeUnit;
/**
@@ -28,11 +28,11 @@ public class StringDataInfo extends BytesDataInfo
{
public StringDataInfo(String string, boolean close)
{
- super(string.getBytes(Charset.forName("UTF-8")), close);
+ super(string.getBytes(StandardCharsets.UTF_8), close);
}
public StringDataInfo(long timeout, TimeUnit unit, String string, boolean close)
{
- super(timeout, unit, string.getBytes(Charset.forName("UTF-8")), close);
+ super(timeout, unit, string.getBytes(StandardCharsets.UTF_8), close);
}
}
diff --git a/jetty-spdy/spdy-core/src/main/java/org/eclipse/jetty/spdy/generator/HeadersBlockGenerator.java b/jetty-spdy/spdy-core/src/main/java/org/eclipse/jetty/spdy/generator/HeadersBlockGenerator.java
index beed61c..4504523 100644
--- a/jetty-spdy/spdy-core/src/main/java/org/eclipse/jetty/spdy/generator/HeadersBlockGenerator.java
+++ b/jetty-spdy/spdy-core/src/main/java/org/eclipse/jetty/spdy/generator/HeadersBlockGenerator.java
@@ -20,7 +20,7 @@ package org.eclipse.jetty.spdy.generator;
import java.io.ByteArrayOutputStream;
import java.nio.ByteBuffer;
-import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
import java.util.Locale;
import org.eclipse.jetty.spdy.CompressionDictionary;
@@ -41,25 +41,24 @@ public class HeadersBlockGenerator
public ByteBuffer generate(short version, Fields headers)
{
// TODO: ByteArrayOutputStream is quite inefficient, but grows on demand; optimize using ByteBuffer ?
- Charset iso1 = Charset.forName("ISO-8859-1");
ByteArrayOutputStream buffer = new ByteArrayOutputStream(headers.size() * 64);
writeCount(version, buffer, headers.size());
for (Fields.Field header : headers)
{
String name = header.name().toLowerCase(Locale.ENGLISH);
- byte[] nameBytes = name.getBytes(iso1);
+ byte[] nameBytes = name.getBytes(StandardCharsets.ISO_8859_1);
writeNameLength(version, buffer, nameBytes.length);
buffer.write(nameBytes, 0, nameBytes.length);
// Most common path first
String value = header.value();
- byte[] valueBytes = value.getBytes(iso1);
+ byte[] valueBytes = value.getBytes(StandardCharsets.ISO_8859_1);
if (header.hasMultipleValues())
{
String[] values = header.values();
for (int i = 1; i < values.length; ++i)
{
- byte[] moreValueBytes = values[i].getBytes(iso1);
+ byte[] moreValueBytes = values[i].getBytes(StandardCharsets.ISO_8859_1);
byte[] newValueBytes = new byte[valueBytes.length + 1 + moreValueBytes.length];
System.arraycopy(valueBytes, 0, newValueBytes, 0, valueBytes.length);
newValueBytes[valueBytes.length] = 0;
diff --git a/jetty-spdy/spdy-core/src/main/java/org/eclipse/jetty/spdy/parser/HeadersBlockParser.java b/jetty-spdy/spdy-core/src/main/java/org/eclipse/jetty/spdy/parser/HeadersBlockParser.java
index 1b2613b..7dda076 100644
--- a/jetty-spdy/spdy-core/src/main/java/org/eclipse/jetty/spdy/parser/HeadersBlockParser.java
+++ b/jetty-spdy/spdy-core/src/main/java/org/eclipse/jetty/spdy/parser/HeadersBlockParser.java
@@ -19,7 +19,7 @@
package org.eclipse.jetty.spdy.parser;
import java.nio.ByteBuffer;
-import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
import java.util.zip.ZipException;
import org.eclipse.jetty.spdy.CompressionDictionary;
@@ -57,8 +57,6 @@ public abstract class HeadersBlockParser
data = null;
ByteBuffer decompressedHeaders = decompress(version, compressedHeaders);
- Charset iso1 = Charset.forName("ISO-8859-1");
-
// We know the decoded bytes contain the full headers,
// so optimize instead of looping byte by byte
int count = readCount(version, decompressedHeaders);
@@ -69,14 +67,14 @@ public abstract class HeadersBlockParser
throw new StreamException(streamId, StreamStatus.PROTOCOL_ERROR, "Invalid header name length");
byte[] nameBytes = new byte[nameLength];
decompressedHeaders.get(nameBytes);
- String name = new String(nameBytes, iso1);
+ String name = new String(nameBytes, StandardCharsets.ISO_8859_1);
int valueLength = readValueLength(version, decompressedHeaders);
if (valueLength == 0)
throw new StreamException(streamId, StreamStatus.PROTOCOL_ERROR, "Invalid header value length");
byte[] valueBytes = new byte[valueLength];
decompressedHeaders.get(valueBytes);
- String value = new String(valueBytes, iso1);
+ String value = new String(valueBytes, StandardCharsets.ISO_8859_1);
// Multi valued headers are separate by NUL
String[] values = value.split("\u0000");
// Check if there are multiple NULs (section 2.6.9)
diff --git a/jetty-spdy/spdy-core/src/test/java/org/eclipse/jetty/spdy/api/ClientUsageTest.java b/jetty-spdy/spdy-core/src/test/java/org/eclipse/jetty/spdy/api/ClientUsageTest.java
index 455b58e..d3aa8d6 100644
--- a/jetty-spdy/spdy-core/src/test/java/org/eclipse/jetty/spdy/api/ClientUsageTest.java
+++ b/jetty-spdy/spdy-core/src/test/java/org/eclipse/jetty/spdy/api/ClientUsageTest.java
@@ -19,6 +19,7 @@
package org.eclipse.jetty.spdy.api;
import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
@@ -242,7 +243,7 @@ public class ClientUsageTest
public void onData(Stream stream, DataInfo dataInfo)
{
StringBuilder builder = (StringBuilder)stream.getAttribute("builder");
- builder.append(dataInfo.asString("UTF-8", true));
+ builder.append(dataInfo.asString(StandardCharsets.UTF_8, true));
}
}, new Promise.Adapter<Stream>()
@@ -250,9 +251,9 @@ public class ClientUsageTest
@Override
public void succeeded(Stream stream)
{
- stream.data(new BytesDataInfo("wee".getBytes(Charset.forName("UTF-8")), false), new Callback.Adapter());
+ stream.data(new BytesDataInfo("wee".getBytes(StandardCharsets.UTF_8), false), new Callback.Adapter());
stream.data(new StringDataInfo("foo", false), new Callback.Adapter());
- stream.data(new ByteBufferDataInfo(Charset.forName("UTF-8").encode("bar"), true), new Callback.Adapter());
+ stream.data(new ByteBufferDataInfo(StandardCharsets.UTF_8.encode("bar"), true), new Callback.Adapter());
}
}
);
diff --git a/jetty-spdy/spdy-core/src/test/java/org/eclipse/jetty/spdy/parser/ParseVersusCacheBenchmarkTest.java b/jetty-spdy/spdy-core/src/test/java/org/eclipse/jetty/spdy/parser/ParseVersusCacheBenchmarkTest.java
index 7787b2e..143a510 100644
--- a/jetty-spdy/spdy-core/src/test/java/org/eclipse/jetty/spdy/parser/ParseVersusCacheBenchmarkTest.java
+++ b/jetty-spdy/spdy-core/src/test/java/org/eclipse/jetty/spdy/parser/ParseVersusCacheBenchmarkTest.java
@@ -20,6 +20,7 @@ package org.eclipse.jetty.spdy.parser;
import java.nio.ByteBuffer;
import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
@@ -43,8 +44,7 @@ public class ParseVersusCacheBenchmarkTest
String name = "Content-Type";
String value = "application/octect-stream";
- Charset charset = Charset.forName("ISO-8859-1");
- ByteBuffer buffer = ByteBuffer.wrap((name + value).getBytes(charset));
+ ByteBuffer buffer = ByteBuffer.wrap((name + value).getBytes(StandardCharsets.ISO_8859_1));
int iterations = 100_000_000;
long begin = System.nanoTime();
@@ -52,12 +52,12 @@ public class ParseVersusCacheBenchmarkTest
{
byte[] nameBytes = new byte[name.length()];
buffer.get(nameBytes);
- String name2 = new String(nameBytes, charset);
+ String name2 = new String(nameBytes, StandardCharsets.ISO_8859_1);
Assert.assertEquals(name2, name);
byte[] valueBytes = new byte[value.length()];
buffer.get(valueBytes);
- String value2 = new String(valueBytes, charset);
+ String value2 = new String(valueBytes, StandardCharsets.ISO_8859_1);
Assert.assertEquals(value2, value);
buffer.flip();
@@ -66,8 +66,8 @@ public class ParseVersusCacheBenchmarkTest
System.err.printf("parse time: %d%n", TimeUnit.NANOSECONDS.toMillis(end - begin));
Map<ByteBuffer, String> map = new HashMap<>();
- map.put(ByteBuffer.wrap(name.getBytes(charset)), name);
- map.put(ByteBuffer.wrap(value.getBytes(charset)), value);
+ map.put(ByteBuffer.wrap(name.getBytes(StandardCharsets.ISO_8859_1)), name);
+ map.put(ByteBuffer.wrap(value.getBytes(StandardCharsets.ISO_8859_1)), value);
final Map<ByteBuffer, String> cache = Collections.unmodifiableMap(map);
begin = System.nanoTime();
diff --git a/jetty-spdy/spdy-http-server/src/test/java/org/eclipse/jetty/spdy/server/http/ProtocolNegotiationTest.java b/jetty-spdy/spdy-http-server/src/test/java/org/eclipse/jetty/spdy/server/http/ProtocolNegotiationTest.java
index 7903b41..fdd4076 100644
--- a/jetty-spdy/spdy-http-server/src/test/java/org/eclipse/jetty/spdy/server/http/ProtocolNegotiationTest.java
+++ b/jetty-spdy/spdy-http-server/src/test/java/org/eclipse/jetty/spdy/server/http/ProtocolNegotiationTest.java
@@ -24,6 +24,7 @@ import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.InetSocketAddress;
+import java.nio.charset.StandardCharsets;
import java.util.List;
import javax.net.ssl.SSLContext;
@@ -129,11 +130,11 @@ public class ProtocolNegotiationTest
"GET / HTTP/1.1\r\n" +
"Host: localhost:" + address.getPort() + "\r\n" +
"\r\n" +
- "").getBytes("UTF-8"));
+ "").getBytes(StandardCharsets.UTF_8));
output.flush();
InputStream input = client.getInputStream();
- BufferedReader reader = new BufferedReader(new InputStreamReader(input, "UTF-8"));
+ BufferedReader reader = new BufferedReader(new InputStreamReader(input, StandardCharsets.UTF_8));
String line = reader.readLine();
Assert.assertTrue(line.contains(" 404 "));
@@ -188,11 +189,11 @@ public class ProtocolNegotiationTest
"GET / HTTP/1.1\r\n" +
"Host: localhost:" + address.getPort() + "\r\n" +
"\r\n" +
- "").getBytes("UTF-8"));
+ "").getBytes(StandardCharsets.UTF_8));
output.flush();
InputStream input = client.getInputStream();
- BufferedReader reader = new BufferedReader(new InputStreamReader(input, "UTF-8"));
+ BufferedReader reader = new BufferedReader(new InputStreamReader(input, StandardCharsets.UTF_8));
String line = reader.readLine();
Assert.assertTrue(line.contains(" 404 "));
@@ -241,11 +242,11 @@ public class ProtocolNegotiationTest
"GET / HTTP/1.1\r\n" +
"Host: localhost:" + address.getPort() + "\r\n" +
"\r\n" +
- "").getBytes("UTF-8"));
+ "").getBytes(StandardCharsets.UTF_8));
output.flush();
InputStream input = client.getInputStream();
- BufferedReader reader = new BufferedReader(new InputStreamReader(input, "UTF-8"));
+ BufferedReader reader = new BufferedReader(new InputStreamReader(input, StandardCharsets.UTF_8));
String line = reader.readLine();
Assert.assertTrue(line.contains(" 404 "));
diff --git a/jetty-spdy/spdy-http-server/src/test/java/org/eclipse/jetty/spdy/server/http/ServerHTTPSPDYTest.java b/jetty-spdy/spdy-http-server/src/test/java/org/eclipse/jetty/spdy/server/http/ServerHTTPSPDYTest.java
index 9851995..190234b 100644
--- a/jetty-spdy/spdy-http-server/src/test/java/org/eclipse/jetty/spdy/server/http/ServerHTTPSPDYTest.java
+++ b/jetty-spdy/spdy-http-server/src/test/java/org/eclipse/jetty/spdy/server/http/ServerHTTPSPDYTest.java
@@ -25,6 +25,7 @@ import java.io.InputStream;
import java.io.OutputStream;
import java.nio.ByteBuffer;
import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
@@ -432,7 +433,7 @@ public class ServerHTTPSPDYTest extends AbstractHTTPSPDYTest
request.setHandled(true);
httpResponse.setStatus(HttpServletResponse.SC_OK);
ServletOutputStream output = httpResponse.getOutputStream();
- output.write(data.getBytes("UTF-8"));
+ output.write(data.getBytes(StandardCharsets.UTF_8));
handlerLatch.countDown();
}
}), null);
@@ -455,7 +456,7 @@ public class ServerHTTPSPDYTest extends AbstractHTTPSPDYTest
public void onData(Stream stream, DataInfo dataInfo)
{
assertTrue(dataInfo.isClose());
- assertEquals(data, dataInfo.asString("UTF-8", true));
+ assertEquals(data, dataInfo.asString(StandardCharsets.UTF_8, true));
dataLatch.countDown();
}
});
@@ -527,9 +528,9 @@ public class ServerHTTPSPDYTest extends AbstractHTTPSPDYTest
request.setHandled(true);
httpResponse.setStatus(HttpServletResponse.SC_OK);
ServletOutputStream output = httpResponse.getOutputStream();
- output.write(data1.getBytes("UTF-8"));
+ output.write(data1.getBytes(StandardCharsets.UTF_8));
output.flush();
- output.write(data2.getBytes("UTF-8"));
+ output.write(data2.getBytes(StandardCharsets.UTF_8));
handlerLatch.countDown();
}
}), null);
@@ -558,9 +559,9 @@ public class ServerHTTPSPDYTest extends AbstractHTTPSPDYTest
int data = dataFrames.incrementAndGet();
assertTrue(data >= 1 && data <= 2);
if (data == 1)
- assertEquals(data1, dataInfo.asString("UTF8", true));
+ assertEquals(data1, dataInfo.asString(StandardCharsets.UTF_8, true));
else
- assertEquals(data2, dataInfo.asString("UTF8", true));
+ assertEquals(data2, dataInfo.asString(StandardCharsets.UTF_8, true));
dataLatch.countDown();
}
});
@@ -744,7 +745,7 @@ public class ServerHTTPSPDYTest extends AbstractHTTPSPDYTest
request.setHandled(true);
httpResponse.setStatus(HttpServletResponse.SC_OK);
ServletOutputStream output = httpResponse.getOutputStream();
- output.write(data.getBytes("UTF-8"));
+ output.write(data.getBytes(StandardCharsets.UTF_8));
output.flush();
output.close();
handlerLatch.countDown();
@@ -775,7 +776,7 @@ public class ServerHTTPSPDYTest extends AbstractHTTPSPDYTest
buffer.write(byteBuffer.get());
if (dataInfo.isClose())
{
- assertEquals(data, new String(buffer.toByteArray(), Charset.forName("UTF-8")));
+ assertEquals(data, new String(buffer.toByteArray(), StandardCharsets.UTF_8));
dataLatch.countDown();
}
}
@@ -801,10 +802,10 @@ public class ServerHTTPSPDYTest extends AbstractHTTPSPDYTest
httpResponse.setStatus(HttpServletResponse.SC_OK);
ServletOutputStream output = httpResponse.getOutputStream();
// Write some
- output.write(data1.getBytes("UTF-8"));
+ output.write(data1.getBytes(StandardCharsets.UTF_8));
// But then change your mind and reset the buffer
httpResponse.resetBuffer();
- output.write(data2.getBytes("UTF-8"));
+ output.write(data2.getBytes(StandardCharsets.UTF_8));
handlerLatch.countDown();
}
}), null);
@@ -833,7 +834,7 @@ public class ServerHTTPSPDYTest extends AbstractHTTPSPDYTest
buffer.write(byteBuffer.get());
if (dataInfo.isClose())
{
- assertEquals(data2, new String(buffer.toByteArray(), Charset.forName("UTF-8")));
+ assertEquals(data2, new String(buffer.toByteArray(), StandardCharsets.UTF_8));
dataLatch.countDown();
}
}
@@ -990,10 +991,10 @@ public class ServerHTTPSPDYTest extends AbstractHTTPSPDYTest
request.setHandled(true);
httpResponse.setHeader("Transfer-Encoding", "chunked");
ServletOutputStream output = httpResponse.getOutputStream();
- output.write(pangram1.getBytes("UTF-8"));
+ output.write(pangram1.getBytes(StandardCharsets.UTF_8));
httpResponse.setHeader("EXTRA", "X");
output.flush();
- output.write(pangram2.getBytes("UTF-8"));
+ output.write(pangram2.getBytes(StandardCharsets.UTF_8));
handlerLatch.countDown();
}
}), null);
@@ -1024,12 +1025,12 @@ public class ServerHTTPSPDYTest extends AbstractHTTPSPDYTest
if (count == 1)
{
Assert.assertFalse(dataInfo.isClose());
- assertEquals(pangram1, dataInfo.asString("UTF-8", true));
+ assertEquals(pangram1, dataInfo.asString(StandardCharsets.UTF_8, true));
}
else if (count == 2)
{
assertTrue(dataInfo.isClose());
- assertEquals(pangram2, dataInfo.asString("UTF-8", true));
+ assertEquals(pangram2, dataInfo.asString(StandardCharsets.UTF_8, true));
}
dataLatch.countDown();
}
diff --git a/jetty-spdy/spdy-http-server/src/test/java/org/eclipse/jetty/spdy/server/proxy/ProxyHTTPToSPDYTest.java b/jetty-spdy/spdy-http-server/src/test/java/org/eclipse/jetty/spdy/server/proxy/ProxyHTTPToSPDYTest.java
index cb8f6a3..66fffc1 100644
--- a/jetty-spdy/spdy-http-server/src/test/java/org/eclipse/jetty/spdy/server/proxy/ProxyHTTPToSPDYTest.java
+++ b/jetty-spdy/spdy-http-server/src/test/java/org/eclipse/jetty/spdy/server/proxy/ProxyHTTPToSPDYTest.java
@@ -19,6 +19,7 @@
package org.eclipse.jetty.spdy.server.proxy;
import java.net.InetSocketAddress;
+import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.Collection;
import java.util.concurrent.CountDownLatch;
@@ -251,7 +252,7 @@ public class ProxyHTTPToSPDYTest
@Test
public void testGETThenSmallResponseContent() throws Exception
{
- final byte[] data = "0123456789ABCDEF".getBytes("UTF-8");
+ final byte[] data = "0123456789ABCDEF".getBytes(StandardCharsets.UTF_8);
InetSocketAddress proxyAddress = startProxy(startServer(new ServerSessionFrameListener.Adapter()
{
@Override
@@ -328,7 +329,7 @@ public class ProxyHTTPToSPDYTest
public void testPOSTWithSmallRequestContentThenSmallResponseContent() throws Exception
{
String dataString = "0123456789ABCDEF";
- final byte[] data = dataString.getBytes("UTF-8");
+ final byte[] data = dataString.getBytes(StandardCharsets.UTF_8);
InetSocketAddress proxyAddress = startProxy(startServer(new ServerSessionFrameListener.Adapter()
{
@Override
@@ -370,7 +371,7 @@ public class ProxyHTTPToSPDYTest
@Test
public void testGETThenSPDYPushIsIgnored() throws Exception
{
- final byte[] data = "0123456789ABCDEF".getBytes("UTF-8");
+ final byte[] data = "0123456789ABCDEF".getBytes(StandardCharsets.UTF_8);
InetSocketAddress proxyAddress = startProxy(startServer(new ServerSessionFrameListener.Adapter()
{
@Override
diff --git a/jetty-spdy/spdy-http-server/src/test/java/org/eclipse/jetty/spdy/server/proxy/ProxySPDYToHTTPTest.java b/jetty-spdy/spdy-http-server/src/test/java/org/eclipse/jetty/spdy/server/proxy/ProxySPDYToHTTPTest.java
index 556c148..58e9aa2 100644
--- a/jetty-spdy/spdy-http-server/src/test/java/org/eclipse/jetty/spdy/server/proxy/ProxySPDYToHTTPTest.java
+++ b/jetty-spdy/spdy-http-server/src/test/java/org/eclipse/jetty/spdy/server/proxy/ProxySPDYToHTTPTest.java
@@ -22,6 +22,7 @@ import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.net.InetSocketAddress;
+import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.Collection;
import java.util.concurrent.CountDownLatch;
@@ -197,7 +198,7 @@ public class ProxySPDYToHTTPTest
@Test
public void testSYNThenREPLYAndDATA() throws Exception
{
- final byte[] data = "0123456789ABCDEF".getBytes("UTF-8");
+ final byte[] data = "0123456789ABCDEF".getBytes(StandardCharsets.UTF_8);
final String header = "foo";
InetSocketAddress proxyAddress = startProxy(startServer(new TestServerHandler(header, data)), 30000, 30000);
diff --git a/jetty-spdy/spdy-http-server/src/test/java/org/eclipse/jetty/spdy/server/proxy/ProxySPDYToSPDYTest.java b/jetty-spdy/spdy-http-server/src/test/java/org/eclipse/jetty/spdy/server/proxy/ProxySPDYToSPDYTest.java
index 064f556..f651dd1 100644
--- a/jetty-spdy/spdy-http-server/src/test/java/org/eclipse/jetty/spdy/server/proxy/ProxySPDYToSPDYTest.java
+++ b/jetty-spdy/spdy-http-server/src/test/java/org/eclipse/jetty/spdy/server/proxy/ProxySPDYToSPDYTest.java
@@ -20,6 +20,7 @@ package org.eclipse.jetty.spdy.server.proxy;
import java.io.ByteArrayOutputStream;
import java.net.InetSocketAddress;
+import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.Collection;
import java.util.concurrent.CountDownLatch;
@@ -227,7 +228,7 @@ public class ProxySPDYToSPDYTest
@Test
public void testSYNThenREPLYAndDATA() throws Exception
{
- final byte[] data = "0123456789ABCDEF".getBytes("UTF-8");
+ final byte[] data = "0123456789ABCDEF".getBytes(StandardCharsets.UTF_8);
final String header = "foo";
InetSocketAddress proxyAddress = startProxy(startServer(new ServerSessionFrameListener.Adapter()
{
@@ -287,7 +288,7 @@ public class ProxySPDYToSPDYTest
@Test
public void testSYNThenSPDYPushIsReceived() throws Exception
{
- final byte[] data = "0123456789ABCDEF".getBytes("UTF-8");
+ final byte[] data = "0123456789ABCDEF".getBytes(StandardCharsets.UTF_8);
InetSocketAddress proxyAddress = startProxy(startServer(new ServerSessionFrameListener.Adapter()
{
@Override
@@ -368,7 +369,7 @@ public class ProxySPDYToSPDYTest
@Test
public void testSYNThenSPDYNestedPushIsReceived() throws Exception
{
- final byte[] data = "0123456789ABCDEF".getBytes("UTF-8");
+ final byte[] data = "0123456789ABCDEF".getBytes(StandardCharsets.UTF_8);
InetSocketAddress proxyAddress = startProxy(startServer(new ServerSessionFrameListener.Adapter()
{
@Override
diff --git a/jetty-spdy/spdy-server/src/test/java/org/eclipse/jetty/spdy/server/SynReplyTest.java b/jetty-spdy/spdy-server/src/test/java/org/eclipse/jetty/spdy/server/SynReplyTest.java
index 4a76d1b..efe68b4 100644
--- a/jetty-spdy/spdy-server/src/test/java/org/eclipse/jetty/spdy/server/SynReplyTest.java
+++ b/jetty-spdy/spdy-server/src/test/java/org/eclipse/jetty/spdy/server/SynReplyTest.java
@@ -21,6 +21,7 @@ package org.eclipse.jetty.spdy.server;
import java.io.ByteArrayOutputStream;
import java.nio.ByteBuffer;
import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
@@ -118,7 +119,7 @@ public class SynReplyTest extends AbstractTest
@Test
public void testSynDataReply() throws Exception
{
- final byte[] dataBytes = "foo".getBytes(Charset.forName("UTF-8"));
+ final byte[] dataBytes = "foo".getBytes(StandardCharsets.UTF_8);
final CountDownLatch synLatch = new CountDownLatch(1);
final CountDownLatch dataLatch = new CountDownLatch(1);
@@ -235,13 +236,13 @@ public class SynReplyTest extends AbstractTest
int dataCount = this.dataCount.incrementAndGet();
if (dataCount == 1)
{
- String chunk1 = dataInfo.asString("UTF-8", true);
+ String chunk1 = dataInfo.asString(StandardCharsets.UTF_8, true);
Assert.assertEquals(data1, chunk1);
dataLatch1.countDown();
}
else if (dataCount == 2)
{
- String chunk2 = dataInfo.asString("UTF-8", true);
+ String chunk2 = dataInfo.asString(StandardCharsets.UTF_8, true);
Assert.assertEquals(data2, chunk2);
dataLatch2.countDown();
}
@@ -277,7 +278,7 @@ public class SynReplyTest extends AbstractTest
@Override
public void onData(Stream stream, DataInfo dataInfo)
{
- String data = dataInfo.asString("UTF-8", true);
+ String data = dataInfo.asString(StandardCharsets.UTF_8, true);
Assert.assertEquals(clientData, data);
clientDataLatch.countDown();
}
@@ -311,7 +312,7 @@ public class SynReplyTest extends AbstractTest
public void onData(Stream stream, DataInfo dataInfo)
{
ByteBuffer buffer = dataInfo.asByteBuffer(false);
- String data = Charset.forName("UTF-8").decode(buffer).toString();
+ String data = StandardCharsets.UTF_8.decode(buffer).toString();
Assert.assertEquals(serverData, data);
serverDataLatch.countDown();
}
@@ -361,7 +362,7 @@ public class SynReplyTest extends AbstractTest
@Override
public void onData(Stream stream, DataInfo dataInfo)
{
- String chunk = dataInfo.asString("UTF-8", true);
+ String chunk = dataInfo.asString(StandardCharsets.UTF_8, true);
Assert.assertEquals(data, chunk);
dataLatch.countDown();
}
diff --git a/jetty-spring/src/main/java/org/eclipse/jetty/spring/SpringConfigurationProcessor.java b/jetty-spring/src/main/java/org/eclipse/jetty/spring/SpringConfigurationProcessor.java
index f226e67..26f2b8d 100644
--- a/jetty-spring/src/main/java/org/eclipse/jetty/spring/SpringConfigurationProcessor.java
+++ b/jetty-spring/src/main/java/org/eclipse/jetty/spring/SpringConfigurationProcessor.java
@@ -20,6 +20,7 @@
package org.eclipse.jetty.spring;
import java.net.URL;
+import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.Map;
import java.util.ServiceLoader;
@@ -80,7 +81,7 @@ public class SpringConfigurationProcessor implements ConfigurationProcessor
: new ByteArrayResource(("" +
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
"<!DOCTYPE beans PUBLIC \"-//SPRING//DTD BEAN//EN\" \"http://www.springframework.org/dtd/spring-beans.dtd\">" +
- config).getBytes("UTF-8"));
+ config).getBytes(StandardCharsets.UTF_8));
_beanFactory = new DefaultListableBeanFactory()
{
diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/AbstractTrie.java b/jetty-util/src/main/java/org/eclipse/jetty/util/AbstractTrie.java
index a9cb827..2d152b2 100644
--- a/jetty-util/src/main/java/org/eclipse/jetty/util/AbstractTrie.java
+++ b/jetty-util/src/main/java/org/eclipse/jetty/util/AbstractTrie.java
@@ -19,6 +19,7 @@
package org.eclipse.jetty.util;
import java.nio.ByteBuffer;
+import java.nio.charset.StandardCharsets;
/* ------------------------------------------------------------ */
@@ -72,7 +73,7 @@ public abstract class AbstractTrie<V> implements Trie<V>
@Override
public V getBest(byte[] b, int offset, int len)
{
- return getBest(new String(b,offset,len,StringUtil.__ISO_8859_1_CHARSET));
+ return getBest(new String(b,offset,len,StandardCharsets.ISO_8859_1));
}
@Override
diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/B64Code.java b/jetty-util/src/main/java/org/eclipse/jetty/util/B64Code.java
index 936984c..f61d1bd 100644
--- a/jetty-util/src/main/java/org/eclipse/jetty/util/B64Code.java
+++ b/jetty-util/src/main/java/org/eclipse/jetty/util/B64Code.java
@@ -21,6 +21,7 @@ package org.eclipse.jetty.util;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
import java.nio.charset.UnsupportedCharsetException;
@@ -65,7 +66,7 @@ public class B64Code
*/
public static String encode(String s)
{
- return encode(s,null);
+ return encode(s, (Charset)null);
}
/**
@@ -80,13 +81,26 @@ public class B64Code
{
byte[] bytes;
if (charEncoding==null)
- bytes=s.getBytes(Charset.forName(StringUtil.__ISO_8859_1));
+ bytes=s.getBytes(StandardCharsets.ISO_8859_1);
else
bytes=s.getBytes(Charset.forName(charEncoding));
return new String(encode(bytes));
}
/**
+ * Base 64 encode as described in RFC 1421.
+ * <p>Does not insert whitespace as described in RFC 1521.
+ * @param s String to encode.
+ * @param charEncoding The character encoding of the provided input String.
+ * @return String containing the encoded form of the input.
+ */
+ public static String encode(String s, Charset charEncoding)
+ {
+ byte[] bytes=s.getBytes(charEncoding==null ? StandardCharsets.ISO_8859_1 : charEncoding);
+ return new String(encode(bytes));
+ }
+
+ /**
* Fast Base 64 encode as described in RFC 1421.
* <p>Does not insert whitespace as described in RFC 1521.
* <p> Avoids creating extra copies of the input/output.
@@ -237,6 +251,24 @@ public class B64Code
}
/**
+ * Base 64 decode as described in RFC 2045.
+ * <p>Unlike {@link #decode(char[])}, extra whitespace is ignored.
+ * @param encoded String to decode.
+ * @param charEncoding Character encoding
+ * used to map the decoded bytes into a String.
+ * @return String decoded byte array.
+ * @throws IllegalArgumentException if the input is not a valid
+ * B64 encoding.
+ */
+ public static String decode(String encoded, Charset charEncoding)
+ {
+ byte[] decoded=decode(encoded);
+ if (charEncoding==null)
+ return new String(decoded);
+ return new String(decoded, charEncoding);
+ }
+
+ /**
* Fast Base 64 decode as described in RFC 1421.
*
* <p>Unlike other decode methods, this does not attempt to
diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/BufferUtil.java b/jetty-util/src/main/java/org/eclipse/jetty/util/BufferUtil.java
index 198e9e7..95e4f50 100644
--- a/jetty-util/src/main/java/org/eclipse/jetty/util/BufferUtil.java
+++ b/jetty-util/src/main/java/org/eclipse/jetty/util/BufferUtil.java
@@ -29,6 +29,7 @@ import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import java.nio.channels.FileChannel.MapMode;
import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
/* ------------------------------------------------------------------------------- */
@@ -454,7 +455,7 @@ public class BufferUtil
*/
public static String toString(ByteBuffer buffer)
{
- return toString(buffer, StringUtil.__ISO_8859_1_CHARSET);
+ return toString(buffer, StandardCharsets.ISO_8859_1);
}
/* ------------------------------------------------------------ */
@@ -464,7 +465,7 @@ public class BufferUtil
*/
public static String toUTF8String(ByteBuffer buffer)
{
- return toString(buffer, StringUtil.__UTF8_CHARSET);
+ return toString(buffer, StandardCharsets.UTF_8);
}
/* ------------------------------------------------------------ */
@@ -733,12 +734,12 @@ public class BufferUtil
public static ByteBuffer toBuffer(String s)
{
- return ByteBuffer.wrap(s.getBytes(StringUtil.__ISO_8859_1_CHARSET));
+ return ByteBuffer.wrap(s.getBytes(StandardCharsets.ISO_8859_1));
}
public static ByteBuffer toDirectBuffer(String s)
{
- byte[] bytes = s.getBytes(StringUtil.__ISO_8859_1_CHARSET);
+ byte[] bytes = s.getBytes(StandardCharsets.ISO_8859_1);
ByteBuffer buf = ByteBuffer.allocateDirect(bytes.length);
buf.put(bytes);
buf.flip();
diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/ByteArrayISO8859Writer.java b/jetty-util/src/main/java/org/eclipse/jetty/util/ByteArrayISO8859Writer.java
index 3787a80..c4ed7f4 100644
--- a/jetty-util/src/main/java/org/eclipse/jetty/util/ByteArrayISO8859Writer.java
+++ b/jetty-util/src/main/java/org/eclipse/jetty/util/ByteArrayISO8859Writer.java
@@ -21,6 +21,7 @@ import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.Writer;
+import java.nio.charset.StandardCharsets;
/* ------------------------------------------------------------ */
@@ -211,7 +212,7 @@ public class ByteArrayISO8859Writer extends Writer
if (_bout==null)
{
_bout = new ByteArrayOutputStream2(2*length);
- _writer = new OutputStreamWriter(_bout,StringUtil.__ISO_8859_1);
+ _writer = new OutputStreamWriter(_bout,StandardCharsets.ISO_8859_1);
}
else
_bout.reset();
diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/IO.java b/jetty-util/src/main/java/org/eclipse/jetty/util/IO.java
index 0194edd..c1e501b 100644
--- a/jetty-util/src/main/java/org/eclipse/jetty/util/IO.java
+++ b/jetty-util/src/main/java/org/eclipse/jetty/util/IO.java
@@ -29,6 +29,7 @@ import java.io.PrintWriter;
import java.io.Reader;
import java.io.StringWriter;
import java.io.Writer;
+import java.nio.charset.Charset;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
@@ -311,7 +312,7 @@ public class IO
public static String toString(InputStream in)
throws IOException
{
- return toString(in,null);
+ return toString(in,(Charset)null);
}
/* ------------------------------------------------------------ */
@@ -320,13 +321,21 @@ public class IO
public static String toString(InputStream in,String encoding)
throws IOException
{
+ return toString(in, encoding==null?null:Charset.forName(encoding));
+ }
+
+ /** Read input stream to string.
+ */
+ public static String toString(InputStream in, Charset encoding)
+ throws IOException
+ {
StringWriter writer=new StringWriter();
InputStreamReader reader = encoding==null?new InputStreamReader(in):new InputStreamReader(in,encoding);
-
+
copy(reader,writer);
return writer.toString();
}
-
+
/* ------------------------------------------------------------ */
/** Read input stream to string.
*/
diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/MultiPartInputStreamParser.java b/jetty-util/src/main/java/org/eclipse/jetty/util/MultiPartInputStreamParser.java
index f47a197..b09edfb 100644
--- a/jetty-util/src/main/java/org/eclipse/jetty/util/MultiPartInputStreamParser.java
+++ b/jetty-util/src/main/java/org/eclipse/jetty/util/MultiPartInputStreamParser.java
@@ -29,6 +29,7 @@ import java.io.FilterInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
+import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
@@ -475,7 +476,7 @@ public class MultiPartInputStreamParser
}
String boundary="--"+contentTypeBoundary;
- byte[] byteBoundary=(boundary+"--").getBytes(StringUtil.__ISO_8859_1);
+ byte[] byteBoundary=(boundary+"--").getBytes(StandardCharsets.ISO_8859_1);
// Get first boundary
String line = null;
diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/MultiPartOutputStream.java b/jetty-util/src/main/java/org/eclipse/jetty/util/MultiPartOutputStream.java
index 85cc700..047a1c0 100644
--- a/jetty-util/src/main/java/org/eclipse/jetty/util/MultiPartOutputStream.java
+++ b/jetty-util/src/main/java/org/eclipse/jetty/util/MultiPartOutputStream.java
@@ -21,6 +21,7 @@ package org.eclipse.jetty.util;
import java.io.FilterOutputStream;
import java.io.IOException;
import java.io.OutputStream;
+import java.nio.charset.StandardCharsets;
/* ================================================================ */
@@ -53,7 +54,7 @@ public class MultiPartOutputStream extends FilterOutputStream
boundary = "jetty"+System.identityHashCode(this)+
Long.toString(System.currentTimeMillis(),36);
- boundaryBytes=boundary.getBytes(StringUtil.__ISO_8859_1);
+ boundaryBytes=boundary.getBytes(StandardCharsets.ISO_8859_1);
}
public MultiPartOutputStream(OutputStream out, String boundary)
@@ -62,7 +63,7 @@ public class MultiPartOutputStream extends FilterOutputStream
super(out);
this.boundary = boundary;
- boundaryBytes=boundary.getBytes(StringUtil.__ISO_8859_1);
+ boundaryBytes=boundary.getBytes(StandardCharsets.ISO_8859_1);
}
/* ------------------------------------------------------------ */
@@ -110,7 +111,7 @@ public class MultiPartOutputStream extends FilterOutputStream
out.write(boundaryBytes);
out.write(__CRLF);
if (contentType != null)
- out.write(("Content-Type: "+contentType).getBytes(StringUtil.__ISO_8859_1));
+ out.write(("Content-Type: "+contentType).getBytes(StandardCharsets.ISO_8859_1));
out.write(__CRLF);
out.write(__CRLF);
}
@@ -128,11 +129,11 @@ public class MultiPartOutputStream extends FilterOutputStream
out.write(boundaryBytes);
out.write(__CRLF);
if (contentType != null)
- out.write(("Content-Type: "+contentType).getBytes(StringUtil.__ISO_8859_1));
+ out.write(("Content-Type: "+contentType).getBytes(StandardCharsets.ISO_8859_1));
out.write(__CRLF);
for (int i=0;headers!=null && i<headers.length;i++)
{
- out.write(headers[i].getBytes(StringUtil.__ISO_8859_1));
+ out.write(headers[i].getBytes(StandardCharsets.ISO_8859_1));
out.write(__CRLF);
}
out.write(__CRLF);
diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/ReadLineInputStream.java b/jetty-util/src/main/java/org/eclipse/jetty/util/ReadLineInputStream.java
index 1aeec5f..b584c7c 100644
--- a/jetty-util/src/main/java/org/eclipse/jetty/util/ReadLineInputStream.java
+++ b/jetty-util/src/main/java/org/eclipse/jetty/util/ReadLineInputStream.java
@@ -21,6 +21,7 @@ package org.eclipse.jetty.util;
import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
+import java.nio.charset.StandardCharsets;
/**
* ReadLineInputStream
@@ -58,7 +59,7 @@ public class ReadLineInputStream extends BufferedInputStream
int m=markpos;
markpos=-1;
if (pos>m)
- return new String(buf,m,pos-m,StringUtil.__UTF8_CHARSET);
+ return new String(buf,m,pos-m, StandardCharsets.UTF_8);
return null;
}
@@ -77,7 +78,7 @@ public class ReadLineInputStream extends BufferedInputStream
_skipLF=true;
int m=markpos;
markpos=-1;
- return new String(buf,m,p-m-1,StringUtil.__UTF8_CHARSET);
+ return new String(buf,m,p-m-1,StandardCharsets.UTF_8);
}
if (b=='\n')
@@ -91,7 +92,7 @@ public class ReadLineInputStream extends BufferedInputStream
}
int m=markpos;
markpos=-1;
- return new String(buf,m,pos-m-1,StringUtil.__UTF8_CHARSET);
+ return new String(buf,m,pos-m-1,StandardCharsets.UTF_8);
}
}
}
diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/StringUtil.java b/jetty-util/src/main/java/org/eclipse/jetty/util/StringUtil.java
index 03e8b2c..9889481 100644
--- a/jetty-util/src/main/java/org/eclipse/jetty/util/StringUtil.java
+++ b/jetty-util/src/main/java/org/eclipse/jetty/util/StringUtil.java
@@ -21,13 +21,14 @@ package org.eclipse.jetty.util;
import java.io.UnsupportedEncodingException;
import java.nio.ByteBuffer;
import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
/** Fast String Utilities.
*
- * These string utilities provide both conveniance methods and
+ * These string utilities provide both convenience methods and
* performance improvements over most standard library versions. The
* main aim of the optimizations is to avoid object creation unless
* absolutely required.
@@ -49,19 +50,30 @@ public class StringUtil
public static final String __ISO_8859_1="ISO-8859-1";
public final static String __UTF8="UTF-8";
public final static String __UTF16="UTF-16";
-
- public final static Charset __UTF8_CHARSET;
- public final static Charset __ISO_8859_1_CHARSET;
- public final static Charset __UTF16_CHARSET;
- public final static Charset __US_ASCII_CHARSET;
+
+ /**
+ * @deprecated Use {@link StandardCharsets#UTF_8}
+ */
+ @Deprecated
+ public final static Charset __UTF8_CHARSET=StandardCharsets.UTF_8;
+ /**
+ * @deprecated Use {@link StandardCharsets#ISO_8859_1}
+ */
+ @Deprecated
+ public final static Charset __ISO_8859_1_CHARSET=StandardCharsets.ISO_8859_1;
+ /**
+ * @deprecated Use {@link StandardCharsets#UTF_16}
+ */
+ @Deprecated
+ public final static Charset __UTF16_CHARSET=StandardCharsets.UTF_16;
+ /**
+ * @deprecated Use {@link StandardCharsets#US_ASCII}
+ */
+ @Deprecated
+ public final static Charset __US_ASCII_CHARSET=StandardCharsets.US_ASCII;
static
{
- __UTF8_CHARSET=Charset.forName(__UTF8);
- __ISO_8859_1_CHARSET=Charset.forName(__ISO_8859_1);
- __UTF16_CHARSET=Charset.forName(__UTF16);
- __US_ASCII_CHARSET=Charset.forName("US-ASCII");
-
CHARSETS.put("UTF-8",__UTF8);
CHARSETS.put("UTF8",__UTF8);
CHARSETS.put("UTF-16",__UTF16);
@@ -343,7 +355,7 @@ public class StringUtil
/* ------------------------------------------------------------ */
public static String toUTF8String(byte[] b,int offset,int length)
{
- return new String(b,offset,length,__UTF8_CHARSET);
+ return new String(b,offset,length,StandardCharsets.UTF_8);
}
/* ------------------------------------------------------------ */
@@ -481,12 +493,12 @@ public class StringUtil
public static byte[] getBytes(String s)
{
- return s.getBytes(__ISO_8859_1_CHARSET);
+ return s.getBytes(StandardCharsets.ISO_8859_1);
}
public static byte[] getUtf8Bytes(String s)
{
- return s.getBytes(__UTF8_CHARSET);
+ return s.getBytes(StandardCharsets.UTF_8);
}
public static byte[] getBytes(String s,String charset)
diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/TreeTrie.java b/jetty-util/src/main/java/org/eclipse/jetty/util/TreeTrie.java
index b82b6f4..7f07455 100644
--- a/jetty-util/src/main/java/org/eclipse/jetty/util/TreeTrie.java
+++ b/jetty-util/src/main/java/org/eclipse/jetty/util/TreeTrie.java
@@ -20,6 +20,7 @@ package org.eclipse.jetty.util;
import java.io.IOException;
import java.nio.ByteBuffer;
+import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
@@ -215,7 +216,7 @@ public class TreeTrie<V> extends AbstractTrie<V>
public V getBest(String s, int offset, int len)
{
// TODO inefficient
- byte[] b=s.substring(offset,offset+len).getBytes(StringUtil.__ISO_8859_1_CHARSET);
+ byte[] b=s.substring(offset,offset+len).getBytes(StandardCharsets.ISO_8859_1);
return getBest(b,0,b.length);
}
diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/URIUtil.java b/jetty-util/src/main/java/org/eclipse/jetty/util/URIUtil.java
index ddae8d0..6bf81d9 100644
--- a/jetty-util/src/main/java/org/eclipse/jetty/util/URIUtil.java
+++ b/jetty-util/src/main/java/org/eclipse/jetty/util/URIUtil.java
@@ -19,6 +19,7 @@
package org.eclipse.jetty.util;
import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
@@ -43,8 +44,14 @@ public class URIUtil
public static final String HTTPS_COLON="https:";
// Use UTF-8 as per http://www.w3.org/TR/html40/appendix/notes.html#non-ascii-chars
- public static final Charset __CHARSET=Charset.forName(System.getProperty("org.eclipse.jetty.util.URI.charset",StringUtil.__UTF8));
-
+ public static final Charset __CHARSET;
+
+ static
+ {
+ String charset = System.getProperty("org.eclipse.jetty.util.URI.charset");
+ __CHARSET = charset == null ? StandardCharsets.UTF_8 : Charset.forName(charset);
+ }
+
private URIUtil()
{}
diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/UrlEncoded.java b/jetty-util/src/main/java/org/eclipse/jetty/util/UrlEncoded.java
index dfe0203..48277bc 100644
--- a/jetty-util/src/main/java/org/eclipse/jetty/util/UrlEncoded.java
+++ b/jetty-util/src/main/java/org/eclipse/jetty/util/UrlEncoded.java
@@ -25,6 +25,7 @@ import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.StringWriter;
import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.Map;
@@ -59,15 +60,16 @@ public class UrlEncoded extends MultiMap<String> implements Cloneable
public static final Charset ENCODING;
static
{
- Charset encoding=null;
+ Charset encoding;
try
{
- encoding=Charset.forName(System.getProperty("org.eclipse.jetty.util.UrlEncoding.charset",StringUtil.__UTF8));
+ String charset = System.getProperty("org.eclipse.jetty.util.UrlEncoding.charset");
+ encoding = charset == null ? StandardCharsets.UTF_8 : Charset.forName(charset);
}
catch(Exception e)
{
LOG.warn(e);
- encoding=StringUtil.__UTF8_CHARSET;
+ encoding=StandardCharsets.UTF_8;
}
ENCODING=encoding;
}
@@ -269,7 +271,6 @@ public class UrlEncoded extends MultiMap<String> implements Cloneable
* @param offset the offset within raw to decode from
* @param length the length of the section to decode
* @param map the {@link MultiMap} to populate
- * @param buffer the buffer to decode into
*/
public static void decodeUtf8To(byte[] raw,int offset, int length, MultiMap<String> map)
{
@@ -594,11 +595,11 @@ public class UrlEncoded extends MultiMap<String> implements Cloneable
/* -------------------------------------------------------------- */
public static void decodeUtf16To(InputStream in, MultiMap<String> map, int maxLength, int maxKeys) throws IOException
{
- InputStreamReader input = new InputStreamReader(in,StringUtil.__UTF16);
+ InputStreamReader input = new InputStreamReader(in,StandardCharsets.UTF_16);
StringWriter buf = new StringWriter(8192);
IO.copy(input,buf,maxLength);
- decodeTo(buf.getBuffer().toString(),map,StringUtil.__UTF16,maxKeys);
+ decodeTo(buf.getBuffer().toString(),map,StandardCharsets.UTF_16,maxKeys);
}
/* -------------------------------------------------------------- */
@@ -610,7 +611,7 @@ public class UrlEncoded extends MultiMap<String> implements Cloneable
{
if (charset==null)
{
- if (ENCODING==StringUtil.__UTF8_CHARSET)
+ if (ENCODING.equals(StandardCharsets.UTF_8))
decodeUtf8To(in,map,maxLength,maxKeys);
else
decodeTo(in,map,ENCODING,maxLength,maxKeys);
@@ -636,19 +637,19 @@ public class UrlEncoded extends MultiMap<String> implements Cloneable
if (charset==null)
charset=ENCODING;
- if (StringUtil.__UTF8_CHARSET.equals(charset))
+ if (StandardCharsets.UTF_8.equals(charset))
{
decodeUtf8To(in,map,maxLength,maxKeys);
return;
}
- if (StringUtil.__ISO_8859_1_CHARSET.equals(charset))
+ if (StandardCharsets.ISO_8859_1.equals(charset))
{
decode88591To(in,map,maxLength,maxKeys);
return;
}
- if (StringUtil.__UTF16_CHARSET.equals(charset)) // Should be all 2 byte encodings
+ if (StandardCharsets.UTF_16.equals(charset)) // Should be all 2 byte encodings
{
decodeUtf16To(in,map,maxLength,maxKeys);
return;
@@ -753,7 +754,7 @@ public class UrlEncoded extends MultiMap<String> implements Cloneable
*/
public static String decodeString(String encoded,int offset,int length,Charset charset)
{
- if (charset==null || StringUtil.__UTF8_CHARSET.equals(charset))
+ if (charset==null || StandardCharsets.UTF_8.equals(charset))
{
Utf8StringBuffer buffer=null;
diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/security/Credential.java b/jetty-util/src/main/java/org/eclipse/jetty/util/security/Credential.java
index a6a135d..8ce30d7 100644
--- a/jetty-util/src/main/java/org/eclipse/jetty/util/security/Credential.java
+++ b/jetty-util/src/main/java/org/eclipse/jetty/util/security/Credential.java
@@ -19,6 +19,7 @@
package org.eclipse.jetty.util.security;
import java.io.Serializable;
+import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import org.eclipse.jetty.util.StringUtil;
@@ -156,7 +157,7 @@ public abstract class Credential implements Serializable
{
if (__md == null) __md = MessageDigest.getInstance("MD5");
__md.reset();
- __md.update(credentials.toString().getBytes(StringUtil.__ISO_8859_1));
+ __md.update(credentials.toString().getBytes(StandardCharsets.ISO_8859_1));
digest = __md.digest();
}
if (digest == null || digest.length != _digest.length) return false;
@@ -213,7 +214,7 @@ public abstract class Credential implements Serializable
}
__md.reset();
- __md.update(password.getBytes(StringUtil.__ISO_8859_1));
+ __md.update(password.getBytes(StandardCharsets.ISO_8859_1));
digest = __md.digest();
}
diff --git a/jetty-util/src/test/java/org/eclipse/jetty/util/B64CodeTest.java b/jetty-util/src/test/java/org/eclipse/jetty/util/B64CodeTest.java
index 5d0ecbf..05033fa 100644
--- a/jetty-util/src/test/java/org/eclipse/jetty/util/B64CodeTest.java
+++ b/jetty-util/src/test/java/org/eclipse/jetty/util/B64CodeTest.java
@@ -23,6 +23,8 @@ import junit.framework.Assert;
import org.junit.Test;
+import java.nio.charset.StandardCharsets;
+
public class B64CodeTest
{
String text = "Man is distinguished, not only by his reason, but by this singular passion from other animals, which is a lust of the mind, that by a perseverance of delight in the continued and indefatigable generation of knowledge, exceeds the short vehemence of any carnal pleasure.";
@@ -30,14 +32,14 @@ public class B64CodeTest
@Test
public void testRFC1421() throws Exception
{
- String b64 = B64Code.encode(text,StringUtil.__ISO_8859_1);
+ String b64 = B64Code.encode(text, StandardCharsets.ISO_8859_1);
Assert.assertEquals("TWFuIGlzIGRpc3Rpbmd1aXNoZWQsIG5vdCBvbmx5IGJ5IGhpcyByZWFzb24sIGJ1dCBieSB0aGlz"+
"IHNpbmd1bGFyIHBhc3Npb24gZnJvbSBvdGhlciBhbmltYWxzLCB3aGljaCBpcyBhIGx1c3Qgb2Yg"+
"dGhlIG1pbmQsIHRoYXQgYnkgYSBwZXJzZXZlcmFuY2Ugb2YgZGVsaWdodCBpbiB0aGUgY29udGlu"+
"dWVkIGFuZCBpbmRlZmF0aWdhYmxlIGdlbmVyYXRpb24gb2Yga25vd2xlZGdlLCBleGNlZWRzIHRo"+
"ZSBzaG9ydCB2ZWhlbWVuY2Ugb2YgYW55IGNhcm5hbCBwbGVhc3VyZS4=",b64);
- char[] chars = B64Code.encode(text.getBytes(StringUtil.__ISO_8859_1),false);
+ char[] chars = B64Code.encode(text.getBytes(StandardCharsets.ISO_8859_1),false);
b64 = new String(chars,0,chars.length);
Assert.assertEquals("TWFuIGlzIGRpc3Rpbmd1aXNoZWQsIG5vdCBvbmx5IGJ5IGhpcyByZWFzb24sIGJ1dCBieSB0aGlz"+
"IHNpbmd1bGFyIHBhc3Npb24gZnJvbSBvdGhlciBhbmltYWxzLCB3aGljaCBpcyBhIGx1c3Qgb2Yg"+
@@ -50,7 +52,7 @@ public class B64CodeTest
@Test
public void testRFC2045() throws Exception
{
- char[] chars = B64Code.encode(text.getBytes(StringUtil.__ISO_8859_1),true);
+ char[] chars = B64Code.encode(text.getBytes(StandardCharsets.ISO_8859_1),true);
String b64 = new String(chars,0,chars.length);
Assert.assertEquals("TWFuIGlzIGRpc3Rpbmd1aXNoZWQsIG5vdCBvbmx5IGJ5IGhpcyByZWFzb24sIGJ1dCBieSB0aGlz\r\n"+
"IHNpbmd1bGFyIHBhc3Npb24gZnJvbSBvdGhlciBhbmltYWxzLCB3aGljaCBpcyBhIGx1c3Qgb2Yg\r\n"+
@@ -64,7 +66,7 @@ public class B64CodeTest
@Test
public void testInteger() throws Exception
{
- byte[] bytes = text.getBytes(StringUtil.__ISO_8859_1);
+ byte[] bytes = text.getBytes(StandardCharsets.ISO_8859_1);
int value=(bytes[0]<<24)+(bytes[1]<<16)+(bytes[2]<<8)+(bytes[3]);
StringBuilder b = new StringBuilder();
@@ -74,7 +76,7 @@ public class B64CodeTest
@Test
public void testLong() throws Exception
{
- byte[] bytes = text.getBytes(StringUtil.__ISO_8859_1);
+ byte[] bytes = text.getBytes(StandardCharsets.ISO_8859_1);
long value=((0xffL&bytes[0])<<56)+((0xffL&bytes[1])<<48)+((0xffL&bytes[2])<<40)+((0xffL&bytes[3])<<32)+
((0xffL&bytes[4])<<24)+((0xffL&bytes[5])<<16)+((0xffL&bytes[6])<<8)+(0xffL&bytes[7]);
diff --git a/jetty-util/src/test/java/org/eclipse/jetty/util/ReadLineInputStreamTest.java b/jetty-util/src/test/java/org/eclipse/jetty/util/ReadLineInputStreamTest.java
index 943ff5f..6260edf 100644
--- a/jetty-util/src/test/java/org/eclipse/jetty/util/ReadLineInputStreamTest.java
+++ b/jetty-util/src/test/java/org/eclipse/jetty/util/ReadLineInputStreamTest.java
@@ -21,6 +21,7 @@ package org.eclipse.jetty.util;
import java.io.OutputStream;
import java.io.PipedInputStream;
import java.io.PipedOutputStream;
+import java.nio.charset.StandardCharsets;
import java.util.concurrent.TimeUnit;
import org.junit.After;
@@ -60,7 +61,7 @@ public class ReadLineInputStreamTest
_pout.close();
else
{
- _pout.write(s.getBytes(StringUtil.__UTF8_CHARSET));
+ _pout.write(s.getBytes(StandardCharsets.UTF_8));
Thread.sleep(50);
}
}
@@ -196,7 +197,7 @@ public class ReadLineInputStreamTest
byte[] body = new byte[6];
_in.read(body);
- Assert.assertEquals("\nBody\n",new String(body,0,6,StringUtil.__UTF8));
+ Assert.assertEquals("\nBody\n",new String(body,0,6,StandardCharsets.UTF_8));
Assert.assertEquals("",_in.readLine());
Assert.assertEquals(null,_in.readLine());
@@ -216,7 +217,7 @@ public class ReadLineInputStreamTest
byte[] body = new byte[6];
_in.read(body);
- Assert.assertEquals("\nBody\n",new String(body,0,6,StringUtil.__UTF8));
+ Assert.assertEquals("\nBody\n",new String(body,0,6,StandardCharsets.UTF_8));
Assert.assertEquals("",_in.readLine());
Assert.assertEquals(null,_in.readLine());
@@ -236,7 +237,7 @@ public class ReadLineInputStreamTest
byte[] body = new byte[6];
_in.read(body);
- Assert.assertEquals("\nBody\n",new String(body,0,6,StringUtil.__UTF8));
+ Assert.assertEquals("\nBody\n",new String(body,0,6,StandardCharsets.UTF_8));
Assert.assertEquals("",_in.readLine());
Assert.assertEquals(null,_in.readLine());
diff --git a/jetty-util/src/test/java/org/eclipse/jetty/util/StringUtilTest.java b/jetty-util/src/test/java/org/eclipse/jetty/util/StringUtilTest.java
index 4a668f4..6503ee3 100644
--- a/jetty-util/src/test/java/org/eclipse/jetty/util/StringUtilTest.java
+++ b/jetty-util/src/test/java/org/eclipse/jetty/util/StringUtilTest.java
@@ -25,6 +25,8 @@ import static org.junit.Assert.assertTrue;
import org.junit.Assert;
import org.junit.Test;
+import java.nio.charset.StandardCharsets;
+
public class StringUtilTest
{
@Test
@@ -160,7 +162,7 @@ public class StringUtilTest
{
String string = "Now \u0690xxxxxxxx";
System.err.println(string);
- byte[] bytes=string.getBytes("UTF-8");
+ byte[] bytes=string.getBytes(StandardCharsets.UTF_8);
System.err.println(new String(bytes));
System.err.println(bytes.length);
long calc=0;
@@ -170,7 +172,7 @@ public class StringUtilTest
long s1=System.currentTimeMillis();
for (int j=1000000; j-->0;)
{
- calc+=new String(bytes,0,bytes.length,"UTF-8").hashCode();
+ calc+=new String(bytes,0,bytes.length,StandardCharsets.UTF_8).hashCode();
}
long s2=System.currentTimeMillis();
for (int j=1000000; j-->0;)
diff --git a/jetty-util/src/test/java/org/eclipse/jetty/util/URITest.java b/jetty-util/src/test/java/org/eclipse/jetty/util/URITest.java
index 691b8e1..42b6b61 100644
--- a/jetty-util/src/test/java/org/eclipse/jetty/util/URITest.java
+++ b/jetty-util/src/test/java/org/eclipse/jetty/util/URITest.java
@@ -21,6 +21,7 @@ package org.eclipse.jetty.util;
import static org.junit.Assert.assertEquals;
import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
import org.junit.Test;
@@ -65,7 +66,7 @@ public class URITest
// Test for null character (real world ugly test case)
byte oddBytes[] = { '/', 0x00, '/' };
- String odd = new String(oddBytes, Charset.forName("ISO-8859-1"));
+ String odd = new String(oddBytes, StandardCharsets.ISO_8859_1);
assertEquals(odd,URIUtil.decodePath("/%00/"));
}
diff --git a/jetty-util/src/test/java/org/eclipse/jetty/util/URLEncodedTest.java b/jetty-util/src/test/java/org/eclipse/jetty/util/URLEncodedTest.java
index ea8de42..f6980f3 100644
--- a/jetty-util/src/test/java/org/eclipse/jetty/util/URLEncodedTest.java
+++ b/jetty-util/src/test/java/org/eclipse/jetty/util/URLEncodedTest.java
@@ -23,6 +23,7 @@ import static org.junit.Assert.assertTrue;
import java.io.ByteArrayInputStream;
import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
import org.junit.Assert;
import org.junit.Test;
@@ -121,22 +122,22 @@ public class URLEncodedTest
assertEquals("encoded get", url_encoded.getString("Name8"),"xx, yy ,zz");
url_encoded.clear();
- url_encoded.decode("Name11=%u30EDxxVerdi+%C6+og+2zz", StringUtil.__ISO_8859_1_CHARSET);
+ url_encoded.decode("Name11=%u30EDxxVerdi+%C6+og+2zz", StandardCharsets.ISO_8859_1);
assertEquals("encoded param size",1, url_encoded.size());
assertEquals("encoded get", "?xxVerdi \u00c6 og 2zz",url_encoded.getString("Name11"));
url_encoded.clear();
- url_encoded.decode("Name12=%u30EDxxVerdi+%2F+og+2zz", StringUtil.__UTF8_CHARSET);
+ url_encoded.decode("Name12=%u30EDxxVerdi+%2F+og+2zz", StandardCharsets.UTF_8);
assertEquals("encoded param size",1, url_encoded.size());
assertEquals("encoded get", url_encoded.getString("Name12"),"\u30edxxVerdi / og 2zz");
url_encoded.clear();
- url_encoded.decode("Name14=%uXXXXa%GGb%+%c%+%d", StringUtil.__ISO_8859_1_CHARSET);
+ url_encoded.decode("Name14=%uXXXXa%GGb%+%c%+%d", StandardCharsets.ISO_8859_1);
assertEquals("encoded param size",1, url_encoded.size());
assertEquals("encoded get","?a?b?c?d", url_encoded.getString("Name14"));
url_encoded.clear();
- url_encoded.decode("Name14=%uXXXX%GG%+%%+%", StringUtil.__UTF8_CHARSET);
+ url_encoded.decode("Name14=%uXXXX%GG%+%%+%", StandardCharsets.UTF_8);
assertEquals("encoded param size",1, url_encoded.size());
assertEquals("encoded get", "\ufffd\ufffd\ufffd\ufffd",url_encoded.getString("Name14"));
@@ -160,38 +161,38 @@ public class URLEncodedTest
public void testBadEncoding()
{
UrlEncoded url_encoded = new UrlEncoded();
- url_encoded.decode("Name15=xx%zzyy", StringUtil.__UTF8_CHARSET);
+ url_encoded.decode("Name15=xx%zzyy", StandardCharsets.UTF_8);
assertEquals("encoded param size",1, url_encoded.size());
assertEquals("encoded get", "xx\ufffdyy", url_encoded.getString("Name15"));
- byte[] bad="Name=%FF%FF%FF".getBytes(StringUtil.__UTF8_CHARSET);
+ byte[] bad="Name=%FF%FF%FF".getBytes(StandardCharsets.UTF_8);
MultiMap<String> map = new MultiMap<String>();
UrlEncoded.decodeUtf8To(bad,0,bad.length,map);
assertEquals("encoded param size",1, map.size());
assertEquals("encoded get", "\ufffd\ufffd\ufffd", map.getString("Name"));
url_encoded.clear();
- url_encoded.decode("Name=%FF%FF%FF", StringUtil.__UTF8_CHARSET);
+ url_encoded.decode("Name=%FF%FF%FF", StandardCharsets.UTF_8);
assertEquals("encoded param size",1, url_encoded.size());
assertEquals("encoded get", "\ufffd\ufffd\ufffd", url_encoded.getString("Name"));
url_encoded.clear();
- url_encoded.decode("Name=%EF%EF%EF", StringUtil.__UTF8_CHARSET);
+ url_encoded.decode("Name=%EF%EF%EF", StandardCharsets.UTF_8);
assertEquals("encoded param size",1, url_encoded.size());
assertEquals("encoded get", "\ufffd\ufffd", url_encoded.getString("Name"));
- assertEquals("x",UrlEncoded.decodeString("x",0,1,StringUtil.__UTF8_CHARSET));
- assertEquals("x\ufffd",UrlEncoded.decodeString("x%",0,2,StringUtil.__UTF8_CHARSET));
- assertEquals("x\ufffd",UrlEncoded.decodeString("x%2",0,3,StringUtil.__UTF8_CHARSET));
- assertEquals("x ",UrlEncoded.decodeString("x%20",0,4,StringUtil.__UTF8_CHARSET));
-
- assertEquals("xxx",UrlEncoded.decodeString("xxx",0,3,StringUtil.__UTF8_CHARSET));
- assertEquals("xxx\ufffd",UrlEncoded.decodeString("xxx%",0,4,StringUtil.__UTF8_CHARSET));
- assertEquals("xxx\ufffd",UrlEncoded.decodeString("xxx%u",0,5,StringUtil.__UTF8_CHARSET));
- assertEquals("xxx\ufffd",UrlEncoded.decodeString("xxx%u1",0,6,StringUtil.__UTF8_CHARSET));
- assertEquals("xxx\ufffd",UrlEncoded.decodeString("xxx%u12",0,7,StringUtil.__UTF8_CHARSET));
- assertEquals("xxx\ufffd",UrlEncoded.decodeString("xxx%u123",0,8,StringUtil.__UTF8_CHARSET));
- assertEquals("xxx\u1234",UrlEncoded.decodeString("xxx%u1234",0,9,StringUtil.__UTF8_CHARSET));
+ assertEquals("x",UrlEncoded.decodeString("x",0,1,StandardCharsets.UTF_8));
+ assertEquals("x\ufffd",UrlEncoded.decodeString("x%",0,2,StandardCharsets.UTF_8));
+ assertEquals("x\ufffd",UrlEncoded.decodeString("x%2",0,3,StandardCharsets.UTF_8));
+ assertEquals("x ",UrlEncoded.decodeString("x%20",0,4,StandardCharsets.UTF_8));
+
+ assertEquals("xxx",UrlEncoded.decodeString("xxx",0,3,StandardCharsets.UTF_8));
+ assertEquals("xxx\ufffd",UrlEncoded.decodeString("xxx%",0,4,StandardCharsets.UTF_8));
+ assertEquals("xxx\ufffd",UrlEncoded.decodeString("xxx%u",0,5,StandardCharsets.UTF_8));
+ assertEquals("xxx\ufffd",UrlEncoded.decodeString("xxx%u1",0,6,StandardCharsets.UTF_8));
+ assertEquals("xxx\ufffd",UrlEncoded.decodeString("xxx%u12",0,7,StandardCharsets.UTF_8));
+ assertEquals("xxx\ufffd",UrlEncoded.decodeString("xxx%u123",0,8,StandardCharsets.UTF_8));
+ assertEquals("xxx\u1234",UrlEncoded.decodeString("xxx%u1234",0,9,StandardCharsets.UTF_8));
}
@@ -224,7 +225,7 @@ public class URLEncodedTest
if (java.nio.charset.Charset.isSupported("Shift_JIS"))
{
- ByteArrayInputStream in2 = new ByteArrayInputStream ("name=%83e%83X%83g".getBytes(StringUtil.__ISO_8859_1));
+ ByteArrayInputStream in2 = new ByteArrayInputStream("name=%83e%83X%83g".getBytes(StandardCharsets.ISO_8859_1));
MultiMap<String> m2 = new MultiMap<>();
UrlEncoded.decodeTo(in2, m2, Charset.forName("Shift_JIS"), -1,-1);
assertEquals("stream length",1,m2.size());
@@ -278,12 +279,12 @@ public class URLEncodedTest
MultiMap<String> map = new MultiMap<>();
UrlEncoded.LOG.info("EXPECT 4 Not Valid UTF8 warnings...");
- UrlEncoded.decodeUtf8To(query.getBytes(StringUtil.__ISO_8859_1),0,query.length(),map);
+ UrlEncoded.decodeUtf8To(query.getBytes(StandardCharsets.ISO_8859_1),0,query.length(),map);
assertEquals("X"+Utf8Appendable.REPLACEMENT+Utf8Appendable.REPLACEMENT+"Z",map.getValue("name",0));
map.clear();
- UrlEncoded.decodeUtf8To(new ByteArrayInputStream(query.getBytes(StringUtil.__ISO_8859_1)),map,100,2);
+ UrlEncoded.decodeUtf8To(new ByteArrayInputStream(query.getBytes(StandardCharsets.ISO_8859_1)),map,100,2);
assertEquals("X"+Utf8Appendable.REPLACEMENT+Utf8Appendable.REPLACEMENT+"Z",map.getValue("name",0));
}
}
diff --git a/jetty-util/src/test/java/org/eclipse/jetty/util/Utf8LineParserTest.java b/jetty-util/src/test/java/org/eclipse/jetty/util/Utf8LineParserTest.java
index eec5684..8a99eb5 100644
--- a/jetty-util/src/test/java/org/eclipse/jetty/util/Utf8LineParserTest.java
+++ b/jetty-util/src/test/java/org/eclipse/jetty/util/Utf8LineParserTest.java
@@ -32,7 +32,7 @@ public class Utf8LineParserTest
{
private void appendUtf8(ByteBuffer buf, String line)
{
- buf.put(ByteBuffer.wrap(StringUtil.getBytes(line,StringUtil.__UTF8)));
+ buf.put(ByteBuffer.wrap(StringUtil.getUtf8Bytes(line)));
}
private void assertEquals(List<String> expected, List<String> actual)
diff --git a/jetty-util/src/test/java/org/eclipse/jetty/util/Utf8StringBufferTest.java b/jetty-util/src/test/java/org/eclipse/jetty/util/Utf8StringBufferTest.java
index ab9371f..a622e01 100644
--- a/jetty-util/src/test/java/org/eclipse/jetty/util/Utf8StringBufferTest.java
+++ b/jetty-util/src/test/java/org/eclipse/jetty/util/Utf8StringBufferTest.java
@@ -22,6 +22,7 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.io.UnsupportedEncodingException;
+import java.nio.charset.StandardCharsets;
import org.junit.Test;
@@ -31,7 +32,7 @@ public class Utf8StringBufferTest
public void testUtfStringBuffer() throws Exception
{
String source = "abcd012345\n\r\u0000\u00a4\u10fb\ufffdjetty";
- byte[] bytes = source.getBytes(StringUtil.__UTF8);
+ byte[] bytes = source.getBytes(StandardCharsets.UTF_8);
Utf8StringBuffer buffer = new Utf8StringBuffer();
for (byte aByte : bytes)
buffer.append(aByte);
@@ -43,7 +44,7 @@ public class Utf8StringBufferTest
public void testUtf8WithMissingByte() throws Exception
{
String source = "abc\u10fb";
- byte[] bytes = source.getBytes(StringUtil.__UTF8);
+ byte[] bytes = source.getBytes(StandardCharsets.UTF_8);
Utf8StringBuffer buffer = new Utf8StringBuffer();
for (int i = 0; i < bytes.length - 1; i++)
buffer.append(bytes[i]);
@@ -54,7 +55,7 @@ public class Utf8StringBufferTest
public void testUtf8WithAdditionalByte() throws Exception
{
String source = "abcXX";
- byte[] bytes = source.getBytes(StringUtil.__UTF8);
+ byte[] bytes = source.getBytes(StandardCharsets.UTF_8);
bytes[3] = (byte)0xc0;
bytes[4] = (byte)0x00;
@@ -68,9 +69,9 @@ public class Utf8StringBufferTest
public void testUTF32codes() throws Exception
{
String source = "\uD842\uDF9F";
- byte[] bytes = source.getBytes("UTF-8");
+ byte[] bytes = source.getBytes(StandardCharsets.UTF_8);
- String jvmcheck = new String(bytes,0,bytes.length,"UTF-8");
+ String jvmcheck = new String(bytes,0,bytes.length,StandardCharsets.UTF_8);
assertEquals(source,jvmcheck);
Utf8StringBuffer buffer = new Utf8StringBuffer();
diff --git a/jetty-util/src/test/java/org/eclipse/jetty/util/Utf8StringBuilderTest.java b/jetty-util/src/test/java/org/eclipse/jetty/util/Utf8StringBuilderTest.java
index 2af6be0..9967074 100644
--- a/jetty-util/src/test/java/org/eclipse/jetty/util/Utf8StringBuilderTest.java
+++ b/jetty-util/src/test/java/org/eclipse/jetty/util/Utf8StringBuilderTest.java
@@ -24,6 +24,8 @@ import static org.junit.Assert.assertTrue;
import org.junit.Assert;
import org.junit.Test;
+import java.nio.charset.StandardCharsets;
+
public class Utf8StringBuilderTest
{
@Test
@@ -76,7 +78,7 @@ public class Utf8StringBuilderTest
public void testUtfStringBuilder() throws Exception
{
String source = "abcd012345\n\r\u0000\u00a4\u10fb\ufffdjetty";
- byte[] bytes = source.getBytes(StringUtil.__UTF8);
+ byte[] bytes = source.getBytes(StandardCharsets.UTF_8);
Utf8StringBuilder buffer = new Utf8StringBuilder();
for (byte aByte : bytes)
buffer.append(aByte);
@@ -88,7 +90,7 @@ public class Utf8StringBuilderTest
public void testShort() throws Exception
{
String source = "abc\u10fb";
- byte[] bytes = source.getBytes(StringUtil.__UTF8);
+ byte[] bytes = source.getBytes(StandardCharsets.UTF_8);
Utf8StringBuilder buffer = new Utf8StringBuilder();
for (int i = 0; i < bytes.length - 1; i++)
buffer.append(bytes[i]);
@@ -99,7 +101,7 @@ public class Utf8StringBuilderTest
public void testLong() throws Exception
{
String source = "abcXX";
- byte[] bytes = source.getBytes(StringUtil.__UTF8);
+ byte[] bytes = source.getBytes(StandardCharsets.UTF_8);
bytes[3] = (byte)0xc0;
bytes[4] = (byte)0x00;
@@ -122,9 +124,9 @@ public class Utf8StringBuilderTest
public void testUTF32codes() throws Exception
{
String source = "\uD842\uDF9F";
- byte[] bytes = source.getBytes("UTF-8");
+ byte[] bytes = source.getBytes(StandardCharsets.UTF_8);
- String jvmcheck = new String(bytes,0,bytes.length,"UTF-8");
+ String jvmcheck = new String(bytes,0,bytes.length,StandardCharsets.UTF_8);
assertEquals(source,jvmcheck);
Utf8StringBuilder buffer = new Utf8StringBuilder();
diff --git a/jetty-util/src/test/java/org/eclipse/jetty/util/log/StdErrLogTest.java b/jetty-util/src/test/java/org/eclipse/jetty/util/log/StdErrLogTest.java
index 5386e09..dfd0317 100644
--- a/jetty-util/src/test/java/org/eclipse/jetty/util/log/StdErrLogTest.java
+++ b/jetty-util/src/test/java/org/eclipse/jetty/util/log/StdErrLogTest.java
@@ -26,6 +26,7 @@ import java.io.PrintStream;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.io.UnsupportedEncodingException;
+import java.nio.charset.StandardCharsets;
import java.util.Properties;
import org.junit.Assert;
@@ -647,7 +648,7 @@ public class StdErrLogTest
log.debug("Show me the source!");
- String output = new String(test.toByteArray(),"UTF-8");
+ String output = new String(test.toByteArray(), StandardCharsets.UTF_8);
// System.err.print(output);
Assert.assertThat(output, containsString(".StdErrLogTest#testPrintSource(StdErrLogTest.java:"));
diff --git a/jetty-util/src/test/java/org/eclipse/jetty/util/resource/FileResourceTest.java b/jetty-util/src/test/java/org/eclipse/jetty/util/resource/FileResourceTest.java
index 2667493..5c754c5 100644
--- a/jetty-util/src/test/java/org/eclipse/jetty/util/resource/FileResourceTest.java
+++ b/jetty-util/src/test/java/org/eclipse/jetty/util/resource/FileResourceTest.java
@@ -26,6 +26,7 @@ import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
+import java.nio.charset.StandardCharsets;
import org.eclipse.jetty.toolchain.test.OS;
import org.eclipse.jetty.toolchain.test.TestingDir;
@@ -52,7 +53,7 @@ public class FileResourceTest
private URL decode(URL url) throws MalformedURLException
{
String raw = url.toExternalForm();
- String decoded = UrlEncoded.decodeString(raw,0,raw.length(),StringUtil.__UTF8_CHARSET);
+ String decoded = UrlEncoded.decodeString(raw,0,raw.length(), StandardCharsets.UTF_8);
return new URL(decoded);
}
diff --git a/jetty-websocket/websocket-api/src/main/java/org/eclipse/jetty/websocket/api/io/WebSocketWriter.java b/jetty-websocket/websocket-api/src/main/java/org/eclipse/jetty/websocket/api/io/WebSocketWriter.java
index abd194d..43db5aa 100644
--- a/jetty-websocket/websocket-api/src/main/java/org/eclipse/jetty/websocket/api/io/WebSocketWriter.java
+++ b/jetty-websocket/websocket-api/src/main/java/org/eclipse/jetty/websocket/api/io/WebSocketWriter.java
@@ -20,13 +20,11 @@ package org.eclipse.jetty.websocket.api.io;
import java.io.IOException;
import java.io.Writer;
-import java.nio.charset.Charset;
import org.eclipse.jetty.websocket.api.Session;
public class WebSocketWriter extends Writer
{
- private final Charset charset = Charset.forName("UTF-8");
private final Session session;
public WebSocketWriter(Session session)
diff --git a/jetty-websocket/websocket-client/src/main/java/org/eclipse/jetty/websocket/client/ClientUpgradeRequest.java b/jetty-websocket/websocket-client/src/main/java/org/eclipse/jetty/websocket/client/ClientUpgradeRequest.java
index 282ef1e..94b9a16 100644
--- a/jetty-websocket/websocket-client/src/main/java/org/eclipse/jetty/websocket/client/ClientUpgradeRequest.java
+++ b/jetty-websocket/websocket-client/src/main/java/org/eclipse/jetty/websocket/client/ClientUpgradeRequest.java
@@ -21,6 +21,7 @@ package org.eclipse.jetty.websocket.client;
import java.net.CookieStore;
import java.net.HttpCookie;
import java.net.URI;
+import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
@@ -222,7 +223,7 @@ public class ClientUpgradeRequest extends UpgradeRequest
if (StringUtil.isNotBlank(query))
{
MultiMap<String> params = new MultiMap<String>();
- UrlEncoded.decodeTo(uri.getQuery(),params,"UTF-8",MAX_KEYS);
+ UrlEncoded.decodeTo(uri.getQuery(),params,StandardCharsets.UTF_8,MAX_KEYS);
for (String key : params.keySet())
{
diff --git a/jetty-websocket/websocket-client/src/main/java/org/eclipse/jetty/websocket/client/io/UpgradeConnection.java b/jetty-websocket/websocket-client/src/main/java/org/eclipse/jetty/websocket/client/io/UpgradeConnection.java
index 9818918..8305e7f 100644
--- a/jetty-websocket/websocket-client/src/main/java/org/eclipse/jetty/websocket/client/io/UpgradeConnection.java
+++ b/jetty-websocket/websocket-client/src/main/java/org/eclipse/jetty/websocket/client/io/UpgradeConnection.java
@@ -21,6 +21,7 @@ package org.eclipse.jetty.websocket.client.io;
import java.io.IOException;
import java.net.URI;
import java.nio.ByteBuffer;
+import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Executor;
@@ -62,7 +63,7 @@ public class UpgradeConnection extends AbstractConnection
request.setRequestURI(uri);
String rawRequest = request.generate();
- ByteBuffer buf = BufferUtil.toBuffer(rawRequest,StringUtil.__UTF8_CHARSET);
+ ByteBuffer buf = BufferUtil.toBuffer(rawRequest, StandardCharsets.UTF_8);
getEndPoint().write(this,buf);
}
diff --git a/jetty-websocket/websocket-client/src/test/java/org/eclipse/jetty/websocket/client/examples/TestClient.java b/jetty-websocket/websocket-client/src/test/java/org/eclipse/jetty/websocket/client/examples/TestClient.java
index f797421..2ab4898 100644
--- a/jetty-websocket/websocket-client/src/test/java/org/eclipse/jetty/websocket/client/examples/TestClient.java
+++ b/jetty-websocket/websocket-client/src/test/java/org/eclipse/jetty/websocket/client/examples/TestClient.java
@@ -20,6 +20,7 @@ package org.eclipse.jetty.websocket.client.examples;
import java.net.InetSocketAddress;
import java.net.URI;
+import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.Random;
import java.util.concurrent.BlockingQueue;
@@ -208,7 +209,7 @@ public class TestClient
{
b.append('A' + __random.nextInt(26));
}
- data = b.toString().getBytes(StringUtil.__UTF8_CHARSET);
+ data = b.toString().getBytes(StandardCharsets.UTF_8);
break;
}
case OpCode.BINARY:
diff --git a/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/AcceptHash.java b/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/AcceptHash.java
index c4d5ba2..83027c0 100644
--- a/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/AcceptHash.java
+++ b/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/AcceptHash.java
@@ -19,6 +19,7 @@
package org.eclipse.jetty.websocket.common;
import java.io.UnsupportedEncodingException;
+import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import org.eclipse.jetty.util.B64Code;
@@ -36,19 +37,7 @@ public class AcceptHash
* <p>
* See <a href="https://tools.ietf.org/html/rfc6455#section-1.3">Opening Handshake (Section 1.3)</a>
*/
- private final static byte[] MAGIC;
-
- static
- {
- try
- {
- MAGIC = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11".getBytes(StringUtil.__ISO_8859_1);
- }
- catch (UnsupportedEncodingException e)
- {
- throw new RuntimeException(e);
- }
- }
+ private final static byte[] MAGIC = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11".getBytes(StandardCharsets.ISO_8859_1);
/**
* Concatenate the provided key with the Magic GUID and return the Base64 encoded form.
@@ -62,7 +51,7 @@ public class AcceptHash
try
{
MessageDigest md = MessageDigest.getInstance("SHA1");
- md.update(key.getBytes("UTF-8"));
+ md.update(key.getBytes(StandardCharsets.UTF_8));
md.update(MAGIC);
return new String(B64Code.encode(md.digest()));
}
diff --git a/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/WebSocketFrame.java b/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/WebSocketFrame.java
index 750e07e..869a122 100644
--- a/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/WebSocketFrame.java
+++ b/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/WebSocketFrame.java
@@ -19,6 +19,7 @@
package org.eclipse.jetty.websocket.common;
import java.nio.ByteBuffer;
+import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import org.eclipse.jetty.util.BufferUtil;
@@ -661,7 +662,7 @@ public class WebSocketFrame implements Frame
public WebSocketFrame setPayload(String str)
{
- setPayload(BufferUtil.toBuffer(str,StringUtil.__UTF8_CHARSET));
+ setPayload(BufferUtil.toBuffer(str, StandardCharsets.UTF_8));
return this;
}
diff --git a/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/WebSocketSession.java b/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/WebSocketSession.java
index fefff4e..1b79f3b 100644
--- a/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/WebSocketSession.java
+++ b/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/WebSocketSession.java
@@ -21,6 +21,7 @@ package org.eclipse.jetty.websocket.common;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.URI;
+import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -89,7 +90,7 @@ public class WebSocketSession extends ContainerLifeCycle implements Session, Inc
String query = requestURI.getQuery();
if (StringUtil.isNotBlank(query))
{
- UrlEncoded.decodeTo(query,params,StringUtil.__UTF8_CHARSET,-1);
+ UrlEncoded.decodeTo(query,params, StandardCharsets.UTF_8,-1);
}
for (String name : params.keySet())
diff --git a/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/extensions/mux/op/MuxAddChannelRequest.java b/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/extensions/mux/op/MuxAddChannelRequest.java
index 64fb928..62e1fc0 100644
--- a/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/extensions/mux/op/MuxAddChannelRequest.java
+++ b/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/extensions/mux/op/MuxAddChannelRequest.java
@@ -19,6 +19,7 @@
package org.eclipse.jetty.websocket.common.extensions.mux.op;
import java.nio.ByteBuffer;
+import java.nio.charset.StandardCharsets;
import org.eclipse.jetty.util.BufferUtil;
import org.eclipse.jetty.util.StringUtil;
@@ -104,7 +105,7 @@ public class MuxAddChannelRequest implements MuxControlBlock
public void setHandshake(String rawstring)
{
- setHandshake(BufferUtil.toBuffer(rawstring,StringUtil.__UTF8_CHARSET));
+ setHandshake(BufferUtil.toBuffer(rawstring, StandardCharsets.UTF_8));
}
public void setRsv(byte rsv)
diff --git a/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/extensions/mux/op/MuxAddChannelResponse.java b/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/extensions/mux/op/MuxAddChannelResponse.java
index a30b6ec..6273a7c 100644
--- a/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/extensions/mux/op/MuxAddChannelResponse.java
+++ b/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/extensions/mux/op/MuxAddChannelResponse.java
@@ -19,6 +19,7 @@
package org.eclipse.jetty.websocket.common.extensions.mux.op;
import java.nio.ByteBuffer;
+import java.nio.charset.StandardCharsets;
import org.eclipse.jetty.util.BufferUtil;
import org.eclipse.jetty.util.StringUtil;
@@ -115,7 +116,7 @@ public class MuxAddChannelResponse implements MuxControlBlock
public void setHandshake(String responseHandshake)
{
- setHandshake(BufferUtil.toBuffer(responseHandshake,StringUtil.__UTF8_CHARSET));
+ setHandshake(BufferUtil.toBuffer(responseHandshake, StandardCharsets.UTF_8));
}
public void setRsv(byte rsv)
diff --git a/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/ClosePayloadParserTest.java b/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/ClosePayloadParserTest.java
index 4fe7cf2..defae5b 100644
--- a/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/ClosePayloadParserTest.java
+++ b/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/ClosePayloadParserTest.java
@@ -21,6 +21,7 @@ package org.eclipse.jetty.websocket.common;
import static org.hamcrest.Matchers.*;
import java.nio.ByteBuffer;
+import java.nio.charset.StandardCharsets;
import org.eclipse.jetty.util.StringUtil;
import org.eclipse.jetty.websocket.api.StatusCode;
@@ -36,7 +37,7 @@ public class ClosePayloadParserTest
{
String expectedReason = "Game Over";
- byte utf[] = expectedReason.getBytes(StringUtil.__UTF8_CHARSET);
+ byte utf[] = expectedReason.getBytes(StandardCharsets.UTF_8);
ByteBuffer payload = ByteBuffer.allocate(utf.length + 2);
payload.putChar((char)StatusCode.NORMAL);
payload.put(utf,0,utf.length);
diff --git a/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/TextPayloadParserTest.java b/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/TextPayloadParserTest.java
index ccfb53f..9dae24d 100644
--- a/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/TextPayloadParserTest.java
+++ b/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/TextPayloadParserTest.java
@@ -21,6 +21,7 @@ package org.eclipse.jetty.websocket.common;
import static org.hamcrest.Matchers.*;
import java.nio.ByteBuffer;
+import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import org.eclipse.jetty.util.StringUtil;
@@ -75,7 +76,7 @@ public class TextPayloadParserTest
sb.append(". The end.");
String expectedText = sb.toString();
- byte utf[] = expectedText.getBytes(StringUtil.__UTF8);
+ byte utf[] = expectedText.getBytes(StandardCharsets.UTF_8);
Assert.assertThat("Must be a long length payload",utf.length,greaterThan(0xFFFF));
@@ -111,7 +112,7 @@ public class TextPayloadParserTest
sb.append(". The end.");
String expectedText = sb.toString();
- byte utf[] = expectedText.getBytes(StringUtil.__UTF8);
+ byte utf[] = expectedText.getBytes(StandardCharsets.UTF_8);
Assert.assertThat("Must be a medium length payload",utf.length,allOf(greaterThan(0x7E),lessThan(0xFFFF)));
@@ -141,8 +142,8 @@ public class TextPayloadParserTest
String part1 = "Hello ";
String part2 = "World";
- byte b1[] = part1.getBytes(StringUtil.__UTF8_CHARSET);
- byte b2[] = part2.getBytes(StringUtil.__UTF8_CHARSET);
+ byte b1[] = part1.getBytes(StandardCharsets.UTF_8);
+ byte b2[] = part2.getBytes(StandardCharsets.UTF_8);
ByteBuffer buf = ByteBuffer.allocate(32);
@@ -178,7 +179,7 @@ public class TextPayloadParserTest
public void testShortMaskedText() throws Exception
{
String expectedText = "Hello World";
- byte utf[] = expectedText.getBytes(StringUtil.__UTF8_CHARSET);
+ byte utf[] = expectedText.getBytes(StandardCharsets.UTF_8);
ByteBuffer buf = ByteBuffer.allocate(24);
buf.put((byte)0x81);
@@ -204,7 +205,7 @@ public class TextPayloadParserTest
{
String expectedText = "Hell\uFF4f W\uFF4Frld";
- byte utf[] = expectedText.getBytes(StringUtil.__UTF8);
+ byte utf[] = expectedText.getBytes(StandardCharsets.UTF_8);
ByteBuffer buf = ByteBuffer.allocate(24);
buf.put((byte)0x81);
diff --git a/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/ab/TestABCase7_3.java b/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/ab/TestABCase7_3.java
index 4a3bd82..117e8f8 100644
--- a/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/ab/TestABCase7_3.java
+++ b/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/ab/TestABCase7_3.java
@@ -21,6 +21,7 @@ package org.eclipse.jetty.websocket.common.ab;
import static org.hamcrest.Matchers.*;
import java.nio.ByteBuffer;
+import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import org.eclipse.jetty.util.BufferUtil;
@@ -234,7 +235,7 @@ public class TestABCase7_3
ByteBuffer actual = generator.generate(close.asFrame());
ByteBuffer expected = ByteBuffer.allocate(132);
- byte messageBytes[] = message.toString().getBytes(StringUtil.__UTF8_CHARSET);
+ byte messageBytes[] = message.toString().getBytes(StandardCharsets.UTF_8);
expected.put(new byte[]
{ (byte)0x88 });
@@ -260,7 +261,7 @@ public class TestABCase7_3
message.append("*");
}
- byte[] messageBytes = message.toString().getBytes(StringUtil.__UTF8_CHARSET);
+ byte[] messageBytes = message.toString().getBytes(StandardCharsets.UTF_8);
ByteBuffer expected = ByteBuffer.allocate(132);
diff --git a/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/extensions/FragmentExtensionTest.java b/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/extensions/FragmentExtensionTest.java
index c7b67cd..ce740e0 100644
--- a/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/extensions/FragmentExtensionTest.java
+++ b/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/extensions/FragmentExtensionTest.java
@@ -22,6 +22,7 @@ import static org.hamcrest.Matchers.*;
import java.io.IOException;
import java.nio.ByteBuffer;
+import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
@@ -89,7 +90,7 @@ public class FragmentExtensionTest
Assert.assertThat(prefix + ".rsv2",actual.isRsv2(),is(false));
Assert.assertThat(prefix + ".rsv3",actual.isRsv3(),is(false));
- ByteBuffer expected = BufferUtil.toBuffer(quote.get(i),StringUtil.__UTF8_CHARSET);
+ ByteBuffer expected = BufferUtil.toBuffer(quote.get(i),StandardCharsets.UTF_8);
Assert.assertThat(prefix + ".payloadLength",actual.getPayloadLength(),is(expected.remaining()));
ByteBufferAssert.assertEquals(prefix + ".payload",expected,actual.getPayload().slice());
}
@@ -125,7 +126,7 @@ public class FragmentExtensionTest
Assert.assertThat("Frame.rsv2",actual.isRsv2(),is(false));
Assert.assertThat("Frame.rsv3",actual.isRsv3(),is(false));
- ByteBuffer expected = BufferUtil.toBuffer(payload,StringUtil.__UTF8_CHARSET);
+ ByteBuffer expected = BufferUtil.toBuffer(payload,StandardCharsets.UTF_8);
Assert.assertThat("Frame.payloadLength",actual.getPayloadLength(),is(expected.remaining()));
ByteBufferAssert.assertEquals("Frame.payload",expected,actual.getPayload().slice());
}
@@ -295,7 +296,7 @@ public class FragmentExtensionTest
Assert.assertThat("Frame.rsv2",actual.isRsv2(),is(false));
Assert.assertThat("Frame.rsv3",actual.isRsv3(),is(false));
- ByteBuffer expected = BufferUtil.toBuffer(payload,StringUtil.__UTF8_CHARSET);
+ ByteBuffer expected = BufferUtil.toBuffer(payload,StandardCharsets.UTF_8);
Assert.assertThat("Frame.payloadLength",actual.getPayloadLength(),is(expected.remaining()));
ByteBufferAssert.assertEquals("Frame.payload",expected,actual.getPayload().slice());
}
diff --git a/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/extensions/IdentityExtensionTest.java b/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/extensions/IdentityExtensionTest.java
index b1a4528..217c2eb 100644
--- a/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/extensions/IdentityExtensionTest.java
+++ b/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/extensions/IdentityExtensionTest.java
@@ -22,6 +22,7 @@ import static org.hamcrest.Matchers.*;
import java.io.IOException;
import java.nio.ByteBuffer;
+import java.nio.charset.StandardCharsets;
import org.eclipse.jetty.util.BufferUtil;
import org.eclipse.jetty.util.StringUtil;
@@ -62,7 +63,7 @@ public class IdentityExtensionTest
Assert.assertThat("Frame.rsv2",actual.isRsv2(),is(false));
Assert.assertThat("Frame.rsv3",actual.isRsv3(),is(false));
- ByteBuffer expected = BufferUtil.toBuffer("hello",StringUtil.__UTF8_CHARSET);
+ ByteBuffer expected = BufferUtil.toBuffer("hello",StandardCharsets.UTF_8);
Assert.assertThat("Frame.payloadLength",actual.getPayloadLength(),is(expected.remaining()));
ByteBufferAssert.assertEquals("Frame.payload",expected,actual.getPayload().slice());
}
@@ -92,7 +93,7 @@ public class IdentityExtensionTest
Assert.assertThat("Frame.rsv2",actual.isRsv2(),is(false));
Assert.assertThat("Frame.rsv3",actual.isRsv3(),is(false));
- ByteBuffer expected = BufferUtil.toBuffer("hello",StringUtil.__UTF8_CHARSET);
+ ByteBuffer expected = BufferUtil.toBuffer("hello",StandardCharsets.UTF_8);
Assert.assertThat("Frame.payloadLength",actual.getPayloadLength(),is(expected.remaining()));
ByteBufferAssert.assertEquals("Frame.payload",expected,actual.getPayload().slice());
}
diff --git a/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/extensions/compress/DeflateCompressionMethodTest.java b/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/extensions/compress/DeflateCompressionMethodTest.java
index 32f741e..92d3f55 100644
--- a/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/extensions/compress/DeflateCompressionMethodTest.java
+++ b/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/extensions/compress/DeflateCompressionMethodTest.java
@@ -21,6 +21,7 @@ package org.eclipse.jetty.websocket.common.extensions.compress;
import static org.hamcrest.Matchers.*;
import java.nio.ByteBuffer;
+import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;
@@ -43,7 +44,7 @@ public class DeflateCompressionMethodTest
{
String expected = msg.toString();
- ByteBuffer orig = BufferUtil.toBuffer(expected,StringUtil.__UTF8_CHARSET);
+ ByteBuffer orig = BufferUtil.toBuffer(expected,StandardCharsets.UTF_8);
LOG.debug("orig: {}",BufferUtil.toDetailString(orig));
diff --git a/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/extensions/compress/FrameCompressionExtensionTest.java b/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/extensions/compress/FrameCompressionExtensionTest.java
index 68f4730..84f87b9 100644
--- a/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/extensions/compress/FrameCompressionExtensionTest.java
+++ b/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/extensions/compress/FrameCompressionExtensionTest.java
@@ -22,6 +22,7 @@ import static org.hamcrest.Matchers.*;
import java.io.IOException;
import java.nio.ByteBuffer;
+import java.nio.charset.StandardCharsets;
import java.util.Collections;
import java.util.zip.Deflater;
import java.util.zip.Inflater;
@@ -84,7 +85,7 @@ public class FrameCompressionExtensionTest
Assert.assertThat(prefix + ".rsv2",actual.isRsv2(),is(false));
Assert.assertThat(prefix + ".rsv3",actual.isRsv3(),is(false));
- ByteBuffer expected = BufferUtil.toBuffer(expectedTextDatas[i],StringUtil.__UTF8_CHARSET);
+ ByteBuffer expected = BufferUtil.toBuffer(expectedTextDatas[i],StandardCharsets.UTF_8);
Assert.assertThat(prefix + ".payloadLength",actual.getPayloadLength(),is(expected.remaining()));
ByteBufferAssert.assertEquals(prefix + ".payload",expected,actual.getPayload().slice());
}
diff --git a/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/extensions/compress/MessageCompressionExtensionTest.java b/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/extensions/compress/MessageCompressionExtensionTest.java
index 3f8c96d..546261d 100644
--- a/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/extensions/compress/MessageCompressionExtensionTest.java
+++ b/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/extensions/compress/MessageCompressionExtensionTest.java
@@ -22,6 +22,7 @@ import static org.hamcrest.Matchers.*;
import java.io.IOException;
import java.nio.ByteBuffer;
+import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
@@ -84,7 +85,7 @@ public class MessageCompressionExtensionTest
Assert.assertThat(prefix + ".rsv2",actual.isRsv2(),is(false));
Assert.assertThat(prefix + ".rsv3",actual.isRsv3(),is(false));
- ByteBuffer expected = BufferUtil.toBuffer(expectedStr,StringUtil.__UTF8_CHARSET);
+ ByteBuffer expected = BufferUtil.toBuffer(expectedStr, StandardCharsets.UTF_8);
Assert.assertThat(prefix + ".payloadLength",actual.getPayloadLength(),is(expected.remaining()));
ByteBufferAssert.assertEquals(prefix + ".payload",expected,actual.getPayload().slice());
}
@@ -188,7 +189,7 @@ public class MessageCompressionExtensionTest
Assert.assertThat("Frame.rsv2",actual.isRsv2(),is(false));
Assert.assertThat("Frame.rsv3",actual.isRsv3(),is(false));
- ByteBuffer expected = BufferUtil.toBuffer(payload,StringUtil.__UTF8_CHARSET);
+ ByteBuffer expected = BufferUtil.toBuffer(payload,StandardCharsets.UTF_8);
Assert.assertThat("Frame.payloadLength",actual.getPayloadLength(),is(expected.remaining()));
ByteBufferAssert.assertEquals("Frame.payload",expected,actual.getPayload().slice());
}
@@ -243,7 +244,7 @@ public class MessageCompressionExtensionTest
Assert.assertThat(prefix + ".rsv2",actual.isRsv2(),is(false));
Assert.assertThat(prefix + ".rsv3",actual.isRsv3(),is(false));
- ByteBuffer expected = BufferUtil.toBuffer(quote.get(i),StringUtil.__UTF8_CHARSET);
+ ByteBuffer expected = BufferUtil.toBuffer(quote.get(i),StandardCharsets.UTF_8);
Assert.assertThat(prefix + ".payloadLength",actual.getPayloadLength(),is(expected.remaining()));
ByteBufferAssert.assertEquals(prefix + ".payload",expected,actual.getPayload().slice());
}
@@ -279,7 +280,7 @@ public class MessageCompressionExtensionTest
for(String part: quote) {
Process process = method.compress();
process.begin();
- process.input(BufferUtil.toBuffer(part,StringUtil.__UTF8_CHARSET));
+ process.input(BufferUtil.toBuffer(part,StandardCharsets.UTF_8));
expectedBuffers.add(process.process());
process.end();
}
@@ -353,7 +354,7 @@ public class MessageCompressionExtensionTest
Assert.assertThat("Frame.rsv2",actual.isRsv2(),is(false));
Assert.assertThat("Frame.rsv3",actual.isRsv3(),is(false));
- ByteBuffer expected = BufferUtil.toBuffer(payload,StringUtil.__UTF8_CHARSET);
+ ByteBuffer expected = BufferUtil.toBuffer(payload,StandardCharsets.UTF_8);
Assert.assertThat("Frame.payloadLength",actual.getPayloadLength(),is(expected.remaining()));
ByteBufferAssert.assertEquals("Frame.payload",expected,actual.getPayload().slice());
}
diff --git a/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/extensions/mux/MuxParserRFCTest.java b/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/extensions/mux/MuxParserRFCTest.java
index 332fa4e..5eceb20 100644
--- a/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/extensions/mux/MuxParserRFCTest.java
+++ b/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/extensions/mux/MuxParserRFCTest.java
@@ -23,6 +23,7 @@ import static org.hamcrest.Matchers.*;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
+import java.nio.charset.StandardCharsets;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
@@ -236,7 +237,7 @@ public class MuxParserRFCTest
}
else
{
- out.write(part.getBytes(StringUtil.__UTF8_CHARSET));
+ out.write(part.getBytes(StandardCharsets.UTF_8));
}
}
return out.toByteArray();
diff --git a/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/io/http/HttpResponseHeaderParserTest.java b/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/io/http/HttpResponseHeaderParserTest.java
index 837cf10..7532b0d 100644
--- a/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/io/http/HttpResponseHeaderParserTest.java
+++ b/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/io/http/HttpResponseHeaderParserTest.java
@@ -22,6 +22,7 @@ import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
import java.nio.ByteBuffer;
+import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;
@@ -39,7 +40,7 @@ public class HttpResponseHeaderParserTest
private void appendUtf8(ByteBuffer buf, String line)
{
- buf.put(ByteBuffer.wrap(StringUtil.getBytes(line,StringUtil.__UTF8)));
+ buf.put(ByteBuffer.wrap(StringUtil.getUtf8Bytes(line)));
}
@Test
@@ -56,7 +57,7 @@ public class HttpResponseHeaderParserTest
// and some body content
resp.append("What you are looking for is not here\r\n");
- ByteBuffer buf = BufferUtil.toBuffer(resp.toString(),StringUtil.__UTF8_CHARSET);
+ ByteBuffer buf = BufferUtil.toBuffer(resp.toString(),StandardCharsets.UTF_8);
HttpResponseParseCapture capture = new HttpResponseParseCapture();
HttpResponseHeaderParser parser = new HttpResponseHeaderParser(capture);
@@ -178,7 +179,7 @@ public class HttpResponseHeaderParserTest
resp.append("Sec-WebSocket-Protocol: chat\r\n");
resp.append("\r\n");
- ByteBuffer buf = BufferUtil.toBuffer(resp.toString(),StringUtil.__UTF8_CHARSET);
+ ByteBuffer buf = BufferUtil.toBuffer(resp.toString(),StandardCharsets.UTF_8);
HttpResponseParseCapture capture = new HttpResponseParseCapture();
HttpResponseHeaderParser parser = new HttpResponseHeaderParser(capture);
diff --git a/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/blockhead/BlockheadClient.java b/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/blockhead/BlockheadClient.java
index 8573c93..601919a 100644
--- a/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/blockhead/BlockheadClient.java
+++ b/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/blockhead/BlockheadClient.java
@@ -33,6 +33,7 @@ import java.net.SocketTimeoutException;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.ByteBuffer;
+import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CountDownLatch;
@@ -718,7 +719,7 @@ public class BlockheadClient implements IncomingFrames, OutgoingFrames, Connecti
public void writeRaw(String str) throws IOException
{
LOG.debug("write((String)[{}]){}{})",str.length(),'\n',str);
- out.write(StringUtil.getBytes(str,StringUtil.__ISO_8859_1));
+ out.write(str.getBytes(StandardCharsets.ISO_8859_1));
}
public void writeRawSlowly(ByteBuffer buf, int segmentSize) throws IOException
diff --git a/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/helper/SafariD00.java b/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/helper/SafariD00.java
index d720634..faced9e 100644
--- a/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/helper/SafariD00.java
+++ b/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/helper/SafariD00.java
@@ -29,6 +29,7 @@ import java.net.Socket;
import java.net.SocketAddress;
import java.net.URI;
import java.nio.ByteBuffer;
+import java.nio.charset.StandardCharsets;
import org.eclipse.jetty.util.BufferUtil;
import org.eclipse.jetty.util.TypeUtil;
@@ -91,7 +92,7 @@ public class SafariD00
// System.out.printf("--- Request ---%n%s",req);
- byte reqBytes[] = req.toString().getBytes("UTF-8");
+ byte reqBytes[] = req.toString().getBytes(StandardCharsets.UTF_8);
byte hixieBytes[] = TypeUtil.fromHexString("e739617916c9daf3");
byte buf[] = new byte[reqBytes.length + hixieBytes.length];
System.arraycopy(reqBytes,0,buf,0,reqBytes.length);
@@ -140,7 +141,7 @@ public class SafariD00
for (String msg : msgs)
{
buf.put((byte)0x00);
- buf.put(msg.getBytes("UTF-8"));
+ buf.put(msg.getBytes(StandardCharsets.UTF_8));
buf.put((byte)0xFF);
}
diff --git a/tests/test-continuation/src/test/java/org/eclipse/jetty/continuation/ContinuationBase.java b/tests/test-continuation/src/test/java/org/eclipse/jetty/continuation/ContinuationBase.java
index 5369abe..f40991d 100644
--- a/tests/test-continuation/src/test/java/org/eclipse/jetty/continuation/ContinuationBase.java
+++ b/tests/test-continuation/src/test/java/org/eclipse/jetty/continuation/ContinuationBase.java
@@ -27,6 +27,7 @@ import static org.junit.Assert.assertThat;
import java.io.IOException;
import java.io.InputStream;
import java.net.Socket;
+import java.nio.charset.StandardCharsets;
import java.util.Timer;
import java.util.TimerTask;
@@ -242,7 +243,7 @@ public abstract class ContinuationBase
try (Socket socket = new Socket("localhost",port);)
{
socket.setSoTimeout(10000);
- socket.getOutputStream().write(request.getBytes("UTF-8"));
+ socket.getOutputStream().write(request.getBytes(StandardCharsets.UTF_8));
socket.getOutputStream().flush();
response = toString(socket.getInputStream());
diff --git a/tests/test-integration/src/test/java/org/eclipse/jetty/test/DigestPostTest.java b/tests/test-integration/src/test/java/org/eclipse/jetty/test/DigestPostTest.java
index 4911cd2..d9928b5 100644
--- a/tests/test-integration/src/test/java/org/eclipse/jetty/test/DigestPostTest.java
+++ b/tests/test-integration/src/test/java/org/eclipse/jetty/test/DigestPostTest.java
@@ -22,6 +22,7 @@ import java.io.FileInputStream;
import java.io.IOException;
import java.net.Socket;
import java.net.URI;
+import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.util.Collections;
import java.util.concurrent.TimeUnit;
@@ -129,14 +130,14 @@ public class DigestPostTest
public void testServerDirectlyHTTP10() throws Exception
{
Socket socket = new Socket("127.0.0.1",((NetworkConnector)_server.getConnectors()[0]).getLocalPort());
- byte[] bytes = __message.getBytes("UTF-8");
+ byte[] bytes = __message.getBytes(StandardCharsets.UTF_8);
_received=null;
socket.getOutputStream().write(
("POST /test/ HTTP/1.0\r\n"+
"Host: 127.0.0.1:"+((NetworkConnector)_server.getConnectors()[0]).getLocalPort()+"\r\n"+
"Content-Length: "+bytes.length+"\r\n"+
- "\r\n").getBytes("UTF-8"));
+ "\r\n").getBytes(StandardCharsets.UTF_8));
socket.getOutputStream().write(bytes);
socket.getOutputStream().flush();
@@ -163,7 +164,7 @@ public class DigestPostTest
"Host: 127.0.0.1:"+((NetworkConnector)_server.getConnectors()[0]).getLocalPort()+"\r\n"+
"Content-Length: "+bytes.length+"\r\n"+
"Authorization: "+digest+"\r\n"+
- "\r\n").getBytes("UTF-8"));
+ "\r\n").getBytes(StandardCharsets.UTF_8));
socket.getOutputStream().write(bytes);
socket.getOutputStream().flush();
@@ -177,7 +178,7 @@ public class DigestPostTest
public void testServerDirectlyHTTP11() throws Exception
{
Socket socket = new Socket("127.0.0.1",((NetworkConnector)_server.getConnectors()[0]).getLocalPort());
- byte[] bytes = __message.getBytes("UTF-8");
+ byte[] bytes = __message.getBytes(StandardCharsets.UTF_8);
_received=null;
socket.getOutputStream().write(
@@ -192,7 +193,7 @@ public class DigestPostTest
byte[] buf=new byte[4096];
int len=socket.getInputStream().read(buf);
- String result=new String(buf,0,len,"UTF-8");
+ String result=new String(buf,0,len,StandardCharsets.UTF_8);
Assert.assertTrue(result.startsWith("HTTP/1.1 401 Unauthorized"));
Assert.assertEquals(null,_received);