Merge remote-tracking branch 'origin/master' into jetty-9.1

Conflicts:
	jetty-client/src/main/java/org/eclipse/jetty/client/util/DigestAuthentication.java
	jetty-client/src/test/java/org/eclipse/jetty/client/HttpReceiverTest.java
	jetty-client/src/test/java/org/eclipse/jetty/client/HttpSenderTest.java
	jetty-http/src/main/java/org/eclipse/jetty/http/HttpField.java
	jetty-server/src/test/java/org/eclipse/jetty/server/AbstractHttpTest.java
	jetty-servlets/src/test/java/org/eclipse/jetty/servlets/AbstractDoSFilterTest.java
	jetty-spdy/spdy-core/src/main/java/org/eclipse/jetty/spdy/generator/HeadersBlockGenerator.java
	jetty-spdy/spdy-core/src/main/java/org/eclipse/jetty/spdy/parser/HeadersBlockParser.java
	jetty-websocket/websocket-client/src/main/java/org/eclipse/jetty/websocket/client/ClientUpgradeRequest.java
	jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/WebSocketFrame.java
	jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/WebSocketSession.java
	jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/extensions/compress/DeflateCompressionMethodTest.java
	jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/extensions/compress/PerMessageDeflateExtensionTest.java
This commit is contained in:
Greg Wilkins 2013-11-03 18:22:09 +11:00
commit eb3bb660b5
123 changed files with 755 additions and 562 deletions

View File

@ -19,6 +19,7 @@
package org.eclipse.jetty.client; package org.eclipse.jetty.client;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.nio.charset.StandardCharsets;
import java.nio.charset.UnsupportedCharsetException; import java.nio.charset.UnsupportedCharsetException;
import java.util.List; import java.util.List;
@ -92,15 +93,22 @@ public class HttpContentResponse implements ContentResponse
public String getContentAsString() public String getContentAsString()
{ {
String encoding = this.encoding; String encoding = this.encoding;
if (encoding == null)
{
return new String(getContent(), StandardCharsets.UTF_8);
}
else
{
try try
{ {
return new String(getContent(), encoding == null ? "UTF-8" : encoding); return new String(getContent(), encoding);
} }
catch (UnsupportedEncodingException e) catch (UnsupportedEncodingException e)
{ {
throw new UnsupportedCharsetException(encoding); throw new UnsupportedCharsetException(encoding);
} }
} }
}
@Override @Override
public String toString() public String toString()

View File

@ -19,6 +19,7 @@
package org.eclipse.jetty.client.util; package org.eclipse.jetty.client.util;
import java.net.URI; import java.net.URI;
import java.nio.charset.StandardCharsets;
import org.eclipse.jetty.client.HttpClient; import org.eclipse.jetty.client.HttpClient;
import org.eclipse.jetty.client.api.Authentication; import org.eclipse.jetty.client.api.Authentication;
@ -73,8 +74,7 @@ public class BasicAuthentication implements Authentication
@Override @Override
public Result authenticate(Request request, ContentResponse response, HeaderInfo headerInfo, Attributes context) public Result authenticate(Request request, ContentResponse response, HeaderInfo headerInfo, Attributes context)
{ {
String encoding = StringUtil.__ISO_8859_1; String value = "Basic " + B64Code.encode(user + ":" + password, StandardCharsets.ISO_8859_1);
String value = "Basic " + B64Code.encode(user + ":" + password, encoding);
return new BasicResult(headerInfo.getHeader(), uri, value); return new BasicResult(headerInfo.getHeader(), uri, value);
} }

View File

@ -20,6 +20,8 @@ package org.eclipse.jetty.client.util;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.nio.charset.UnsupportedCharsetException; import java.nio.charset.UnsupportedCharsetException;
import java.util.Locale; import java.util.Locale;
@ -131,7 +133,7 @@ public abstract class BufferingResponseListener extends Listener.Adapter
{ {
String encoding = this.encoding; String encoding = this.encoding;
if (encoding == null) if (encoding == null)
encoding = "UTF-8"; return getContentAsString(StandardCharsets.UTF_8);
return getContentAsString(encoding); return getContentAsString(encoding);
} }
@ -151,4 +153,14 @@ public abstract class BufferingResponseListener extends Listener.Adapter
throw new UnsupportedCharsetException(encoding); 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);
}
} }

View File

@ -218,14 +218,13 @@ public class DigestAuthentication implements Authentication
if (digester == null) if (digester == null)
return; return;
Charset charset = StandardCharsets.ISO_8859_1;
String A1 = user + ":" + realm + ":" + password; 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.getMethod() + ":" + request.getURI(); String A2 = request.getMethod() + ":" + request.getURI();
if ("auth-int".equals(qop)) if ("auth-int".equals(qop))
A2 += ":" + toHexString(digester.digest(content)); 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 nonceCount;
String clientNonce; String clientNonce;
@ -242,7 +241,7 @@ public class DigestAuthentication implements Authentication
clientNonce = null; clientNonce = null;
A3 = hashA1 + ":" + nonce + ":" + hashA2; 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"); StringBuilder value = new StringBuilder("Digest");
value.append(" username=\"").append(user).append("\""); value.append(" username=\"").append(user).append("\"");

View File

@ -19,6 +19,7 @@
package org.eclipse.jetty.client.util; package org.eclipse.jetty.client.util;
import java.nio.charset.Charset; import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import org.eclipse.jetty.client.api.ContentProvider; import org.eclipse.jetty.client.api.ContentProvider;
@ -32,7 +33,7 @@ public class StringContentProvider extends BytesContentProvider
{ {
public StringContentProvider(String content) public StringContentProvider(String content)
{ {
this(content, "UTF-8"); this(content, StandardCharsets.UTF_8);
} }
public StringContentProvider(String content, String encoding) public StringContentProvider(String content, String encoding)

View File

@ -26,6 +26,7 @@ import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.charset.Charset; import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.zip.GZIPInputStream; import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream; import java.util.zip.GZIPOutputStream;
@ -59,7 +60,7 @@ public class GZIPContentDecoderTest
data += data; data += data;
ByteArrayOutputStream baos = new ByteArrayOutputStream(); ByteArrayOutputStream baos = new ByteArrayOutputStream();
GZIPOutputStream output = new GZIPOutputStream(baos); GZIPOutputStream output = new GZIPOutputStream(baos);
output.write(data.getBytes("UTF-8")); output.write(data.getBytes(StandardCharsets.UTF_8));
output.close(); output.close();
byte[] bytes = baos.toByteArray(); byte[] bytes = baos.toByteArray();
@ -68,7 +69,7 @@ public class GZIPContentDecoderTest
int read; int read;
while ((read = input.read()) >= 0) while ((read = input.read()) >= 0)
baos.write(read); baos.write(read);
assertEquals(data, new String(baos.toByteArray(), "UTF-8")); assertEquals(data, new String(baos.toByteArray(), StandardCharsets.UTF_8));
} }
@Test @Test
@ -91,13 +92,13 @@ public class GZIPContentDecoderTest
ByteArrayOutputStream baos = new ByteArrayOutputStream(); ByteArrayOutputStream baos = new ByteArrayOutputStream();
GZIPOutputStream output = new GZIPOutputStream(baos); GZIPOutputStream output = new GZIPOutputStream(baos);
output.write(data.getBytes("UTF-8")); output.write(data.getBytes(StandardCharsets.UTF_8));
output.close(); output.close();
byte[] bytes = baos.toByteArray(); byte[] bytes = baos.toByteArray();
GZIPContentDecoder decoder = new GZIPContentDecoder(); GZIPContentDecoder decoder = new GZIPContentDecoder();
ByteBuffer decoded = decoder.decode(ByteBuffer.wrap(bytes)); 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 @Test
@ -107,7 +108,7 @@ public class GZIPContentDecoderTest
ByteArrayOutputStream baos = new ByteArrayOutputStream(); ByteArrayOutputStream baos = new ByteArrayOutputStream();
GZIPOutputStream output = new GZIPOutputStream(baos); GZIPOutputStream output = new GZIPOutputStream(baos);
output.write(data.getBytes("UTF-8")); output.write(data.getBytes(StandardCharsets.UTF_8));
output.close(); output.close();
byte[] bytes = baos.toByteArray(); byte[] bytes = baos.toByteArray();
@ -121,7 +122,7 @@ public class GZIPContentDecoderTest
ByteBuffer decoded = decoder.decode(ByteBuffer.wrap(bytes1)); ByteBuffer decoded = decoder.decode(ByteBuffer.wrap(bytes1));
assertEquals(0, decoded.capacity()); assertEquals(0, decoded.capacity());
decoded = decoder.decode(ByteBuffer.wrap(bytes2)); decoded = decoder.decode(ByteBuffer.wrap(bytes2));
assertEquals(data, Charset.forName("UTF-8").decode(decoded).toString()); assertEquals(data, StandardCharsets.UTF_8.decode(decoded).toString());
} }
@Test @Test
@ -131,7 +132,7 @@ public class GZIPContentDecoderTest
ByteArrayOutputStream baos = new ByteArrayOutputStream(); ByteArrayOutputStream baos = new ByteArrayOutputStream();
GZIPOutputStream output = new GZIPOutputStream(baos); GZIPOutputStream output = new GZIPOutputStream(baos);
output.write(data.getBytes("UTF-8")); output.write(data.getBytes(StandardCharsets.UTF_8));
output.close(); output.close();
byte[] bytes = baos.toByteArray(); byte[] bytes = baos.toByteArray();
@ -143,7 +144,7 @@ public class GZIPContentDecoderTest
GZIPContentDecoder decoder = new GZIPContentDecoder(); GZIPContentDecoder decoder = new GZIPContentDecoder();
ByteBuffer decoded = decoder.decode(ByteBuffer.wrap(bytes1)); 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()); assertFalse(decoder.isFinished());
decoded = decoder.decode(ByteBuffer.wrap(bytes2)); decoded = decoder.decode(ByteBuffer.wrap(bytes2));
assertEquals(0, decoded.remaining()); assertEquals(0, decoded.remaining());
@ -157,7 +158,7 @@ public class GZIPContentDecoderTest
ByteArrayOutputStream baos = new ByteArrayOutputStream(); ByteArrayOutputStream baos = new ByteArrayOutputStream();
GZIPOutputStream output = new GZIPOutputStream(baos); GZIPOutputStream output = new GZIPOutputStream(baos);
output.write(data.getBytes("UTF-8")); output.write(data.getBytes(StandardCharsets.UTF_8));
output.close(); output.close();
byte[] bytes = baos.toByteArray(); byte[] bytes = baos.toByteArray();
@ -171,7 +172,7 @@ public class GZIPContentDecoderTest
ByteBuffer decoded = decoder.decode(ByteBuffer.wrap(bytes1)); ByteBuffer decoded = decoder.decode(ByteBuffer.wrap(bytes1));
assertEquals(0, decoded.capacity()); assertEquals(0, decoded.capacity());
decoded = decoder.decode(ByteBuffer.wrap(bytes2)); decoded = decoder.decode(ByteBuffer.wrap(bytes2));
assertEquals(data, Charset.forName("UTF-8").decode(decoded).toString()); assertEquals(data, StandardCharsets.UTF_8.decode(decoded).toString());
} }
@Test @Test
@ -180,14 +181,14 @@ public class GZIPContentDecoderTest
String data1 = "0"; String data1 = "0";
ByteArrayOutputStream baos = new ByteArrayOutputStream(); ByteArrayOutputStream baos = new ByteArrayOutputStream();
GZIPOutputStream output = new GZIPOutputStream(baos); GZIPOutputStream output = new GZIPOutputStream(baos);
output.write(data1.getBytes("UTF-8")); output.write(data1.getBytes(StandardCharsets.UTF_8));
output.close(); output.close();
byte[] bytes1 = baos.toByteArray(); byte[] bytes1 = baos.toByteArray();
String data2 = "1"; String data2 = "1";
baos = new ByteArrayOutputStream(); baos = new ByteArrayOutputStream();
output = new GZIPOutputStream(baos); output = new GZIPOutputStream(baos);
output.write(data2.getBytes("UTF-8")); output.write(data2.getBytes(StandardCharsets.UTF_8));
output.close(); output.close();
byte[] bytes2 = baos.toByteArray(); byte[] bytes2 = baos.toByteArray();
@ -198,11 +199,11 @@ public class GZIPContentDecoderTest
GZIPContentDecoder decoder = new GZIPContentDecoder(); GZIPContentDecoder decoder = new GZIPContentDecoder();
ByteBuffer buffer = ByteBuffer.wrap(bytes); ByteBuffer buffer = ByteBuffer.wrap(bytes);
ByteBuffer decoded = decoder.decode(buffer); 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(decoder.isFinished());
assertTrue(buffer.hasRemaining()); assertTrue(buffer.hasRemaining());
decoded = decoder.decode(buffer); decoded = decoder.decode(buffer);
assertEquals(data2, Charset.forName("UTF-8").decode(decoded).toString()); assertEquals(data2, StandardCharsets.UTF_8.decode(decoded).toString());
assertTrue(decoder.isFinished()); assertTrue(decoder.isFinished());
assertFalse(buffer.hasRemaining()); assertFalse(buffer.hasRemaining());
} }
@ -215,7 +216,7 @@ public class GZIPContentDecoderTest
data += data; data += data;
ByteArrayOutputStream baos = new ByteArrayOutputStream(); ByteArrayOutputStream baos = new ByteArrayOutputStream();
GZIPOutputStream output = new GZIPOutputStream(baos); GZIPOutputStream output = new GZIPOutputStream(baos);
output.write(data.getBytes("UTF-8")); output.write(data.getBytes(StandardCharsets.UTF_8));
output.close(); output.close();
byte[] bytes = baos.toByteArray(); byte[] bytes = baos.toByteArray();
@ -225,7 +226,7 @@ public class GZIPContentDecoderTest
while (buffer.hasRemaining()) while (buffer.hasRemaining())
{ {
ByteBuffer decoded = decoder.decode(buffer); ByteBuffer decoded = decoder.decode(buffer);
result += Charset.forName("UTF-8").decode(decoded).toString(); result += StandardCharsets.UTF_8.decode(decoded).toString();
} }
assertEquals(data, result); assertEquals(data, result);
} }
@ -238,7 +239,7 @@ public class GZIPContentDecoderTest
data += data; data += data;
ByteArrayOutputStream baos = new ByteArrayOutputStream(); ByteArrayOutputStream baos = new ByteArrayOutputStream();
GZIPOutputStream output = new GZIPOutputStream(baos); GZIPOutputStream output = new GZIPOutputStream(baos);
output.write(data.getBytes("UTF-8")); output.write(data.getBytes(StandardCharsets.UTF_8));
output.close(); output.close();
byte[] bytes = baos.toByteArray(); byte[] bytes = baos.toByteArray();
@ -249,7 +250,7 @@ public class GZIPContentDecoderTest
{ {
ByteBuffer decoded = decoder.decode(ByteBuffer.wrap(new byte[]{buffer.get()})); ByteBuffer decoded = decoder.decode(ByteBuffer.wrap(new byte[]{buffer.get()}));
if (decoded.hasRemaining()) if (decoded.hasRemaining())
result += Charset.forName("UTF-8").decode(decoded).toString(); result += StandardCharsets.UTF_8.decode(decoded).toString();
} }
assertEquals(data, result); assertEquals(data, result);
assertTrue(decoder.isFinished()); assertTrue(decoder.isFinished());
@ -263,12 +264,12 @@ public class GZIPContentDecoderTest
data1 += data1; data1 += data1;
ByteArrayOutputStream baos = new ByteArrayOutputStream(); ByteArrayOutputStream baos = new ByteArrayOutputStream();
GZIPOutputStream output = new GZIPOutputStream(baos); GZIPOutputStream output = new GZIPOutputStream(baos);
output.write(data1.getBytes("UTF-8")); output.write(data1.getBytes(StandardCharsets.UTF_8));
output.close(); output.close();
byte[] bytes1 = baos.toByteArray(); byte[] bytes1 = baos.toByteArray();
String data2 = "HELLO"; String data2 = "HELLO";
byte[] bytes2 = data2.getBytes("UTF-8"); byte[] bytes2 = data2.getBytes(StandardCharsets.UTF_8);
byte[] bytes = new byte[bytes1.length + bytes2.length]; byte[] bytes = new byte[bytes1.length + bytes2.length];
System.arraycopy(bytes1, 0, bytes, 0, bytes1.length); System.arraycopy(bytes1, 0, bytes, 0, bytes1.length);
@ -281,12 +282,12 @@ public class GZIPContentDecoderTest
{ {
ByteBuffer decoded = decoder.decode(buffer); ByteBuffer decoded = decoder.decode(buffer);
if (decoded.hasRemaining()) if (decoded.hasRemaining())
result += Charset.forName("UTF-8").decode(decoded).toString(); result += StandardCharsets.UTF_8.decode(decoded).toString();
if (decoder.isFinished()) if (decoder.isFinished())
break; break;
} }
assertEquals(data1, result); assertEquals(data1, result);
assertTrue(buffer.hasRemaining()); assertTrue(buffer.hasRemaining());
assertEquals(data2, Charset.forName("UTF-8").decode(buffer).toString()); assertEquals(data2, StandardCharsets.UTF_8.decode(buffer).toString());
} }
} }

View File

@ -21,6 +21,7 @@ package org.eclipse.jetty.client;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.IOException; import java.io.IOException;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.concurrent.CountDownLatch; import java.util.concurrent.CountDownLatch;
@ -60,13 +61,13 @@ public class HttpClientContinueTest extends AbstractHttpClientServerTest
@Test @Test
public void test_Expect100Continue_WithOneContent_Respond100Continue() throws Exception public void test_Expect100Continue_WithOneContent_Respond100Continue() throws Exception
{ {
test_Expect100Continue_Respond100Continue("data1".getBytes("UTF-8")); test_Expect100Continue_Respond100Continue("data1".getBytes(StandardCharsets.UTF_8));
} }
@Test @Test
public void test_Expect100Continue_WithMultipleContents_Respond100Continue() throws Exception 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 private void test_Expect100Continue_Respond100Continue(byte[]... contents) throws Exception

View File

@ -20,6 +20,7 @@ package org.eclipse.jetty.client;
import java.io.IOException; import java.io.IOException;
import java.net.URI; import java.net.URI;
import java.nio.charset.StandardCharsets;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
import javax.servlet.ServletException; import javax.servlet.ServletException;
@ -82,7 +83,7 @@ public class HttpClientProxyTest extends AbstractHttpClientServerTest
{ {
final String user = "foo"; final String user = "foo";
final String password = "bar"; 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 serverHost = "server";
final String realm = "test_realm"; final String realm = "test_realm";
final int status = HttpStatus.NO_CONTENT_204; final int status = HttpStatus.NO_CONTENT_204;

View File

@ -25,6 +25,7 @@ import java.net.URI;
import java.net.URLEncoder; import java.net.URLEncoder;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.channels.UnresolvedAddressException; import java.nio.channels.UnresolvedAddressException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.Paths; import java.nio.file.Paths;
@ -174,10 +175,10 @@ public class HttpClientTest extends AbstractHttpClientServerTest
response.setCharacterEncoding("UTF-8"); response.setCharacterEncoding("UTF-8");
ServletOutputStream output = response.getOutputStream(); ServletOutputStream output = response.getOutputStream();
String paramValue1 = request.getParameter(paramName1); String paramValue1 = request.getParameter(paramName1);
output.write(paramValue1.getBytes("UTF-8")); output.write(paramValue1.getBytes(StandardCharsets.UTF_8));
String paramValue2 = request.getParameter(paramName2); String paramValue2 = request.getParameter(paramName2);
Assert.assertEquals("", paramValue2); Assert.assertEquals("", paramValue2);
output.write("empty".getBytes("UTF-8")); output.write("empty".getBytes(StandardCharsets.UTF_8));
baseRequest.setHandled(true); baseRequest.setHandled(true);
} }
}); });
@ -189,7 +190,7 @@ public class HttpClientTest extends AbstractHttpClientServerTest
Assert.assertNotNull(response); Assert.assertNotNull(response);
Assert.assertEquals(200, response.getStatus()); 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); Assert.assertEquals(value1 + "empty", content);
} }
@ -207,9 +208,9 @@ public class HttpClientTest extends AbstractHttpClientServerTest
ServletOutputStream output = response.getOutputStream(); ServletOutputStream output = response.getOutputStream();
String[] paramValues1 = request.getParameterValues(paramName1); String[] paramValues1 = request.getParameterValues(paramName1);
for (String paramValue : paramValues1) for (String paramValue : paramValues1)
output.write(paramValue.getBytes("UTF-8")); output.write(paramValue.getBytes(StandardCharsets.UTF_8));
String paramValue2 = request.getParameter(paramName2); String paramValue2 = request.getParameter(paramName2);
output.write(paramValue2.getBytes("UTF-8")); output.write(paramValue2.getBytes(StandardCharsets.UTF_8));
baseRequest.setHandled(true); baseRequest.setHandled(true);
} }
}); });
@ -225,7 +226,7 @@ public class HttpClientTest extends AbstractHttpClientServerTest
Assert.assertNotNull(response); Assert.assertNotNull(response);
Assert.assertEquals(200, response.getStatus()); 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); Assert.assertEquals(value11 + value12 + value2, content);
} }
@ -257,7 +258,7 @@ public class HttpClientTest extends AbstractHttpClientServerTest
Assert.assertNotNull(response); Assert.assertNotNull(response);
Assert.assertEquals(200, response.getStatus()); 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 @Test
@ -289,7 +290,7 @@ public class HttpClientTest extends AbstractHttpClientServerTest
Assert.assertNotNull(response); Assert.assertNotNull(response);
Assert.assertEquals(200, response.getStatus()); 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 @Test

View File

@ -18,6 +18,7 @@
package org.eclipse.jetty.client; package org.eclipse.jetty.client;
import java.nio.charset.StandardCharsets;
public class HttpReceiverTest public class HttpReceiverTest
{ {
// @Rule // @Rule
@ -102,7 +103,7 @@ public class HttpReceiverTest
// Assert.assertNotNull(headers); // Assert.assertNotNull(headers);
// Assert.assertEquals(1, headers.size()); // Assert.assertEquals(1, headers.size());
// Assert.assertEquals(String.valueOf(content.length()), headers.get(HttpHeader.CONTENT_LENGTH)); // 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); // Assert.assertEquals(content, received);
// } // }
// //

View File

@ -18,6 +18,7 @@
package org.eclipse.jetty.client; package org.eclipse.jetty.client;
import java.nio.charset.StandardCharsets;
public class HttpSenderTest public class HttpSenderTest
{ {
// @Rule // @Rule
@ -172,7 +173,7 @@ public class HttpSenderTest
// HttpConnection connection = new HttpConnection(client, endPoint, destination); // HttpConnection connection = new HttpConnection(client, endPoint, destination);
// Request request = client.newRequest(URI.create("http://localhost/")); // Request request = client.newRequest(URI.create("http://localhost/"));
// String content = "abcdef"; // 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 headersLatch = new CountDownLatch(1);
// final CountDownLatch successLatch = new CountDownLatch(1); // final CountDownLatch successLatch = new CountDownLatch(1);
// request.listener(new Request.Listener.Adapter() // request.listener(new Request.Listener.Adapter()
@ -207,7 +208,7 @@ public class HttpSenderTest
// Request request = client.newRequest(URI.create("http://localhost/")); // Request request = client.newRequest(URI.create("http://localhost/"));
// String content1 = "0123456789"; // String content1 = "0123456789";
// String content2 = "abcdef"; // 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 headersLatch = new CountDownLatch(1);
// final CountDownLatch successLatch = new CountDownLatch(1); // final CountDownLatch successLatch = new CountDownLatch(1);
// request.listener(new Request.Listener.Adapter() // request.listener(new Request.Listener.Adapter()
@ -242,7 +243,7 @@ public class HttpSenderTest
// Request request = client.newRequest(URI.create("http://localhost/")); // Request request = client.newRequest(URI.create("http://localhost/"));
// String content1 = "0123456789"; // String content1 = "0123456789";
// String content2 = "ABCDEF"; // 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 // @Override
// public long getLength() // public long getLength()

View File

@ -24,6 +24,7 @@ import java.io.OutputStream;
import java.net.HttpCookie; import java.net.HttpCookie;
import java.net.URI; import java.net.URI;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.util.concurrent.CountDownLatch; import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
@ -269,7 +270,7 @@ public class Usage
HttpClient client = new HttpClient(); HttpClient client = new HttpClient();
client.start(); 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) ContentResponse response = client.newRequest("localhost", 8080)
// Provide the content as InputStream // Provide the content as InputStream

View File

@ -24,6 +24,7 @@ import java.io.InputStream;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.io.OutputStream; import java.io.OutputStream;
import java.net.SocketTimeoutException; import java.net.SocketTimeoutException;
import java.nio.charset.StandardCharsets;
import java.util.Arrays; import java.util.Arrays;
import java.util.concurrent.Callable; import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService; import java.util.concurrent.ExecutorService;
@ -151,7 +152,7 @@ public class SslBytesClientTest extends SslBytesTest
SimpleProxy.AutomaticFlow automaticProxyFlow = proxy.startAutomaticFlow(); SimpleProxy.AutomaticFlow automaticProxyFlow = proxy.startAutomaticFlow();
// Read request // 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(); String line = reader.readLine();
Assert.assertTrue(line.startsWith("GET")); Assert.assertTrue(line.startsWith("GET"));
while (line.length() > 0) while (line.length() > 0)
@ -161,7 +162,7 @@ public class SslBytesClientTest extends SslBytesTest
OutputStream output = server.getOutputStream(); OutputStream output = server.getOutputStream();
output.write(("HTTP/1.1 200 OK\r\n" + output.write(("HTTP/1.1 200 OK\r\n" +
"Content-Length: 0\r\n" + "Content-Length: 0\r\n" +
"\r\n").getBytes("UTF-8")); "\r\n").getBytes(StandardCharsets.UTF_8));
output.flush(); output.flush();
Assert.assertTrue(automaticProxyFlow.stop(5, TimeUnit.SECONDS)); Assert.assertTrue(automaticProxyFlow.stop(5, TimeUnit.SECONDS));
@ -197,7 +198,7 @@ public class SslBytesClientTest extends SslBytesTest
// Read request // Read request
InputStream serverInput = server.getInputStream(); 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(); String line = reader.readLine();
Assert.assertTrue(line.startsWith("GET")); Assert.assertTrue(line.startsWith("GET"));
while (line.length() > 0) while (line.length() > 0)
@ -206,16 +207,16 @@ public class SslBytesClientTest extends SslBytesTest
OutputStream serverOutput = server.getOutputStream(); OutputStream serverOutput = server.getOutputStream();
byte[] data1 = new byte[1024]; byte[] data1 = new byte[1024];
Arrays.fill(data1, (byte)'X'); 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]; byte[] data2 = new byte[1024];
Arrays.fill(data2, (byte)'Y'); 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 // Write first part of the response
serverOutput.write(("HTTP/1.1 200 OK\r\n" + serverOutput.write(("HTTP/1.1 200 OK\r\n" +
"Content-Type: text/plain\r\n" + "Content-Type: text/plain\r\n" +
"Content-Length: " + (content1.length() + content2.length()) + "\r\n" + "Content-Length: " + (content1.length() + content2.length()) + "\r\n" +
"\r\n" + "\r\n" +
content1).getBytes("UTF-8")); content1).getBytes(StandardCharsets.UTF_8));
serverOutput.flush(); serverOutput.flush();
Assert.assertTrue(automaticProxyFlow.stop(5, TimeUnit.SECONDS)); Assert.assertTrue(automaticProxyFlow.stop(5, TimeUnit.SECONDS));
@ -319,7 +320,7 @@ public class SslBytesClientTest extends SslBytesTest
// Read request // Read request
InputStream serverInput = server.getInputStream(); 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(); String line = reader.readLine();
Assert.assertTrue(line.startsWith("GET")); Assert.assertTrue(line.startsWith("GET"));
while (line.length() > 0) while (line.length() > 0)
@ -328,16 +329,16 @@ public class SslBytesClientTest extends SslBytesTest
OutputStream serverOutput = server.getOutputStream(); OutputStream serverOutput = server.getOutputStream();
byte[] data1 = new byte[1024]; byte[] data1 = new byte[1024];
Arrays.fill(data1, (byte)'X'); 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]; byte[] data2 = new byte[1024];
Arrays.fill(data2, (byte)'Y'); 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 // Write first part of the response
serverOutput.write(("HTTP/1.1 200 OK\r\n" + serverOutput.write(("HTTP/1.1 200 OK\r\n" +
"Content-Type: text/plain\r\n" + "Content-Type: text/plain\r\n" +
"Content-Length: " + (content1.length() + content2.length()) + "\r\n" + "Content-Length: " + (content1.length() + content2.length()) + "\r\n" +
"\r\n" + "\r\n" +
content1).getBytes("UTF-8")); content1).getBytes(StandardCharsets.UTF_8));
serverOutput.flush(); serverOutput.flush();
Assert.assertTrue(automaticProxyFlow.stop(5, TimeUnit.SECONDS)); Assert.assertTrue(automaticProxyFlow.stop(5, TimeUnit.SECONDS));

View File

@ -31,6 +31,7 @@ import java.net.SocketTimeoutException;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.channels.SelectionKey; import java.nio.channels.SelectionKey;
import java.nio.channels.SocketChannel; import java.nio.channels.SocketChannel;
import java.nio.charset.StandardCharsets;
import java.util.Arrays; import java.util.Arrays;
import java.util.concurrent.Callable; import java.util.concurrent.Callable;
import java.util.concurrent.CountDownLatch; import java.util.concurrent.CountDownLatch;
@ -586,7 +587,7 @@ public class SslBytesServerTest extends SslBytesTest
clientOutput.write(("" + clientOutput.write(("" +
"GET / HTTP/1.1\r\n" + "GET / HTTP/1.1\r\n" +
"Host: localhost\r\n" + "Host: localhost\r\n" +
"\r\n").getBytes("UTF-8")); "\r\n").getBytes(StandardCharsets.UTF_8));
clientOutput.flush(); clientOutput.flush();
return null; return null;
} }
@ -628,7 +629,7 @@ public class SslBytesServerTest extends SslBytesTest
clientOutput.write(("" + clientOutput.write(("" +
"GET / HTTP/1.1\r\n" + "GET / HTTP/1.1\r\n" +
"Host: localhost\r\n" + "Host: localhost\r\n" +
"\r\n").getBytes("UTF-8")); "\r\n").getBytes(StandardCharsets.UTF_8));
clientOutput.flush(); clientOutput.flush();
return null; return null;
} }
@ -644,7 +645,7 @@ public class SslBytesServerTest extends SslBytesTest
Assert.assertEquals(TLSRecord.Type.APPLICATION, record.getType()); Assert.assertEquals(TLSRecord.Type.APPLICATION, record.getType());
proxy.flushToClient(record); 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(); String line = reader.readLine();
Assert.assertNotNull(line); Assert.assertNotNull(line);
Assert.assertTrue(line.startsWith("HTTP/1.1 200 ")); Assert.assertTrue(line.startsWith("HTTP/1.1 200 "));
@ -721,7 +722,7 @@ public class SslBytesServerTest extends SslBytesTest
clientOutput.write(("" + clientOutput.write(("" +
"GET / HTTP/1.1\r\n" + "GET / HTTP/1.1\r\n" +
"Host: localhost\r\n" + "Host: localhost\r\n" +
"\r\n").getBytes("UTF-8")); "\r\n").getBytes(StandardCharsets.UTF_8));
clientOutput.flush(); clientOutput.flush();
return null; return null;
} }
@ -738,7 +739,7 @@ public class SslBytesServerTest extends SslBytesTest
Assert.assertEquals(TLSRecord.Type.APPLICATION, record.getType()); Assert.assertEquals(TLSRecord.Type.APPLICATION, record.getType());
proxy.flushToClient(record); 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(); String line = reader.readLine();
Assert.assertNotNull(line); Assert.assertNotNull(line);
Assert.assertTrue(line.startsWith("HTTP/1.1 200 ")); Assert.assertTrue(line.startsWith("HTTP/1.1 200 "));
@ -801,7 +802,7 @@ public class SslBytesServerTest extends SslBytesTest
clientOutput.write(("" + clientOutput.write(("" +
"GET / HTTP/1.1\r\n" + "GET / HTTP/1.1\r\n" +
"Host: localhost\r\n" + "Host: localhost\r\n" +
"\r\n").getBytes("UTF-8")); "\r\n").getBytes(StandardCharsets.UTF_8));
clientOutput.flush(); clientOutput.flush();
return null; return null;
} }
@ -876,7 +877,7 @@ public class SslBytesServerTest extends SslBytesTest
clientOutput.write(("" + clientOutput.write(("" +
"GET / HTTP/1.1\r\n" + "GET / HTTP/1.1\r\n" +
"Host: localhost\r\n" + "Host: localhost\r\n" +
"\r\n").getBytes("UTF-8")); "\r\n").getBytes(StandardCharsets.UTF_8));
clientOutput.flush(); clientOutput.flush();
return null; return null;
} }
@ -946,7 +947,7 @@ public class SslBytesServerTest extends SslBytesTest
clientOutput.write(("" + clientOutput.write(("" +
"GET / HTTP/1.1\r\n" + "GET / HTTP/1.1\r\n" +
"Host: localhost\r\n" + "Host: localhost\r\n" +
"\r\n").getBytes("UTF-8")); "\r\n").getBytes(StandardCharsets.UTF_8));
clientOutput.flush(); clientOutput.flush();
return null; return null;
} }
@ -1005,7 +1006,7 @@ public class SslBytesServerTest extends SslBytesTest
clientOutput.write(("" + clientOutput.write(("" +
"GET / HTTP/1.1\r\n" + "GET / HTTP/1.1\r\n" +
"Host: localhost\r\n" + "Host: localhost\r\n" +
"\r\n").getBytes("UTF-8")); "\r\n").getBytes(StandardCharsets.UTF_8));
clientOutput.flush(); clientOutput.flush();
return null; return null;
} }
@ -1055,7 +1056,7 @@ public class SslBytesServerTest extends SslBytesTest
byte[] data = new byte[128 * 1024]; byte[] data = new byte[128 * 1024];
Arrays.fill(data, (byte)'X'); 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>() Future<Object> request = threadPool.submit(new Callable<Object>()
{ {
@Override @Override
@ -1067,7 +1068,7 @@ public class SslBytesServerTest extends SslBytesTest
"Host: localhost\r\n" + "Host: localhost\r\n" +
"Content-Length: " + content.length() + "\r\n" + "Content-Length: " + content.length() + "\r\n" +
"\r\n" + "\r\n" +
content).getBytes("UTF-8")); content).getBytes(StandardCharsets.UTF_8));
clientOutput.flush(); clientOutput.flush();
return null; return null;
} }
@ -1113,7 +1114,7 @@ public class SslBytesServerTest extends SslBytesTest
byte[] data = new byte[128 * 1024]; byte[] data = new byte[128 * 1024];
Arrays.fill(data, (byte)'X'); 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>() Future<Object> request = threadPool.submit(new Callable<Object>()
{ {
@Override @Override
@ -1125,7 +1126,7 @@ public class SslBytesServerTest extends SslBytesTest
"Host: localhost\r\n" + "Host: localhost\r\n" +
"Content-Length: " + content.length() + "\r\n" + "Content-Length: " + content.length() + "\r\n" +
"\r\n" + "\r\n" +
content).getBytes("UTF-8")); content).getBytes(StandardCharsets.UTF_8));
clientOutput.flush(); clientOutput.flush();
return null; return null;
} }
@ -1187,7 +1188,7 @@ public class SslBytesServerTest extends SslBytesTest
clientOutput.write(("" + clientOutput.write(("" +
"GET / HTTP/1.1\r\n" + "GET / HTTP/1.1\r\n" +
"Host: localhost\r\n" + "Host: localhost\r\n" +
"\r\n").getBytes("UTF-8")); "\r\n").getBytes(StandardCharsets.UTF_8));
clientOutput.flush(); clientOutput.flush();
return null; return null;
} }
@ -1266,7 +1267,7 @@ public class SslBytesServerTest extends SslBytesTest
"Content-Type: text/plain\r\n" + "Content-Type: text/plain\r\n" +
"Content-Length: " + content.length() + "\r\n" + "Content-Length: " + content.length() + "\r\n" +
"\r\n" + "\r\n" +
content).getBytes("UTF-8")); content).getBytes(StandardCharsets.UTF_8));
clientOutput.flush(); clientOutput.flush();
return null; return null;
} }
@ -1287,7 +1288,7 @@ public class SslBytesServerTest extends SslBytesTest
Assert.assertEquals(TLSRecord.Type.APPLICATION, record.getType()); Assert.assertEquals(TLSRecord.Type.APPLICATION, record.getType());
proxy.flushToClient(record); 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(); String line = reader.readLine();
Assert.assertNotNull(line); Assert.assertNotNull(line);
Assert.assertTrue(line.startsWith("HTTP/1.1 200 ")); Assert.assertTrue(line.startsWith("HTTP/1.1 200 "));
@ -1318,7 +1319,7 @@ public class SslBytesServerTest extends SslBytesTest
// Use a content that is larger than the TLS record which is 2^14 (around 16k) // Use a content that is larger than the TLS record which is 2^14 (around 16k)
byte[] data = new byte[128 * 1024]; byte[] data = new byte[128 * 1024];
Arrays.fill(data, (byte)'X'); 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>() Future<Object> request = threadPool.submit(new Callable<Object>()
{ {
@ -1332,7 +1333,7 @@ public class SslBytesServerTest extends SslBytesTest
"Content-Type: text/plain\r\n" + "Content-Type: text/plain\r\n" +
"Content-Length: " + content.length() + "\r\n" + "Content-Length: " + content.length() + "\r\n" +
"\r\n" + "\r\n" +
content).getBytes("UTF-8")); content).getBytes(StandardCharsets.UTF_8));
clientOutput.flush(); clientOutput.flush();
return null; return null;
} }
@ -1364,7 +1365,7 @@ public class SslBytesServerTest extends SslBytesTest
Assert.assertEquals(TLSRecord.Type.APPLICATION, record.getType()); Assert.assertEquals(TLSRecord.Type.APPLICATION, record.getType());
proxy.flushToClient(record); 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(); String line = reader.readLine();
Assert.assertNotNull(line); Assert.assertNotNull(line);
Assert.assertTrue(line.startsWith("HTTP/1.1 200 ")); Assert.assertTrue(line.startsWith("HTTP/1.1 200 "));
@ -1399,10 +1400,10 @@ public class SslBytesServerTest extends SslBytesTest
byte[] data1 = new byte[1024]; byte[] data1 = new byte[1024];
Arrays.fill(data1, (byte)'X'); 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]; byte[] data2 = new byte[1024];
Arrays.fill(data2, (byte)'Y'); 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 // Write only part of the body
automaticProxyFlow = proxy.startAutomaticFlow(); automaticProxyFlow = proxy.startAutomaticFlow();
@ -1412,7 +1413,7 @@ public class SslBytesServerTest extends SslBytesTest
"Content-Type: text/plain\r\n" + "Content-Type: text/plain\r\n" +
"Content-Length: " + (content1.length() + content2.length()) + "\r\n" + "Content-Length: " + (content1.length() + content2.length()) + "\r\n" +
"\r\n" + "\r\n" +
content1).getBytes("UTF-8")); content1).getBytes(StandardCharsets.UTF_8));
clientOutput.flush(); clientOutput.flush();
Assert.assertTrue(automaticProxyFlow.stop(5, TimeUnit.SECONDS)); Assert.assertTrue(automaticProxyFlow.stop(5, TimeUnit.SECONDS));
@ -1446,7 +1447,7 @@ public class SslBytesServerTest extends SslBytesTest
@Override @Override
public Object call() throws Exception public Object call() throws Exception
{ {
clientOutput.write(content2.getBytes("UTF-8")); clientOutput.write(content2.getBytes(StandardCharsets.UTF_8));
clientOutput.flush(); clientOutput.flush();
return null; return null;
} }
@ -1490,10 +1491,10 @@ public class SslBytesServerTest extends SslBytesTest
// Use a content that is larger than the TLS record which is 2^14 (around 16k) // Use a content that is larger than the TLS record which is 2^14 (around 16k)
byte[] data1 = new byte[80 * 1024]; byte[] data1 = new byte[80 * 1024];
Arrays.fill(data1, (byte)'X'); 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]; byte[] data2 = new byte[48 * 1024];
Arrays.fill(data2, (byte)'Y'); 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 // Write only part of the body
automaticProxyFlow = proxy.startAutomaticFlow(); automaticProxyFlow = proxy.startAutomaticFlow();
@ -1503,7 +1504,7 @@ public class SslBytesServerTest extends SslBytesTest
"Content-Type: text/plain\r\n" + "Content-Type: text/plain\r\n" +
"Content-Length: " + (content1.length() + content2.length()) + "\r\n" + "Content-Length: " + (content1.length() + content2.length()) + "\r\n" +
"\r\n" + "\r\n" +
content1).getBytes("UTF-8")); content1).getBytes(StandardCharsets.UTF_8));
clientOutput.flush(); clientOutput.flush();
Assert.assertTrue(automaticProxyFlow.stop(5, TimeUnit.SECONDS)); Assert.assertTrue(automaticProxyFlow.stop(5, TimeUnit.SECONDS));
@ -1568,7 +1569,7 @@ public class SslBytesServerTest extends SslBytesTest
@Override @Override
public Object call() throws Exception public Object call() throws Exception
{ {
clientOutput.write(content2.getBytes("UTF-8")); clientOutput.write(content2.getBytes(StandardCharsets.UTF_8));
clientOutput.flush(); clientOutput.flush();
return null; return null;
} }
@ -1590,7 +1591,7 @@ public class SslBytesServerTest extends SslBytesTest
Assert.assertEquals(TLSRecord.Type.APPLICATION, record.getType()); Assert.assertEquals(TLSRecord.Type.APPLICATION, record.getType());
proxy.flushToClient(record); 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(); String line = reader.readLine();
Assert.assertNotNull(line); Assert.assertNotNull(line);
Assert.assertTrue(line.startsWith("HTTP/1.1 200 ")); Assert.assertTrue(line.startsWith("HTTP/1.1 200 "));
@ -1624,10 +1625,10 @@ public class SslBytesServerTest extends SslBytesTest
// Use a content that is larger than the TLS record which is 2^14 (around 16k) // Use a content that is larger than the TLS record which is 2^14 (around 16k)
byte[] data1 = new byte[80 * 1024]; byte[] data1 = new byte[80 * 1024];
Arrays.fill(data1, (byte)'X'); 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]; byte[] data2 = new byte[48 * 1024];
Arrays.fill(data2, (byte)'Y'); 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 // Write only part of the body
automaticProxyFlow = proxy.startAutomaticFlow(); automaticProxyFlow = proxy.startAutomaticFlow();
@ -1637,7 +1638,7 @@ public class SslBytesServerTest extends SslBytesTest
"Content-Type: text/plain\r\n" + "Content-Type: text/plain\r\n" +
"Content-Length: " + (content1.length() + content2.length()) + "\r\n" + "Content-Length: " + (content1.length() + content2.length()) + "\r\n" +
"\r\n" + "\r\n" +
content1).getBytes("UTF-8")); content1).getBytes(StandardCharsets.UTF_8));
clientOutput.flush(); clientOutput.flush();
Assert.assertTrue(automaticProxyFlow.stop(5, TimeUnit.SECONDS)); Assert.assertTrue(automaticProxyFlow.stop(5, TimeUnit.SECONDS));
@ -1720,7 +1721,7 @@ public class SslBytesServerTest extends SslBytesTest
@Override @Override
public Object call() throws Exception public Object call() throws Exception
{ {
clientOutput.write(content2.getBytes("UTF-8")); clientOutput.write(content2.getBytes(StandardCharsets.UTF_8));
clientOutput.flush(); clientOutput.flush();
return null; return null;
} }
@ -1752,7 +1753,7 @@ public class SslBytesServerTest extends SslBytesTest
Assert.assertEquals(TLSRecord.Type.APPLICATION, record.getType()); Assert.assertEquals(TLSRecord.Type.APPLICATION, record.getType());
proxy.flushToClient(record); 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(); String line = reader.readLine();
Assert.assertNotNull(line); Assert.assertNotNull(line);
Assert.assertTrue(line.startsWith("HTTP/1.1 200 ")); Assert.assertTrue(line.startsWith("HTTP/1.1 200 "));
@ -1783,7 +1784,7 @@ public class SslBytesServerTest extends SslBytesTest
byte[] data = new byte[3 * 1024]; byte[] data = new byte[3 * 1024];
Arrays.fill(data, (byte)'Y'); Arrays.fill(data, (byte)'Y');
String content = new String(data, "UTF-8"); String content = new String(data, StandardCharsets.UTF_8);
automaticProxyFlow = proxy.startAutomaticFlow(); automaticProxyFlow = proxy.startAutomaticFlow();
clientOutput.write(("" + clientOutput.write(("" +
"POST / HTTP/1.1\r\n" + "POST / HTTP/1.1\r\n" +
@ -1792,10 +1793,10 @@ public class SslBytesServerTest extends SslBytesTest
"Content-Length: " + content.length() + "\r\n" + "Content-Length: " + content.length() + "\r\n" +
"Connection: close\r\n" + "Connection: close\r\n" +
"\r\n" + "\r\n" +
content).getBytes("UTF-8")); content).getBytes(StandardCharsets.UTF_8));
clientOutput.flush(); 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(); String line = reader.readLine();
Assert.assertNotNull(line); Assert.assertNotNull(line);
Assert.assertTrue(line.startsWith("HTTP/1.1 200 ")); Assert.assertTrue(line.startsWith("HTTP/1.1 200 "));
@ -1841,7 +1842,7 @@ public class SslBytesServerTest extends SslBytesTest
}); });
// Instead of passing the Client Hello, we simulate plain text was passed in // 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 // We expect that the server closes the connection immediately
TLSRecord record = proxy.readFromServer(); TLSRecord record = proxy.readFromServer();
@ -1875,7 +1876,7 @@ public class SslBytesServerTest extends SslBytesTest
clientOutput.write(("" + clientOutput.write(("" +
"GET / HTTP/1.1\r\n" + "GET / HTTP/1.1\r\n" +
"Host: localhost\r\n" + "Host: localhost\r\n" +
"\r\n").getBytes("UTF-8")); "\r\n").getBytes(StandardCharsets.UTF_8));
clientOutput.flush(); clientOutput.flush();
latch.countDown(); latch.countDown();
} }

View File

@ -18,6 +18,7 @@
package org.eclipse.jetty.http; package org.eclipse.jetty.http;
import java.nio.charset.StandardCharsets;
/* ------------------------------------------------------------ */ /* ------------------------------------------------------------ */
/** A HTTP Field /** A HTTP Field

View File

@ -19,6 +19,7 @@
package org.eclipse.jetty.http; package org.eclipse.jetty.http;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
import org.eclipse.jetty.http.HttpTokens.EndOfContent; import org.eclipse.jetty.http.HttpTokens.EndOfContent;
import org.eclipse.jetty.util.ArrayTernaryTrie; import org.eclipse.jetty.util.ArrayTernaryTrie;
@ -1025,12 +1026,12 @@ public class HttpParser
// Have to get the fields exactly from the buffer to match case // Have to get the fields exactly from the buffer to match case
String fn=field.getName(); String fn=field.getName();
String fv=field.getValue(); 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) if (fv==null)
v=null; v=null;
else 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); field=new HttpField(field.getHeader(),n,v);
} }
} }

View File

@ -22,6 +22,7 @@ import java.io.ByteArrayOutputStream;
import java.io.IOException; import java.io.IOException;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.charset.Charset; import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import org.eclipse.jetty.http.HttpGenerator.RequestInfo; import org.eclipse.jetty.http.HttpGenerator.RequestInfo;
import org.eclipse.jetty.http.HttpGenerator.ResponseInfo; import org.eclipse.jetty.http.HttpGenerator.ResponseInfo;
@ -346,7 +347,7 @@ public class HttpTester
String content_type=get(HttpHeader.CONTENT_TYPE); String content_type=get(HttpHeader.CONTENT_TYPE);
String encoding=MimeTypes.getCharsetFromContentType(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); return new String(bytes,charset);
} }

View File

@ -21,6 +21,7 @@ package org.eclipse.jetty.http;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.net.URI; import java.net.URI;
import java.nio.charset.Charset; import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import org.eclipse.jetty.util.MultiMap; import org.eclipse.jetty.util.MultiMap;
import org.eclipse.jetty.util.StringUtil; import org.eclipse.jetty.util.StringUtil;
@ -100,15 +101,7 @@ public class HttpURI
public HttpURI(String raw) public HttpURI(String raw)
{ {
_rawString=raw; _rawString=raw;
byte[] b; byte[] b = raw.getBytes(StandardCharsets.UTF_8);
try
{
b = raw.getBytes(StringUtil.__UTF8);
}
catch (UnsupportedEncodingException e)
{
throw new RuntimeException(e.getMessage());
}
parse(b,0,b.length); parse(b,0,b.length);
_charset = URIUtil.__CHARSET; _charset = URIUtil.__CHARSET;
} }
@ -619,6 +612,11 @@ public class HttpURI
} }
public String getDecodedPath(String encoding) public String getDecodedPath(String encoding)
{
return getDecodedPath(Charset.forName(encoding));
}
public String getDecodedPath(Charset encoding)
{ {
if (_path==_param) if (_path==_param)
return null; return null;
@ -678,9 +676,9 @@ public class HttpURI
if (bytes==null) 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() public String getPathAndParam()
@ -734,10 +732,10 @@ public class HttpURI
{ {
if (_query==_fragment) if (_query==_fragment)
return; return;
if (_charset==StringUtil.__UTF8_CHARSET) if (_charset.equals(StandardCharsets.UTF_8))
UrlEncoded.decodeUtf8To(_raw,_query+1,_fragment-_query-1,parameters); UrlEncoded.decodeUtf8To(_raw,_query+1,_fragment-_query-1,parameters);
else 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 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); 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() public void clear()
{ {
_scheme=_authority=_host=_port=_path=_param=_query=_fragment=_end=0; _scheme=_authority=_host=_port=_path=_param=_query=_fragment=_end=0;

View File

@ -24,6 +24,7 @@ import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -112,7 +113,7 @@ public class HttpParserTest
@Test @Test
public void testLineParse3() throws Exception 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.RequestHandler<ByteBuffer> handler = new Handler();
HttpParser parser= new HttpParser(handler); HttpParser parser= new HttpParser(handler);
@ -126,7 +127,7 @@ public class HttpParserTest
@Test @Test
public void testLineParse4() throws Exception 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.RequestHandler<ByteBuffer> handler = new Handler();
HttpParser parser= new HttpParser(handler); HttpParser parser= new HttpParser(handler);
@ -346,10 +347,10 @@ public class HttpParserTest
ByteBuffer buffer=BufferUtil.allocate(4096); ByteBuffer buffer=BufferUtil.allocate(4096);
BufferUtil.flipToFill(buffer); BufferUtil.flipToFill(buffer);
BufferUtil.put(BufferUtil.toBuffer("GET "),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(" HTTP/1.0\r\n"),buffer);
BufferUtil.put(BufferUtil.toBuffer("Header1: "),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.put(BufferUtil.toBuffer(" \r\n\r\n"),buffer);
BufferUtil.flipToFlush(buffer,0); BufferUtil.flipToFlush(buffer,0);
@ -1348,7 +1349,7 @@ public class HttpParserTest
{ {
if (_content==null) if (_content==null)
_content=""; _content="";
String c = BufferUtil.toString(ref,StringUtil.__UTF8_CHARSET); String c = BufferUtil.toString(ref,StandardCharsets.UTF_8);
//System.err.println("content '"+c+"'"); //System.err.println("content '"+c+"'");
_content= _content + c; _content= _content + c;
ref.position(ref.limit()); ref.position(ref.limit());

View File

@ -23,6 +23,7 @@ import java.net.InetSocketAddress;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.channels.ClosedChannelException; import java.nio.channels.ClosedChannelException;
import java.nio.charset.Charset; import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import org.eclipse.jetty.util.BufferUtil; import org.eclipse.jetty.util.BufferUtil;
import org.eclipse.jetty.util.StringUtil; import org.eclipse.jetty.util.StringUtil;
@ -153,7 +154,7 @@ public class ByteArrayEndPoint extends AbstractEndPoint
/* ------------------------------------------------------------ */ /* ------------------------------------------------------------ */
public void setInput(String s) 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() 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() public String takeOutputString()
{ {
return takeOutputString(StringUtil.__UTF8_CHARSET); return takeOutputString(StandardCharsets.UTF_8);
} }
/* ------------------------------------------------------------ */ /* ------------------------------------------------------------ */

View File

@ -21,6 +21,7 @@ package org.eclipse.jetty.io;
import java.io.IOException; import java.io.IOException;
import java.io.OutputStream; import java.io.OutputStream;
import java.io.Writer; import java.io.Writer;
import java.nio.charset.Charset;
/* ------------------------------------------------------------ */ /* ------------------------------------------------------------ */
@ -33,14 +34,14 @@ import java.io.Writer;
public class WriterOutputStream extends OutputStream public class WriterOutputStream extends OutputStream
{ {
protected final Writer _writer; protected final Writer _writer;
protected final String _encoding; protected final Charset _encoding;
private final byte[] _buf=new byte[1]; private final byte[] _buf=new byte[1];
/* ------------------------------------------------------------ */ /* ------------------------------------------------------------ */
public WriterOutputStream(Writer writer, String encoding) public WriterOutputStream(Writer writer, String encoding)
{ {
_writer=writer; _writer=writer;
_encoding=encoding; _encoding=encoding==null?null:Charset.forName(encoding);
} }
/* ------------------------------------------------------------ */ /* ------------------------------------------------------------ */

View File

@ -36,6 +36,7 @@ import java.nio.channels.AsynchronousServerSocketChannel;
import java.nio.channels.AsynchronousSocketChannel; import java.nio.channels.AsynchronousSocketChannel;
import java.nio.channels.ServerSocketChannel; import java.nio.channels.ServerSocketChannel;
import java.nio.channels.SocketChannel; import java.nio.channels.SocketChannel;
import java.nio.charset.StandardCharsets;
import java.util.concurrent.CountDownLatch; import java.util.concurrent.CountDownLatch;
import java.util.concurrent.Future; import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
@ -444,7 +445,7 @@ public class IOTest
ByteBuffer read = ByteBuffer.allocate(1024); ByteBuffer read = ByteBuffer.allocate(1024);
Future<Integer> reading = server.read(read); 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); ByteBuffer write = BufferUtil.toBuffer(data);
Future<Integer> writing = client.write(write); Future<Integer> writing = client.write(write);

View File

@ -23,6 +23,7 @@ import java.io.IOException;
import java.net.Socket; import java.net.Socket;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.channels.SocketChannel; import java.nio.channels.SocketChannel;
import java.nio.charset.StandardCharsets;
import javax.net.ssl.SSLEngine; import javax.net.ssl.SSLEngine;
import javax.net.ssl.SSLEngineResult; import javax.net.ssl.SSLEngineResult;
import javax.net.ssl.SSLEngineResult.HandshakeStatus; import javax.net.ssl.SSLEngineResult.HandshakeStatus;
@ -170,7 +171,7 @@ public class SelectChannelEndPointSslTest extends SelectChannelEndPointTest
if (debug) System.err.println("\nSay Hello"); if (debug) System.err.println("\nSay Hello");
// write a message // write a message
appOut.put("HelloWorld".getBytes("UTF-8")); appOut.put("HelloWorld".getBytes(StandardCharsets.UTF_8));
appOut.flip(); appOut.flip();
SSLEngineResult result =engine.wrap(appOut,sslOut); SSLEngineResult result =engine.wrap(appOut,sslOut);
if (debug) System.err.println(result); if (debug) System.err.println(result);

View File

@ -29,6 +29,7 @@ import java.nio.ByteBuffer;
import java.nio.channels.SelectionKey; import java.nio.channels.SelectionKey;
import java.nio.channels.ServerSocketChannel; import java.nio.channels.ServerSocketChannel;
import java.nio.channels.SocketChannel; import java.nio.channels.SocketChannel;
import java.nio.charset.StandardCharsets;
import java.util.concurrent.CountDownLatch; import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
@ -228,7 +229,7 @@ public class SelectChannelEndPointTest
_manager.accept(server); _manager.accept(server);
// Write client to 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 // Verify echo server to client
for (char c : "HelloWorld".toCharArray()) for (char c : "HelloWorld".toCharArray())
@ -253,7 +254,7 @@ public class SelectChannelEndPointTest
} }
// write then shutdown // 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 // Verify echo server to client
for (char c : "Goodbye Cruel TLS".toCharArray()) for (char c : "Goodbye Cruel TLS".toCharArray())
@ -287,7 +288,7 @@ public class SelectChannelEndPointTest
_manager.accept(server); _manager.accept(server);
// Write client to 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 // Verify echo server to client
for (char c : "HelloWorld".toCharArray()) for (char c : "HelloWorld".toCharArray())
@ -310,7 +311,7 @@ public class SelectChannelEndPointTest
} }
// write then shutdown // write then shutdown
client.getOutputStream().write("Goodbye Cruel TLS".getBytes("UTF-8")); client.getOutputStream().write("Goodbye Cruel TLS".getBytes(StandardCharsets.UTF_8));
client.shutdownOutput(); client.shutdownOutput();
// Verify echo server to client // Verify echo server to client
@ -343,7 +344,7 @@ public class SelectChannelEndPointTest
// Write 8 and cause block waiting for 10 // Write 8 and cause block waiting for 10
_blockAt = 10; _blockAt = 10;
clientOutputStream.write("12345678".getBytes("UTF-8")); clientOutputStream.write("12345678".getBytes(StandardCharsets.UTF_8));
clientOutputStream.flush(); clientOutputStream.flush();
Assert.assertTrue(_lastEndPointLatch.await(1, TimeUnit.SECONDS)); Assert.assertTrue(_lastEndPointLatch.await(1, TimeUnit.SECONDS));
@ -363,7 +364,7 @@ public class SelectChannelEndPointTest
} }
// write remaining characters // write remaining characters
clientOutputStream.write("90ABCDEF".getBytes("UTF-8")); clientOutputStream.write("90ABCDEF".getBytes(StandardCharsets.UTF_8));
clientOutputStream.flush(); clientOutputStream.flush();
// Verify echo server to client // Verify echo server to client
@ -388,7 +389,7 @@ public class SelectChannelEndPointTest
_manager.accept(server); _manager.accept(server);
// Write client to 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 // Verify echo server to client
for (char c : "HelloWorld".toCharArray()) for (char c : "HelloWorld".toCharArray())
@ -436,7 +437,7 @@ public class SelectChannelEndPointTest
_manager.accept(server); _manager.accept(server);
// Write client to server // Write client to server
clientOutputStream.write("HelloWorld".getBytes("UTF-8")); clientOutputStream.write("HelloWorld".getBytes(StandardCharsets.UTF_8));
// Verify echo server to client // Verify echo server to client
for (char c : "HelloWorld".toCharArray()) for (char c : "HelloWorld".toCharArray())
@ -452,7 +453,7 @@ public class SelectChannelEndPointTest
// Write 8 and cause block waiting for 10 // Write 8 and cause block waiting for 10
_blockAt = 10; _blockAt = 10;
clientOutputStream.write("12345678".getBytes("UTF-8")); clientOutputStream.write("12345678".getBytes(StandardCharsets.UTF_8));
clientOutputStream.flush(); clientOutputStream.flush();
// read until idle shutdown received // read until idle shutdown received
@ -493,8 +494,8 @@ public class SelectChannelEndPointTest
_manager.accept(server); _manager.accept(server);
final int writes = 200000; final int writes = 200000;
final byte[] bytes = "HelloWorld-".getBytes(StringUtil.__UTF8_CHARSET); final byte[] bytes = "HelloWorld-".getBytes(StandardCharsets.UTF_8);
byte[] count = "0\n".getBytes(StringUtil.__UTF8_CHARSET); byte[] count = "0\n".getBytes(StandardCharsets.UTF_8);
BufferedOutputStream out = new BufferedOutputStream(client.getOutputStream()); BufferedOutputStream out = new BufferedOutputStream(client.getOutputStream());
final CountDownLatch latch = new CountDownLatch(writes); final CountDownLatch latch = new CountDownLatch(writes);
final InputStream in = new BufferedInputStream(client.getInputStream()); final InputStream in = new BufferedInputStream(client.getInputStream());
@ -561,7 +562,7 @@ public class SelectChannelEndPointTest
for (int i = 1; i < writes; i++) for (int i = 1; i < writes; i++)
{ {
out.write(bytes); 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'); out.write('\n');
if (i % 1000 == 0) if (i % 1000 == 0)
{ {
@ -599,7 +600,7 @@ public class SelectChannelEndPointTest
// Write client to server // Write client to server
_writeCount = 10000; _writeCount = 10000;
String data = "Now is the time for all good men to come to the aid of the party"; 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()); BufferedInputStream in = new BufferedInputStream(client.getInputStream());
int byteNum = 0; int byteNum = 0;

View File

@ -27,6 +27,7 @@ import java.nio.ByteBuffer;
import java.nio.channels.SelectionKey; import java.nio.channels.SelectionKey;
import java.nio.channels.ServerSocketChannel; import java.nio.channels.ServerSocketChannel;
import java.nio.channels.SocketChannel; import java.nio.channels.SocketChannel;
import java.nio.charset.StandardCharsets;
import java.util.concurrent.CountDownLatch; import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
@ -234,14 +235,14 @@ public class SslConnectionTest
server.configureBlocking(false); server.configureBlocking(false);
_manager.accept(server); _manager.accept(server);
client.getOutputStream().write("Hello".getBytes("UTF-8")); client.getOutputStream().write("Hello".getBytes(StandardCharsets.UTF_8));
byte[] buffer = new byte[1024]; byte[] buffer = new byte[1024];
int len=client.getInputStream().read(buffer); int len=client.getInputStream().read(buffer);
Assert.assertEquals(5, len); 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); _dispatches.set(0);
client.getOutputStream().write("World".getBytes("UTF-8")); client.getOutputStream().write("World".getBytes(StandardCharsets.UTF_8));
len=5; len=5;
while(len>0) while(len>0)
len-=client.getInputStream().read(buffer); len-=client.getInputStream().read(buffer);
@ -266,7 +267,7 @@ public class SslConnectionTest
byte[] buffer = new byte[1024]; byte[] buffer = new byte[1024];
int len=client.getInputStream().read(buffer); 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)); Assert.assertEquals(null,_writeCallback.get(100,TimeUnit.MILLISECONDS));
client.close(); client.close();
} }
@ -292,7 +293,7 @@ public class SslConnectionTest
{ {
try 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) while(count.getCount()>0)
{ {
String line=in.readLine(); String line=in.readLine();
@ -311,7 +312,7 @@ public class SslConnectionTest
for (int i=0;i<LINES;i++) 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"); // System.err.println("wrote");
if (i%1000==0) if (i%1000==0)
{ {

View File

@ -19,6 +19,7 @@
package org.eclipse.jetty.security.jaspi.modules; package org.eclipse.jetty.security.jaspi.modules;
import java.io.IOException; import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
@ -119,7 +120,7 @@ public class BaseAuthModule implements ServerAuthModule, ServerAuthContext
throws IOException, UnsupportedCallbackException throws IOException, UnsupportedCallbackException
{ {
credentials = credentials.substring(credentials.indexOf(' ')+1); 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(':'); int i = credentials.indexOf(':');
String userName = credentials.substring(0,i); String userName = credentials.substring(0,i);
String password = credentials.substring(i+1); String password = credentials.substring(i+1);

View File

@ -19,6 +19,7 @@
package org.eclipse.jetty.security.jaspi.modules; package org.eclipse.jetty.security.jaspi.modules;
import java.io.IOException; import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest; import java.security.MessageDigest;
import java.util.Map; import java.util.Map;
@ -306,18 +307,18 @@ public class DigestAuthModule extends BaseAuthModule
else else
{ {
// calc A1 digest // calc A1 digest
md.update(username.getBytes(StringUtil.__ISO_8859_1)); md.update(username.getBytes(StandardCharsets.ISO_8859_1));
md.update((byte) ':'); md.update((byte) ':');
md.update(realm.getBytes(StringUtil.__ISO_8859_1)); md.update(realm.getBytes(StandardCharsets.ISO_8859_1));
md.update((byte) ':'); md.update((byte) ':');
md.update(password.getBytes(StringUtil.__ISO_8859_1)); md.update(password.getBytes(StandardCharsets.ISO_8859_1));
ha1 = md.digest(); ha1 = md.digest();
} }
// calc A2 digest // calc A2 digest
md.reset(); md.reset();
md.update(method.getBytes(StringUtil.__ISO_8859_1)); md.update(method.getBytes(StandardCharsets.ISO_8859_1));
md.update((byte) ':'); md.update((byte) ':');
md.update(uri.getBytes(StringUtil.__ISO_8859_1)); md.update(uri.getBytes(StandardCharsets.ISO_8859_1));
byte[] ha2 = md.digest(); byte[] ha2 = md.digest();
// calc digest // calc digest
@ -327,17 +328,17 @@ public class DigestAuthModule extends BaseAuthModule
// request-digest = <"> < KD ( H(A1), unq(nonce-value) ":" H(A2) // 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((byte) ':');
md.update(nonce.getBytes(StringUtil.__ISO_8859_1)); md.update(nonce.getBytes(StandardCharsets.ISO_8859_1));
md.update((byte) ':'); md.update((byte) ':');
md.update(nc.getBytes(StringUtil.__ISO_8859_1)); md.update(nc.getBytes(StandardCharsets.ISO_8859_1));
md.update((byte) ':'); md.update((byte) ':');
md.update(cnonce.getBytes(StringUtil.__ISO_8859_1)); md.update(cnonce.getBytes(StandardCharsets.ISO_8859_1));
md.update((byte) ':'); md.update((byte) ':');
md.update(qop.getBytes(StringUtil.__ISO_8859_1)); md.update(qop.getBytes(StandardCharsets.ISO_8859_1));
md.update((byte) ':'); 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(); byte[] digest = md.digest();
// check digest // check digest

View File

@ -25,6 +25,7 @@ import java.io.InputStream;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.io.OutputStream; import java.io.OutputStream;
import java.net.Socket; import java.net.Socket;
import java.nio.charset.StandardCharsets;
import javax.net.ssl.SSLContext; import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSocket; import javax.net.ssl.SSLSocket;
@ -78,7 +79,7 @@ public class ConnectHandlerSSLTest extends AbstractConnectHandlerTest
OutputStream output = socket.getOutputStream(); OutputStream output = socket.getOutputStream();
BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream())); BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
output.write(request.getBytes("UTF-8")); output.write(request.getBytes(StandardCharsets.UTF_8));
output.flush(); output.flush();
// Expect 200 OK from the CONNECT request // Expect 200 OK from the CONNECT request
@ -98,7 +99,7 @@ public class ConnectHandlerSSLTest extends AbstractConnectHandlerTest
"GET /echo HTTP/1.1\r\n" + "GET /echo HTTP/1.1\r\n" +
"Host: " + hostPort + "\r\n" + "Host: " + hostPort + "\r\n" +
"\r\n"; "\r\n";
output.write(request.getBytes("UTF-8")); output.write(request.getBytes(StandardCharsets.UTF_8));
output.flush(); output.flush();
response = readResponse(input); response = readResponse(input);
@ -121,7 +122,7 @@ public class ConnectHandlerSSLTest extends AbstractConnectHandlerTest
OutputStream output = socket.getOutputStream(); OutputStream output = socket.getOutputStream();
BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream())); BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
output.write(request.getBytes("UTF-8")); output.write(request.getBytes(StandardCharsets.UTF_8));
output.flush(); output.flush();
// Expect 200 OK from the CONNECT request // Expect 200 OK from the CONNECT request
@ -145,7 +146,7 @@ public class ConnectHandlerSSLTest extends AbstractConnectHandlerTest
"Content-Length: 5\r\n" + "Content-Length: 5\r\n" +
"\r\n" + "\r\n" +
"HELLO"; "HELLO";
output.write(request.getBytes("UTF-8")); output.write(request.getBytes(StandardCharsets.UTF_8));
output.flush(); output.flush();
response = readResponse(input); response = readResponse(input);

View File

@ -27,6 +27,7 @@ import java.io.OutputStream;
import java.net.InetAddress; import java.net.InetAddress;
import java.net.Socket; import java.net.Socket;
import java.net.UnknownHostException; import java.net.UnknownHostException;
import java.nio.charset.StandardCharsets;
import java.util.Locale; import java.util.Locale;
import java.util.concurrent.ConcurrentMap; import java.util.concurrent.ConcurrentMap;
@ -71,7 +72,7 @@ public class ConnectHandlerTest extends AbstractConnectHandlerTest
OutputStream output = socket.getOutputStream(); OutputStream output = socket.getOutputStream();
BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream())); BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
output.write(request.getBytes("UTF-8")); output.write(request.getBytes(StandardCharsets.UTF_8));
output.flush(); output.flush();
// Expect 200 OK from the CONNECT request // Expect 200 OK from the CONNECT request
@ -93,7 +94,7 @@ public class ConnectHandlerTest extends AbstractConnectHandlerTest
OutputStream output = socket.getOutputStream(); OutputStream output = socket.getOutputStream();
BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream())); BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
output.write(request.getBytes("UTF-8")); output.write(request.getBytes(StandardCharsets.UTF_8));
output.flush(); output.flush();
// Expect 200 OK from the CONNECT request // Expect 200 OK from the CONNECT request
@ -104,7 +105,7 @@ public class ConnectHandlerTest extends AbstractConnectHandlerTest
"GET /echo" + " HTTP/1.1\r\n" + "GET /echo" + " HTTP/1.1\r\n" +
"Host: " + hostPort + "\r\n" + "Host: " + hostPort + "\r\n" +
"\r\n"; "\r\n";
output.write(request.getBytes("UTF-8")); output.write(request.getBytes(StandardCharsets.UTF_8));
output.flush(); output.flush();
response = readResponse(input); response = readResponse(input);
@ -130,7 +131,7 @@ public class ConnectHandlerTest extends AbstractConnectHandlerTest
OutputStream output = socket.getOutputStream(); OutputStream output = socket.getOutputStream();
BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream())); BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
output.write(request.getBytes("UTF-8")); output.write(request.getBytes(StandardCharsets.UTF_8));
output.flush(); output.flush();
// Expect 403 from the CONNECT request // Expect 403 from the CONNECT request
@ -151,7 +152,7 @@ public class ConnectHandlerTest extends AbstractConnectHandlerTest
OutputStream output = socket.getOutputStream(); OutputStream output = socket.getOutputStream();
BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream())); BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
output.write(request.getBytes("UTF-8")); output.write(request.getBytes(StandardCharsets.UTF_8));
output.flush(); output.flush();
// Expect 200 from the CONNECT request // Expect 200 from the CONNECT request
@ -162,7 +163,7 @@ public class ConnectHandlerTest extends AbstractConnectHandlerTest
"GET /echo" + " HTTP/1.1\r\n" + "GET /echo" + " HTTP/1.1\r\n" +
"Host: " + hostPort + "\r\n" + "Host: " + hostPort + "\r\n" +
"\r\n"; "\r\n";
output.write(request.getBytes("UTF-8")); output.write(request.getBytes(StandardCharsets.UTF_8));
output.flush(); output.flush();
response = readResponse(input); response = readResponse(input);
@ -188,7 +189,7 @@ public class ConnectHandlerTest extends AbstractConnectHandlerTest
OutputStream output = socket.getOutputStream(); OutputStream output = socket.getOutputStream();
BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream())); BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
output.write(request.getBytes("UTF-8")); output.write(request.getBytes(StandardCharsets.UTF_8));
output.flush(); output.flush();
// Expect 403 from the CONNECT request // Expect 403 from the CONNECT request
@ -209,7 +210,7 @@ public class ConnectHandlerTest extends AbstractConnectHandlerTest
OutputStream output = socket.getOutputStream(); OutputStream output = socket.getOutputStream();
BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream())); BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
output.write(request.getBytes("UTF-8")); output.write(request.getBytes(StandardCharsets.UTF_8));
output.flush(); output.flush();
// Expect 200 from the CONNECT request // Expect 200 from the CONNECT request
@ -220,7 +221,7 @@ public class ConnectHandlerTest extends AbstractConnectHandlerTest
"GET /echo" + " HTTP/1.1\r\n" + "GET /echo" + " HTTP/1.1\r\n" +
"Host: 127.0.0.1:" + port + "\r\n" + "Host: 127.0.0.1:" + port + "\r\n" +
"\r\n"; "\r\n";
output.write(request.getBytes("UTF-8")); output.write(request.getBytes(StandardCharsets.UTF_8));
output.flush(); output.flush();
response = readResponse(input); response = readResponse(input);
@ -245,7 +246,7 @@ public class ConnectHandlerTest extends AbstractConnectHandlerTest
return false; return false;
} }
String b64 = proxyAuthorization.substring("Basic ".length()); 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); return "test:test".equals(credentials);
} }
}; };
@ -265,7 +266,7 @@ public class ConnectHandlerTest extends AbstractConnectHandlerTest
OutputStream output = socket.getOutputStream(); OutputStream output = socket.getOutputStream();
BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream())); BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
output.write(request.getBytes("UTF-8")); output.write(request.getBytes(StandardCharsets.UTF_8));
output.flush(); output.flush();
// Expect 407 from the CONNECT request // Expect 407 from the CONNECT request
@ -289,7 +290,7 @@ public class ConnectHandlerTest extends AbstractConnectHandlerTest
OutputStream output = socket.getOutputStream(); OutputStream output = socket.getOutputStream();
BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream())); BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
output.write(request.getBytes("UTF-8")); output.write(request.getBytes(StandardCharsets.UTF_8));
output.flush(); output.flush();
// Expect 200 from the CONNECT request // Expect 200 from the CONNECT request
@ -300,7 +301,7 @@ public class ConnectHandlerTest extends AbstractConnectHandlerTest
"GET /echo" + " HTTP/1.1\r\n" + "GET /echo" + " HTTP/1.1\r\n" +
"Host: " + hostPort + "\r\n" + "Host: " + hostPort + "\r\n" +
"\r\n"; "\r\n";
output.write(request.getBytes("UTF-8")); output.write(request.getBytes(StandardCharsets.UTF_8));
output.flush(); output.flush();
response = readResponse(input); response = readResponse(input);
@ -342,7 +343,7 @@ public class ConnectHandlerTest extends AbstractConnectHandlerTest
OutputStream output = socket.getOutputStream(); OutputStream output = socket.getOutputStream();
BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream())); BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
output.write(request.getBytes("UTF-8")); output.write(request.getBytes(StandardCharsets.UTF_8));
output.flush(); output.flush();
// Expect 500 OK from the CONNECT request // Expect 500 OK from the CONNECT request
@ -368,7 +369,7 @@ public class ConnectHandlerTest extends AbstractConnectHandlerTest
OutputStream output = socket.getOutputStream(); OutputStream output = socket.getOutputStream();
BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream())); BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
output.write(request.getBytes("UTF-8")); output.write(request.getBytes(StandardCharsets.UTF_8));
output.flush(); output.flush();
// Expect 200 OK from the CONNECT request // Expect 200 OK from the CONNECT request
@ -379,7 +380,7 @@ public class ConnectHandlerTest extends AbstractConnectHandlerTest
"GET /echo" + " HTTP/1.1\r\n" + "GET /echo" + " HTTP/1.1\r\n" +
"Host: " + hostPort + "\r\n" + "Host: " + hostPort + "\r\n" +
"\r\n"; "\r\n";
output.write(request.getBytes("UTF-8")); output.write(request.getBytes(StandardCharsets.UTF_8));
output.flush(); output.flush();
response = readResponse(input); response = readResponse(input);
@ -404,7 +405,7 @@ public class ConnectHandlerTest extends AbstractConnectHandlerTest
OutputStream output = socket.getOutputStream(); OutputStream output = socket.getOutputStream();
BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream())); BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
output.write(request.getBytes("UTF-8")); output.write(request.getBytes(StandardCharsets.UTF_8));
output.flush(); output.flush();
// Expect 200 OK from the CONNECT request // Expect 200 OK from the CONNECT request
@ -431,7 +432,7 @@ public class ConnectHandlerTest extends AbstractConnectHandlerTest
OutputStream output = socket.getOutputStream(); OutputStream output = socket.getOutputStream();
BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream())); BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
output.write(request.getBytes("UTF-8")); output.write(request.getBytes(StandardCharsets.UTF_8));
output.flush(); output.flush();
// Expect 200 OK from the CONNECT request // Expect 200 OK from the CONNECT request
@ -444,7 +445,7 @@ public class ConnectHandlerTest extends AbstractConnectHandlerTest
"GET /echo" + " HTTP/1.1\r\n" + "GET /echo" + " HTTP/1.1\r\n" +
"Host: " + hostPort + "\r\n" + "Host: " + hostPort + "\r\n" +
"\r\n"; "\r\n";
output.write(request.getBytes("UTF-8")); output.write(request.getBytes(StandardCharsets.UTF_8));
output.flush(); output.flush();
response = readResponse(input); response = readResponse(input);
@ -467,7 +468,7 @@ public class ConnectHandlerTest extends AbstractConnectHandlerTest
OutputStream output = socket.getOutputStream(); OutputStream output = socket.getOutputStream();
BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream())); BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
output.write(request.getBytes("UTF-8")); output.write(request.getBytes(StandardCharsets.UTF_8));
output.flush(); output.flush();
// Expect 200 OK from the CONNECT request // Expect 200 OK from the CONNECT request
@ -478,7 +479,7 @@ public class ConnectHandlerTest extends AbstractConnectHandlerTest
"GET /echo HTTP/1.1\r\n" + "GET /echo HTTP/1.1\r\n" +
"Host: " + hostPort + "\r\n" + "Host: " + hostPort + "\r\n" +
"\r\n"; "\r\n";
output.write(request.getBytes("UTF-8")); output.write(request.getBytes(StandardCharsets.UTF_8));
output.flush(); output.flush();
response = readResponse(input); response = readResponse(input);
@ -506,7 +507,7 @@ public class ConnectHandlerTest extends AbstractConnectHandlerTest
OutputStream output = socket.getOutputStream(); OutputStream output = socket.getOutputStream();
BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream())); BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
output.write(request.getBytes("UTF-8")); output.write(request.getBytes(StandardCharsets.UTF_8));
output.flush(); output.flush();
// Expect 200 OK from the CONNECT request // Expect 200 OK from the CONNECT request
@ -517,7 +518,7 @@ public class ConnectHandlerTest extends AbstractConnectHandlerTest
"GET /close HTTP/1.1\r\n" + "GET /close HTTP/1.1\r\n" +
"Host: " + hostPort + "\r\n" + "Host: " + hostPort + "\r\n" +
"\r\n"; "\r\n";
output.write(request.getBytes("UTF-8")); output.write(request.getBytes(StandardCharsets.UTF_8));
output.flush(); output.flush();
int read = input.read(); int read = input.read();
@ -538,7 +539,7 @@ public class ConnectHandlerTest extends AbstractConnectHandlerTest
OutputStream output = socket.getOutputStream(); OutputStream output = socket.getOutputStream();
BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream())); BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
output.write(request.getBytes("UTF-8")); output.write(request.getBytes(StandardCharsets.UTF_8));
output.flush(); output.flush();
// Expect 200 OK from the CONNECT request // Expect 200 OK from the CONNECT request
@ -551,7 +552,7 @@ public class ConnectHandlerTest extends AbstractConnectHandlerTest
"Content-Length: 5\r\n" + "Content-Length: 5\r\n" +
"\r\n" + "\r\n" +
"HELLO"; "HELLO";
output.write(request.getBytes("UTF-8")); output.write(request.getBytes(StandardCharsets.UTF_8));
output.flush(); output.flush();
response = readResponse(input); response = readResponse(input);
@ -562,7 +563,7 @@ public class ConnectHandlerTest extends AbstractConnectHandlerTest
"GET /echo" + " HTTP/1.1\r\n" + "GET /echo" + " HTTP/1.1\r\n" +
"Host: " + hostPort + "\r\n" + "Host: " + hostPort + "\r\n" +
"\r\n"; "\r\n";
output.write(request.getBytes("UTF-8")); output.write(request.getBytes(StandardCharsets.UTF_8));
output.flush(); output.flush();
response = readResponse(input); response = readResponse(input);
@ -585,7 +586,7 @@ public class ConnectHandlerTest extends AbstractConnectHandlerTest
OutputStream output = socket.getOutputStream(); OutputStream output = socket.getOutputStream();
BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream())); BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
output.write(request.getBytes("UTF-8")); output.write(request.getBytes(StandardCharsets.UTF_8));
output.flush(); output.flush();
// Expect 200 OK from the CONNECT request // Expect 200 OK from the CONNECT request
@ -603,7 +604,7 @@ public class ConnectHandlerTest extends AbstractConnectHandlerTest
"Content-Length: " + body.length() + "\r\n" + "Content-Length: " + body.length() + "\r\n" +
"\r\n" + "\r\n" +
body; body;
output.write(request.getBytes("UTF-8")); output.write(request.getBytes(StandardCharsets.UTF_8));
output.flush(); output.flush();
response = readResponse(input); response = readResponse(input);
@ -649,7 +650,7 @@ public class ConnectHandlerTest extends AbstractConnectHandlerTest
OutputStream output = socket.getOutputStream(); OutputStream output = socket.getOutputStream();
BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream())); BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
output.write(request.getBytes("UTF-8")); output.write(request.getBytes(StandardCharsets.UTF_8));
output.flush(); output.flush();
// Expect 200 OK from the CONNECT request // Expect 200 OK from the CONNECT request
@ -663,7 +664,7 @@ public class ConnectHandlerTest extends AbstractConnectHandlerTest
"Content-Length: " + body.length() + "\r\n" + "Content-Length: " + body.length() + "\r\n" +
"\r\n" + "\r\n" +
body; body;
output.write(request.getBytes("UTF-8")); output.write(request.getBytes(StandardCharsets.UTF_8));
output.flush(); output.flush();
response = readResponse(input); response = readResponse(input);
@ -688,7 +689,7 @@ public class ConnectHandlerTest extends AbstractConnectHandlerTest
OutputStream output = socket.getOutputStream(); OutputStream output = socket.getOutputStream();
BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream())); BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
output.write(request.getBytes("UTF-8")); output.write(request.getBytes(StandardCharsets.UTF_8));
output.flush(); output.flush();
socket.shutdownOutput(); socket.shutdownOutput();
@ -716,7 +717,7 @@ public class ConnectHandlerTest extends AbstractConnectHandlerTest
OutputStream output = socket.getOutputStream(); OutputStream output = socket.getOutputStream();
BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream())); BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
output.write(request.getBytes("UTF-8")); output.write(request.getBytes(StandardCharsets.UTF_8));
output.flush(); output.flush();
// Expect 200 OK from the CONNECT request // Expect 200 OK from the CONNECT request
@ -727,7 +728,7 @@ public class ConnectHandlerTest extends AbstractConnectHandlerTest
"GET /echo" + " HTTP/1.1\r\n" + "GET /echo" + " HTTP/1.1\r\n" +
"Host: " + hostPort + "\r\n" + "Host: " + hostPort + "\r\n" +
"\r\n"; "\r\n";
output.write(request.getBytes("UTF-8")); output.write(request.getBytes(StandardCharsets.UTF_8));
output.flush(); output.flush();
socket.shutdownOutput(); socket.shutdownOutput();

View File

@ -21,6 +21,7 @@ package org.eclipse.jetty.rewrite.handler;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import java.io.IOException; import java.io.IOException;
import java.nio.charset.StandardCharsets;
import org.eclipse.jetty.http.HttpURI; import org.eclipse.jetty.http.HttpURI;
import org.eclipse.jetty.util.MultiMap; import org.eclipse.jetty.util.MultiMap;
@ -87,7 +88,7 @@ public class RewriteRegexRuleTest extends AbstractRuleTestCase
if (test[5]!=null) if (test[5]!=null)
{ {
MultiMap<String> params=new MultiMap<String>(); 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()) for (String n:params.keySet())
assertEquals(params.getString(n),_request.getParameter(n)); assertEquals(params.getString(n),_request.getParameter(n));

View File

@ -19,6 +19,7 @@
package org.eclipse.jetty.security.authentication; package org.eclipse.jetty.security.authentication;
import java.io.IOException; import java.io.IOException;
import java.nio.charset.StandardCharsets;
import javax.servlet.ServletRequest; import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse; import javax.servlet.ServletResponse;
@ -82,7 +83,7 @@ public class BasicAuthenticator extends LoginAuthenticator
if ("basic".equalsIgnoreCase(method)) if ("basic".equalsIgnoreCase(method))
{ {
credentials = credentials.substring(space+1); 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(':'); int i = credentials.indexOf(':');
if (i>0) if (i>0)
{ {

View File

@ -19,6 +19,7 @@
package org.eclipse.jetty.security.authentication; package org.eclipse.jetty.security.authentication;
import java.io.IOException; import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest; import java.security.MessageDigest;
import java.security.SecureRandom; import java.security.SecureRandom;
import java.util.BitSet; import java.util.BitSet;
@ -367,18 +368,18 @@ public class DigestAuthenticator extends LoginAuthenticator
else else
{ {
// calc A1 digest // calc A1 digest
md.update(username.getBytes(StringUtil.__ISO_8859_1)); md.update(username.getBytes(StandardCharsets.ISO_8859_1));
md.update((byte) ':'); md.update((byte) ':');
md.update(realm.getBytes(StringUtil.__ISO_8859_1)); md.update(realm.getBytes(StandardCharsets.ISO_8859_1));
md.update((byte) ':'); md.update((byte) ':');
md.update(password.getBytes(StringUtil.__ISO_8859_1)); md.update(password.getBytes(StandardCharsets.ISO_8859_1));
ha1 = md.digest(); ha1 = md.digest();
} }
// calc A2 digest // calc A2 digest
md.reset(); md.reset();
md.update(method.getBytes(StringUtil.__ISO_8859_1)); md.update(method.getBytes(StandardCharsets.ISO_8859_1));
md.update((byte) ':'); md.update((byte) ':');
md.update(uri.getBytes(StringUtil.__ISO_8859_1)); md.update(uri.getBytes(StandardCharsets.ISO_8859_1));
byte[] ha2 = md.digest(); byte[] ha2 = md.digest();
// calc digest // calc digest
@ -388,17 +389,17 @@ public class DigestAuthenticator extends LoginAuthenticator
// request-digest = <"> < KD ( H(A1), unq(nonce-value) ":" H(A2) // 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((byte) ':');
md.update(nonce.getBytes(StringUtil.__ISO_8859_1)); md.update(nonce.getBytes(StandardCharsets.ISO_8859_1));
md.update((byte) ':'); md.update((byte) ':');
md.update(nc.getBytes(StringUtil.__ISO_8859_1)); md.update(nc.getBytes(StandardCharsets.ISO_8859_1));
md.update((byte) ':'); md.update((byte) ':');
md.update(cnonce.getBytes(StringUtil.__ISO_8859_1)); md.update(cnonce.getBytes(StandardCharsets.ISO_8859_1));
md.update((byte) ':'); md.update((byte) ':');
md.update(qop.getBytes(StringUtil.__ISO_8859_1)); md.update(qop.getBytes(StandardCharsets.ISO_8859_1));
md.update((byte) ':'); 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(); byte[] digest = md.digest();
// check digest // check digest

View File

@ -27,6 +27,7 @@ import static org.junit.Assert.assertTrue;
import static org.junit.matchers.JUnitMatchers.containsString; import static org.junit.matchers.JUnitMatchers.containsString;
import java.io.IOException; import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest; import java.security.MessageDigest;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
@ -569,17 +570,17 @@ public class ConstraintTest
MessageDigest md = MessageDigest.getInstance("MD5"); MessageDigest md = MessageDigest.getInstance("MD5");
byte[] ha1; byte[] ha1;
// calc A1 digest // calc A1 digest
md.update(username.getBytes(StringUtil.__ISO_8859_1)); md.update(username.getBytes(StandardCharsets.ISO_8859_1));
md.update((byte) ':'); md.update((byte) ':');
md.update("TestRealm".getBytes(StringUtil.__ISO_8859_1)); md.update("TestRealm".getBytes(StandardCharsets.ISO_8859_1));
md.update((byte) ':'); md.update((byte) ':');
md.update(password.getBytes(StringUtil.__ISO_8859_1)); md.update(password.getBytes(StandardCharsets.ISO_8859_1));
ha1 = md.digest(); ha1 = md.digest();
// calc A2 digest // calc A2 digest
md.reset(); md.reset();
md.update("GET".getBytes(StringUtil.__ISO_8859_1)); md.update("GET".getBytes(StandardCharsets.ISO_8859_1));
md.update((byte) ':'); md.update((byte) ':');
md.update(uri.getBytes(StringUtil.__ISO_8859_1)); md.update(uri.getBytes(StandardCharsets.ISO_8859_1));
byte[] ha2 = md.digest(); byte[] ha2 = md.digest();
// calc digest // calc digest
@ -589,17 +590,17 @@ public class ConstraintTest
// request-digest = <"> < KD ( H(A1), unq(nonce-value) ":" H(A2) // 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((byte) ':');
md.update(nonce.getBytes(StringUtil.__ISO_8859_1)); md.update(nonce.getBytes(StandardCharsets.ISO_8859_1));
md.update((byte) ':'); md.update((byte) ':');
md.update(nc.getBytes(StringUtil.__ISO_8859_1)); md.update(nc.getBytes(StandardCharsets.ISO_8859_1));
md.update((byte) ':'); md.update((byte) ':');
md.update(CNONCE.getBytes(StringUtil.__ISO_8859_1)); md.update(CNONCE.getBytes(StandardCharsets.ISO_8859_1));
md.update((byte) ':'); md.update((byte) ':');
md.update("auth".getBytes(StringUtil.__ISO_8859_1)); md.update("auth".getBytes(StandardCharsets.ISO_8859_1));
md.update((byte) ':'); 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(); byte[] digest = md.digest();
// check digest // check digest

View File

@ -22,6 +22,7 @@ import java.io.IOException;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.channels.ClosedChannelException; import java.nio.channels.ClosedChannelException;
import java.nio.charset.StandardCharsets;
import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
@ -491,7 +492,7 @@ public class HttpChannel<T> implements HttpParser.RequestHandler<T>, Runnable
{ {
LOG.warn("Failed UTF-8 decode for request path, trying ISO-8859-1"); LOG.warn("Failed UTF-8 decode for request path, trying ISO-8859-1");
LOG.ignore(e); LOG.ignore(e);
path = _uri.getDecodedPath(StringUtil.__ISO_8859_1); path = _uri.getDecodedPath(StandardCharsets.ISO_8859_1);
} }
String info = URIUtil.canonicalPath(path); String info = URIUtil.canonicalPath(path);

View File

@ -20,6 +20,7 @@ package org.eclipse.jetty.server;
import java.io.IOException; import java.io.IOException;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
import java.util.concurrent.BlockingQueue; import java.util.concurrent.BlockingQueue;
import java.util.concurrent.CountDownLatch; import java.util.concurrent.CountDownLatch;
import java.util.concurrent.Executor; 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 public String getResponses(String requests,long idleFor,TimeUnit units) throws Exception
{ {
ByteBuffer result = getResponses(BufferUtil.toBuffer(requests,StringUtil.__UTF8_CHARSET),idleFor,units); ByteBuffer result = getResponses(BufferUtil.toBuffer(requests,StandardCharsets.UTF_8),idleFor,units);
return result==null?null:BufferUtil.toString(result,StringUtil.__UTF8_CHARSET); return result==null?null:BufferUtil.toString(result,StandardCharsets.UTF_8);
} }
/** Sends requests and get's responses based on thread activity. /** Sends requests and get's responses based on thread activity.
@ -150,7 +151,7 @@ public class LocalConnector extends AbstractConnector
*/ */
public LocalEndPoint executeRequest(String rawRequest) 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) private LocalEndPoint executeRequest(ByteBuffer rawRequest)
@ -190,7 +191,7 @@ public class LocalConnector extends AbstractConnector
// TODO this is a busy wait // TODO this is a busy wait
while(getIn()==null || BufferUtil.hasContent(getIn())) while(getIn()==null || BufferUtil.hasContent(getIn()))
Thread.yield(); Thread.yield();
setInput(BufferUtil.toBuffer(s, StringUtil.__UTF8_CHARSET)); setInput(BufferUtil.toBuffer(s, StandardCharsets.UTF_8));
} }
@Override @Override

View File

@ -28,6 +28,7 @@ import java.io.UnsupportedEncodingException;
import java.net.InetAddress; import java.net.InetAddress;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.nio.charset.Charset; import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.nio.charset.UnsupportedCharsetException; import java.nio.charset.UnsupportedCharsetException;
import java.security.Principal; import java.security.Principal;
import java.util.ArrayList; import java.util.ArrayList;
@ -1873,7 +1874,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 * 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. * The request attribute "org.eclipse.jetty.server.server.Request.queryEncoding" may be set as an alternate method of calling setQueryEncoding.
* *
@ -2100,6 +2101,7 @@ public class Request implements HttpServletRequest
setAttribute(__MULTIPART_INPUT_STREAM, _multiPartInputStream); setAttribute(__MULTIPART_INPUT_STREAM, _multiPartInputStream);
setAttribute(__MULTIPART_CONTEXT, _context); setAttribute(__MULTIPART_CONTEXT, _context);
Collection<Part> parts = _multiPartInputStream.getParts(); //causes parsing Collection<Part> parts = _multiPartInputStream.getParts(); //causes parsing
ByteArrayOutputStream os = null;
for (Part p:parts) for (Part p:parts)
{ {
MultiPartInputStreamParser.MultiPart mp = (MultiPartInputStreamParser.MultiPart)p; MultiPartInputStreamParser.MultiPart mp = (MultiPartInputStreamParser.MultiPart)p;
@ -2110,21 +2112,17 @@ public class Request implements HttpServletRequest
if (mp.getContentType() != null) if (mp.getContentType() != null)
charset = MimeTypes.getCharsetFromContentType(mp.getContentType()); charset = MimeTypes.getCharsetFromContentType(mp.getContentType());
ByteArrayOutputStream os = null; //get the bytes regardless of being in memory or in temp file
InputStream is = mp.getInputStream(); //get the bytes regardless of being in memory or in temp file try (InputStream is = mp.getInputStream())
try
{ {
if (os == null)
os = new ByteArrayOutputStream(); os = new ByteArrayOutputStream();
IO.copy(is, os); 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 getParameter(""); //cause params to be evaluated
getParameters().add(mp.getName(), content); getParameters().add(mp.getName(), content);
} }
finally os.reset();
{
IO.close(os);
IO.close(is);
}
} }
} }
} }
@ -2169,7 +2167,7 @@ public class Request implements HttpServletRequest
{ {
// extract parameters from dispatch query // extract parameters from dispatch query
MultiMap<String> parameters = new MultiMap<>(); 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; boolean merge_old_query = false;
@ -2194,7 +2192,7 @@ public class Request implements HttpServletRequest
MultiMap<String> overridden_new_query = new MultiMap<>(); 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()) for(String name: overridden_old_query.keySet())
{ {

View File

@ -25,6 +25,7 @@ import java.io.OutputStream;
import java.net.InetAddress; import java.net.InetAddress;
import java.net.ServerSocket; import java.net.ServerSocket;
import java.net.Socket; import java.net.Socket;
import java.nio.charset.StandardCharsets;
import java.util.Properties; import java.util.Properties;
import org.eclipse.jetty.util.StringUtil; import org.eclipse.jetty.util.StringUtil;
@ -112,7 +113,7 @@ public class ShutdownMonitor
// Reply to client // Reply to client
debug("Informing client that we are stopped."); 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(); out.flush();
// Shutdown Monitor // Shutdown Monitor
@ -131,7 +132,7 @@ public class ShutdownMonitor
else if ("status".equals(cmd)) else if ("status".equals(cmd))
{ {
// Reply to client // Reply to client
out.write("OK\r\n".getBytes(StringUtil.__UTF8)); out.write("OK\r\n".getBytes(StandardCharsets.UTF_8));
out.flush(); out.flush();
} }
} }

View File

@ -25,6 +25,7 @@ import java.io.OutputStreamWriter;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.net.Socket; import java.net.Socket;
import java.net.URISyntaxException; import java.net.URISyntaxException;
import java.nio.charset.StandardCharsets;
import javax.servlet.ServletException; import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
@ -76,7 +77,7 @@ public abstract class AbstractHttpTest
{ {
Socket socket = new Socket("localhost", connector.getLocalPort()); Socket socket = new Socket("localhost", connector.getLocalPort());
socket.setSoTimeout((int)connector.getIdleTimeout()); 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())); PrintWriter writer = new PrintWriter(new OutputStreamWriter(socket.getOutputStream()));
String request = "GET / " + httpVersion + "\r\n"; String request = "GET / " + httpVersion + "\r\n";

View File

@ -30,6 +30,7 @@ import java.io.InputStreamReader;
import java.io.OutputStream; import java.io.OutputStream;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.net.Socket; import java.net.Socket;
import java.nio.charset.StandardCharsets;
import java.util.Arrays; import java.util.Arrays;
import java.util.concurrent.BlockingQueue; import java.util.concurrent.BlockingQueue;
import java.util.concurrent.Exchanger; import java.util.concurrent.Exchanger;
@ -96,7 +97,7 @@ public class AsyncRequestReadTest
"Content-Length: "+content.length+"\r\n"+ "Content-Length: "+content.length+"\r\n"+
"Content-Type: bytes\r\n"+ "Content-Type: bytes\r\n"+
"\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(h);
out.write(content); out.write(content);
@ -108,7 +109,7 @@ public class AsyncRequestReadTest
"Content-Type: bytes\r\n"+ "Content-Type: bytes\r\n"+
"Connection: close\r\n"+ "Connection: close\r\n"+
"\r\n"; "\r\n";
h=header.getBytes(StringUtil.__ISO_8859_1); h=header.getBytes(StandardCharsets.ISO_8859_1);
out.write(h); out.write(h);
out.write(content); out.write(content);
out.flush(); out.flush();
@ -244,7 +245,7 @@ public class AsyncRequestReadTest
"Content-Length: "+content.length+"\r\n"+ "Content-Length: "+content.length+"\r\n"+
"Content-Type: bytes\r\n"+ "Content-Type: bytes\r\n"+
"\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(h);
out.write(content); out.write(content);
@ -254,7 +255,7 @@ public class AsyncRequestReadTest
"Content-Type: bytes\r\n"+ "Content-Type: bytes\r\n"+
"Connection: close\r\n"+ "Connection: close\r\n"+
"\r\n"; "\r\n";
h=header.getBytes(StringUtil.__ISO_8859_1); h=header.getBytes(StandardCharsets.ISO_8859_1);
out.write(h); out.write(h);
out.write(content); out.write(content);
out.flush(); out.flush();
@ -294,7 +295,7 @@ public class AsyncRequestReadTest
"Content-Length: "+content.length+"\r\n"+ "Content-Length: "+content.length+"\r\n"+
"Content-Type: bytes\r\n"+ "Content-Type: bytes\r\n"+
"\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(h);
out.write(content,0,4096); out.write(content,0,4096);
out.flush(); out.flush();
@ -329,7 +330,7 @@ public class AsyncRequestReadTest
"Content-Length: "+content.length+"\r\n"+ "Content-Length: "+content.length+"\r\n"+
"Content-Type: bytes\r\n"+ "Content-Type: bytes\r\n"+
"\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(h);
out.write(content,0,4096); out.write(content,0,4096);
out.flush(); out.flush();

View File

@ -24,6 +24,7 @@ import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.net.InetAddress; import java.net.InetAddress;
import java.net.Socket; import java.net.Socket;
import java.nio.charset.StandardCharsets;
import java.util.Random; import java.util.Random;
import java.util.Timer; import java.util.Timer;
import java.util.TimerTask; import java.util.TimerTask;
@ -140,7 +141,7 @@ public class AsyncStressTest
"result: "+__paths[p][1]+"\r\n"+ "result: "+__paths[p][1]+"\r\n"+
((l+1<loops)?"":"Connection: close\r\n")+ ((l+1<loops)?"":"Connection: close\r\n")+
"\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(); socket[i].getOutputStream().flush();
} }
if (l%80==0) if (l%80==0)
@ -155,7 +156,7 @@ public class AsyncStressTest
String[] results=new String[connections]; String[] results=new String[connections];
for (int i=0;i<connections;i++) 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) if (i%80==0)
System.err.println(); System.err.println();
System.err.print('-'); System.err.print('-');

View File

@ -24,6 +24,7 @@ import java.io.IOException;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.io.OutputStream; import java.io.OutputStream;
import java.net.Socket; import java.net.Socket;
import java.nio.charset.StandardCharsets;
import java.util.concurrent.CountDownLatch; import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
@ -141,7 +142,7 @@ public class ConnectionOpenCloseTest extends AbstractHttpTest
"GET / HTTP/1.1\r\n" + "GET / HTTP/1.1\r\n" +
"Host: localhost:" + connector.getLocalPort() + "\r\n" + "Host: localhost:" + connector.getLocalPort() + "\r\n" +
"Connection: close\r\n" + "Connection: close\r\n" +
"\r\n").getBytes("UTF-8")); "\r\n").getBytes(StandardCharsets.UTF_8));
output.flush(); output.flush();
BufferedReader reader = new BufferedReader(new InputStreamReader(socket.getInputStream())); BufferedReader reader = new BufferedReader(new InputStreamReader(socket.getInputStream()));
@ -212,7 +213,7 @@ public class ConnectionOpenCloseTest extends AbstractHttpTest
"GET / HTTP/1.1\r\n" + "GET / HTTP/1.1\r\n" +
"Host: localhost:" + connector.getLocalPort() + "\r\n" + "Host: localhost:" + connector.getLocalPort() + "\r\n" +
"Connection: close\r\n" + "Connection: close\r\n" +
"\r\n").getBytes("UTF-8")); "\r\n").getBytes(StandardCharsets.UTF_8));
output.flush(); output.flush();
BufferedReader reader = new BufferedReader(new InputStreamReader(socket.getInputStream())); BufferedReader reader = new BufferedReader(new InputStreamReader(socket.getInputStream()));

View File

@ -24,6 +24,7 @@ import java.io.OutputStream;
import java.io.OutputStreamWriter; import java.io.OutputStreamWriter;
import java.io.Reader; import java.io.Reader;
import java.io.Writer; import java.io.Writer;
import java.nio.charset.StandardCharsets;
import java.util.Enumeration; import java.util.Enumeration;
import javax.servlet.ServletException; import javax.servlet.ServletException;
@ -97,7 +98,7 @@ public class DumpHandler extends AbstractHandler
OutputStream out = response.getOutputStream(); OutputStream out = response.getOutputStream();
ByteArrayOutputStream buf = new ByteArrayOutputStream(2048); 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("<html><h1>"+label+"</h1>");
writer.write("<pre>\npathInfo="+request.getPathInfo()+"\n</pre>\n"); writer.write("<pre>\npathInfo="+request.getPathInfo()+"\n</pre>\n");
writer.write("<pre>\ncontentType="+request.getContentType()+"\n</pre>\n"); writer.write("<pre>\ncontentType="+request.getContentType()+"\n</pre>\n");

View File

@ -20,6 +20,7 @@ package org.eclipse.jetty.server;
import java.io.IOException; import java.io.IOException;
import java.net.Socket; import java.net.Socket;
import java.nio.charset.StandardCharsets;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import javax.servlet.ServletException; import javax.servlet.ServletException;
@ -76,7 +77,7 @@ public class GracefulStopTest
try(Socket socket = new Socket("localhost",server.getBean(NetworkConnector.class).getLocalPort());) 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()); String out = IO.toString(socket.getInputStream());
Assert.assertThat(out,Matchers.containsString("200 OK")); Assert.assertThat(out,Matchers.containsString("200 OK"));
} }

View File

@ -23,6 +23,7 @@ import java.io.IOException;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.io.OutputStream; import java.io.OutputStream;
import java.net.Socket; import java.net.Socket;
import java.nio.charset.StandardCharsets;
import javax.servlet.ServletException; import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
@ -71,10 +72,10 @@ public class HostHeaderCustomizerTest
String request = "" + String request = "" +
"GET / HTTP/1.0\r\n" + "GET / HTTP/1.0\r\n" +
"\r\n"; "\r\n";
output.write(request.getBytes("UTF-8")); output.write(request.getBytes(StandardCharsets.UTF_8));
output.flush(); 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(); SimpleHttpParser parser = new SimpleHttpParser();
SimpleHttpResponse response = parser.readResponse(input); SimpleHttpResponse response = parser.readResponse(input);

View File

@ -38,6 +38,7 @@ import java.io.OutputStream;
import java.net.Socket; import java.net.Socket;
import java.net.URI; import java.net.URI;
import java.net.URL; import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.Arrays; import java.util.Arrays;
import java.util.concurrent.CountDownLatch; import java.util.concurrent.CountDownLatch;
import java.util.concurrent.Exchanger; import java.util.concurrent.Exchanger;
@ -969,12 +970,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("123456789"));
assertTrue(in.contains("abcdefghZ")); assertTrue(in.contains("abcdefghZ"));
assertFalse(in.contains("Wibble")); 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); assertEquals("Wibble\n", in);
} }
} }
@ -1414,11 +1415,11 @@ public abstract class HttpServerTestBase extends HttpServerTestFixture
{ {
for (int i = 0; i < REQS; i++) 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("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(StringUtil.__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(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(); out.flush();
} }
catch (Exception e) catch (Exception e)

View File

@ -28,6 +28,7 @@ import java.io.UnsupportedEncodingException;
import java.net.URLDecoder; import java.net.URLDecoder;
import java.net.URLEncoder; import java.net.URLEncoder;
import java.nio.charset.Charset; import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import org.eclipse.jetty.http.HttpURI; import org.eclipse.jetty.http.HttpURI;
import org.eclipse.jetty.util.MultiMap; import org.eclipse.jetty.util.MultiMap;
@ -330,7 +331,7 @@ public class HttpURITest
huri=new HttpURI(uri); huri=new HttpURI(uri);
params = new MultiMap<>(); 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)); 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")); HttpURI uri = new HttpURI("/path?value="+URLEncoder.encode(value,"UTF-8"));
MultiMap<String> parameters = new MultiMap<>(); MultiMap<String> parameters = new MultiMap<>();
uri.decodeQueryTo(parameters,"UTF-8"); uri.decodeQueryTo(parameters,StandardCharsets.UTF_8);
assertEquals(value,parameters.getString("value")); assertEquals(value,parameters.getString("value"));
} }
} }
@ -366,7 +367,7 @@ public class HttpURITest
{ {
try 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); uri.parseConnect(buf,2,buf.length-4);
assertEquals("path"+i,connect_tests[i][0].trim(),uri.getPath()); assertEquals("path"+i,connect_tests[i][0].trim(),uri.getPath());
@ -384,13 +385,13 @@ public class HttpURITest
public void testNonURIAscii() throws Exception public void testNonURIAscii() throws Exception
{ {
String url = "http://www.foo.com/ma\u00F1ana"; String url = "http://www.foo.com/ma\u00F1ana";
byte[] asISO = url.getBytes("ISO-8859-1"); byte[] asISO = url.getBytes(StandardCharsets.ISO_8859_1);
new String(asISO, "ISO-8859-1"); new String(asISO, StandardCharsets.ISO_8859_1);
//use a non UTF-8 charset as the encoding and url-escape as per //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 //http://www.w3.org/TR/html40/appendix/notes.html#non-ascii-chars
String s = URLEncoder.encode(url, "ISO-8859-1"); 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 //parse it, using the same encoding
uri.parse(s); uri.parse(s);

View File

@ -22,6 +22,7 @@ import static org.junit.Assert.assertEquals;
import java.io.IOException; import java.io.IOException;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
import org.eclipse.jetty.io.ByteBufferPool; import org.eclipse.jetty.io.ByteBufferPool;
import org.eclipse.jetty.io.MappedByteBufferPool; import org.eclipse.jetty.io.MappedByteBufferPool;
@ -67,7 +68,7 @@ public class HttpWriterTest
{ {
HttpWriter _writer = new Utf8HttpWriter(_httpOut); HttpWriter _writer = new Utf8HttpWriter(_httpOut);
_writer.write("Now is the time"); _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 @Test
@ -75,7 +76,7 @@ public class HttpWriterTest
{ {
HttpWriter _writer = new Utf8HttpWriter(_httpOut); HttpWriter _writer = new Utf8HttpWriter(_httpOut);
_writer.write("How now \uFF22rown cow"); _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 @Test
@ -83,7 +84,7 @@ public class HttpWriterTest
{ {
HttpWriter _writer = new EncodingHttpWriter(_httpOut,StringUtil.__UTF16); HttpWriter _writer = new EncodingHttpWriter(_httpOut,StringUtil.__UTF16);
_writer.write("How now \uFF22rown cow"); _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 @Test
@ -93,7 +94,7 @@ public class HttpWriterTest
String data="xxx\uD801\uDC00xxx"; String data="xxx\uD801\uDC00xxx";
_writer.write(data); _writer.write(data);
assertEquals("787878F0909080787878",TypeUtil.toHexString(BufferUtil.toArray(_bytes))); 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()); assertEquals(3+4+3,_bytes.remaining());
Utf8StringBuilder buf = new Utf8StringBuilder(); Utf8StringBuilder buf = new Utf8StringBuilder();
@ -109,7 +110,7 @@ public class HttpWriterTest
final String multiByteDuplicateStr = "\uFF22"; final String multiByteDuplicateStr = "\uFF22";
int remainSize = 1; int remainSize = 1;
int multiByteStrByteLength = multiByteDuplicateStr.getBytes("UTF-8").length; int multiByteStrByteLength = multiByteDuplicateStr.getBytes(StandardCharsets.UTF_8).length;
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
for (int i = 0; i < HttpWriter.MAX_OUTPUT_CHARS - multiByteStrByteLength; i++) { for (int i = 0; i < HttpWriter.MAX_OUTPUT_CHARS - multiByteStrByteLength; i++) {
sb.append(singleByteStr); sb.append(singleByteStr);
@ -125,7 +126,7 @@ public class HttpWriterTest
_writer.write(buf, 0, length); _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 @Test
@ -133,7 +134,7 @@ public class HttpWriterTest
{ {
HttpWriter _writer = new Iso88591HttpWriter(_httpOut); HttpWriter _writer = new Iso88591HttpWriter(_httpOut);
_writer.write("How now \uFF22rown cow"); _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 @Test
@ -143,11 +144,11 @@ public class HttpWriterTest
String source = "\uD842\uDF9F"; 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); _writer.write(source.toCharArray(),0,source.toCharArray().length);
java.io.ByteArrayOutputStream baos = new java.io.ByteArrayOutputStream(); 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.write(source.toCharArray(),0,source.toCharArray().length);
osw.flush(); osw.flush();
@ -181,11 +182,11 @@ public class HttpWriterTest
} }
String source = sb.toString(); 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); _writer.write(source.toCharArray(),0,source.toCharArray().length);
java.io.ByteArrayOutputStream baos = new java.io.ByteArrayOutputStream(); 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.write(source.toCharArray(),0,source.toCharArray().length);
osw.flush(); osw.flush();
@ -219,11 +220,11 @@ public class HttpWriterTest
} }
String source = sb.toString(); 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); _writer.write(source.toCharArray(),0,source.toCharArray().length);
java.io.ByteArrayOutputStream baos = new java.io.ByteArrayOutputStream(); 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.write(source.toCharArray(),0,source.toCharArray().length);
osw.flush(); osw.flush();

View File

@ -24,6 +24,7 @@ import static org.hamcrest.Matchers.not;
import static org.junit.Assert.assertThat; import static org.junit.Assert.assertThat;
import java.net.Socket; import java.net.Socket;
import java.nio.charset.StandardCharsets;
import java.util.Arrays; import java.util.Arrays;
import java.util.concurrent.CountDownLatch; import java.util.concurrent.CountDownLatch;
@ -161,7 +162,7 @@ public class LowResourcesMonitorTest
for (int i=0;i<socket.length;i++) for (int i=0;i<socket.length;i++)
Assert.assertEquals(-1,socket[i].getInputStream().read()); 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()); Assert.assertEquals('H',newSocket.getInputStream().read());
} }
@ -183,11 +184,11 @@ public class LowResourcesMonitorTest
Thread.sleep(1200); Thread.sleep(1200);
Assert.assertTrue(_lowResourcesMonitor.isLowOnResources()); Assert.assertTrue(_lowResourcesMonitor.isLowOnResources());
Assert.assertEquals(-1,socket0.getInputStream().read()); 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); Thread.sleep(1200);
Assert.assertTrue(_lowResourcesMonitor.isLowOnResources()); Assert.assertTrue(_lowResourcesMonitor.isLowOnResources());
socket1.getOutputStream().write("E".getBytes(StringUtil.__UTF8_CHARSET)); socket1.getOutputStream().write("E".getBytes(StandardCharsets.UTF_8));
Thread.sleep(1200); Thread.sleep(1200);
Assert.assertTrue(_lowResourcesMonitor.isLowOnResources()); Assert.assertTrue(_lowResourcesMonitor.isLowOnResources());

View File

@ -24,6 +24,7 @@ import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
import java.net.Socket; import java.net.Socket;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
import java.util.concurrent.CountDownLatch; import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.atomic.AtomicReference;
@ -129,14 +130,14 @@ public class NetworkTrafficListenerTest
@Override @Override
public void incoming(Socket socket, ByteBuffer bytes) 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(); incomingLatch.countDown();
} }
@Override @Override
public void outgoing(Socket socket, ByteBuffer bytes) 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(); outgoingLatch.countDown();
} }
}); });
@ -154,7 +155,7 @@ public class NetworkTrafficListenerTest
Socket socket = new Socket("localhost", port); Socket socket = new Socket("localhost", port);
OutputStream output = socket.getOutputStream(); OutputStream output = socket.getOutputStream();
output.write(request.getBytes("UTF-8")); output.write(request.getBytes(StandardCharsets.UTF_8));
output.flush(); output.flush();
assertTrue(incomingLatch.await(1, TimeUnit.SECONDS)); assertTrue(incomingLatch.await(1, TimeUnit.SECONDS));
@ -164,7 +165,7 @@ public class NetworkTrafficListenerTest
assertEquals(expectedResponse, outgoingData.get()); assertEquals(expectedResponse, outgoingData.get());
byte[] responseBytes = readResponse(socket); byte[] responseBytes = readResponse(socket);
String response = new String(responseBytes, "UTF-8"); String response = new String(responseBytes, StandardCharsets.UTF_8);
assertEquals(expectedResponse, response); assertEquals(expectedResponse, response);
socket.close(); socket.close();
@ -180,7 +181,7 @@ public class NetworkTrafficListenerTest
{ {
request.setHandled(true); request.setHandled(true);
ServletOutputStream output = servletResponse.getOutputStream(); ServletOutputStream output = servletResponse.getOutputStream();
output.write(responseContent.getBytes("UTF-8")); output.write(responseContent.getBytes(StandardCharsets.UTF_8));
output.write(END_OF_CONTENT); output.write(END_OF_CONTENT);
} }
}); });
@ -193,13 +194,13 @@ public class NetworkTrafficListenerTest
{ {
public void incoming(Socket socket, ByteBuffer bytes) 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(); incomingLatch.countDown();
} }
public void outgoing(Socket socket, ByteBuffer bytes) 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(); outgoingLatch.countDown();
} }
}); });
@ -217,7 +218,7 @@ public class NetworkTrafficListenerTest
Socket socket = new Socket("localhost", port); Socket socket = new Socket("localhost", port);
OutputStream output = socket.getOutputStream(); OutputStream output = socket.getOutputStream();
output.write(request.getBytes("UTF-8")); output.write(request.getBytes(StandardCharsets.UTF_8));
output.flush(); output.flush();
assertTrue(incomingLatch.await(1, TimeUnit.SECONDS)); assertTrue(incomingLatch.await(1, TimeUnit.SECONDS));
@ -227,7 +228,7 @@ public class NetworkTrafficListenerTest
assertEquals(expectedResponse, outgoingData.get()); assertEquals(expectedResponse, outgoingData.get());
byte[] responseBytes = readResponse(socket); byte[] responseBytes = readResponse(socket);
String response = new String(responseBytes, "UTF-8"); String response = new String(responseBytes, StandardCharsets.UTF_8);
assertEquals(expectedResponse, response); assertEquals(expectedResponse, response);
socket.close(); socket.close();
@ -245,9 +246,9 @@ public class NetworkTrafficListenerTest
{ {
request.setHandled(true); request.setHandled(true);
ServletOutputStream output = servletResponse.getOutputStream(); ServletOutputStream output = servletResponse.getOutputStream();
output.write(responseChunk1.getBytes("UTF-8")); output.write(responseChunk1.getBytes(StandardCharsets.UTF_8));
output.flush(); output.flush();
output.write(responseChunk2.getBytes("UTF-8")); output.write(responseChunk2.getBytes(StandardCharsets.UTF_8));
output.flush(); output.flush();
} }
}); });
@ -260,13 +261,13 @@ public class NetworkTrafficListenerTest
{ {
public void incoming(Socket socket, ByteBuffer bytes) 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(); incomingLatch.countDown();
} }
public void outgoing(Socket socket, ByteBuffer bytes) 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(); outgoingLatch.countDown();
} }
}); });
@ -289,7 +290,7 @@ public class NetworkTrafficListenerTest
Socket socket = new Socket("localhost", port); Socket socket = new Socket("localhost", port);
OutputStream output = socket.getOutputStream(); OutputStream output = socket.getOutputStream();
output.write(request.getBytes("UTF-8")); output.write(request.getBytes(StandardCharsets.UTF_8));
output.flush(); output.flush();
assertTrue(incomingLatch.await(1, TimeUnit.SECONDS)); assertTrue(incomingLatch.await(1, TimeUnit.SECONDS));
@ -299,7 +300,7 @@ public class NetworkTrafficListenerTest
assertEquals(expectedResponse, outgoingData.get()); assertEquals(expectedResponse, outgoingData.get());
byte[] responseBytes = readResponse(socket); byte[] responseBytes = readResponse(socket);
String response = new String(responseBytes, "UTF-8"); String response = new String(responseBytes, StandardCharsets.UTF_8);
assertEquals(expectedResponse, response); assertEquals(expectedResponse, response);
socket.close(); socket.close();
@ -326,13 +327,13 @@ public class NetworkTrafficListenerTest
{ {
public void incoming(Socket socket, ByteBuffer bytes) 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(); incomingLatch.countDown();
} }
public void outgoing(Socket socket, ByteBuffer bytes) 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(); outgoingLatch.countDown();
} }
}); });
@ -354,7 +355,7 @@ public class NetworkTrafficListenerTest
Socket socket = new Socket("localhost", port); Socket socket = new Socket("localhost", port);
OutputStream output = socket.getOutputStream(); OutputStream output = socket.getOutputStream();
output.write(request.getBytes("UTF-8")); output.write(request.getBytes(StandardCharsets.UTF_8));
output.flush(); output.flush();
assertTrue(incomingLatch.await(1, TimeUnit.SECONDS)); assertTrue(incomingLatch.await(1, TimeUnit.SECONDS));
@ -364,7 +365,7 @@ public class NetworkTrafficListenerTest
assertEquals(expectedResponse, outgoingData.get()); assertEquals(expectedResponse, outgoingData.get());
byte[] responseBytes = readResponse(socket); byte[] responseBytes = readResponse(socket);
String response = new String(responseBytes, "UTF-8"); String response = new String(responseBytes, StandardCharsets.UTF_8);
assertEquals(expectedResponse, response); assertEquals(expectedResponse, response);
socket.close(); socket.close();
@ -399,12 +400,12 @@ public class NetworkTrafficListenerTest
{ {
public void incoming(Socket socket, ByteBuffer bytes) 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) 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(); outgoingLatch.countDown();
} }
}); });
@ -428,14 +429,14 @@ public class NetworkTrafficListenerTest
Socket socket = new Socket("localhost", port); Socket socket = new Socket("localhost", port);
OutputStream output = socket.getOutputStream(); OutputStream output = socket.getOutputStream();
output.write(request.getBytes("UTF-8")); output.write(request.getBytes(StandardCharsets.UTF_8));
output.flush(); output.flush();
assertTrue(outgoingLatch.await(1, TimeUnit.SECONDS)); assertTrue(outgoingLatch.await(1, TimeUnit.SECONDS));
assertEquals(expectedResponse, outgoingData.get()); assertEquals(expectedResponse, outgoingData.get());
byte[] responseBytes = readResponse(socket); byte[] responseBytes = readResponse(socket);
String response = new String(responseBytes, "UTF-8"); String response = new String(responseBytes, StandardCharsets.UTF_8);
assertEquals(expectedResponse, response); assertEquals(expectedResponse, response);
assertEquals(request, incomingData.get()); assertEquals(request, incomingData.get());

View File

@ -25,6 +25,7 @@ import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.Reader; import java.io.Reader;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Map; import java.util.Map;
@ -563,7 +564,7 @@ public class RequestTest
{ {
baseRequest.setHandled(true); baseRequest.setHandled(true);
Reader reader=request.getReader(); 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.setContentLength(b.length);
response.getOutputStream().write(b); response.getOutputStream().write(b);
response.flushBuffer(); response.flushBuffer();
@ -612,7 +613,7 @@ public class RequestTest
String in = IO.toString(reader); String in = IO.toString(reader);
String param = request.getParameter("param"); 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.setContentLength(b.length);
response.getOutputStream().write(b); response.getOutputStream().write(b);
response.flushBuffer(); response.flushBuffer();
@ -647,7 +648,7 @@ public class RequestTest
{ {
baseRequest.setHandled(true); baseRequest.setHandled(true);
InputStream in=request.getInputStream(); 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.setContentLength(b.length);
response.getOutputStream().write(b); response.getOutputStream().write(b);
response.flushBuffer(); response.flushBuffer();

View File

@ -19,6 +19,7 @@
package org.eclipse.jetty.server; package org.eclipse.jetty.server;
import java.net.Socket; import java.net.Socket;
import java.nio.charset.StandardCharsets;
import org.eclipse.jetty.util.IO; import org.eclipse.jetty.util.IO;
@ -35,7 +36,7 @@ public class SelectChannelAsyncContextTest extends LocalAsyncContextTest
{ {
ServerConnector connector = (ServerConnector)_connector; ServerConnector connector = (ServerConnector)_connector;
Socket socket = new Socket((String)null,connector.getLocalPort()); 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()); return IO.toString(socket.getInputStream());
} }
} }

View File

@ -24,6 +24,7 @@ import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.net.Socket; import java.net.Socket;
import java.nio.charset.StandardCharsets;
import java.util.Locale; import java.util.Locale;
import org.eclipse.jetty.server.session.SessionHandler; import org.eclipse.jetty.server.session.SessionHandler;
@ -101,7 +102,7 @@ public class SelectChannelTimeoutTest extends ConnectorTimeoutTest
ServerConnector connector = (ServerConnector)_connector; ServerConnector connector = (ServerConnector)_connector;
Socket socket = new Socket((String)null,connector.getLocalPort()); Socket socket = new Socket((String)null,connector.getLocalPort());
socket.setSoTimeout(10 * MAX_IDLE_TIME); 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(); InputStream inputStream = socket.getInputStream();
long start = System.currentTimeMillis(); long start = System.currentTimeMillis();
String response = IO.toString(inputStream); String response = IO.toString(inputStream);

View File

@ -25,6 +25,7 @@ import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
import java.net.Socket; import java.net.Socket;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
import java.util.Arrays; import java.util.Arrays;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
@ -116,7 +117,7 @@ public class SlowClientWithPipelinedRequestTest
"GET /content HTTP/1.1\r\n" + "GET /content HTTP/1.1\r\n" +
"Host: localhost:" + connector.getLocalPort() + "\r\n" + "Host: localhost:" + connector.getLocalPort() + "\r\n" +
"\r\n" + "\r\n" +
"").getBytes("UTF-8")); "").getBytes(StandardCharsets.UTF_8));
output.flush(); output.flush();
InputStream input = client.getInputStream(); InputStream input = client.getInputStream();
@ -129,7 +130,7 @@ public class SlowClientWithPipelinedRequestTest
"GET /pipelined HTTP/1.1\r\n" + "GET /pipelined HTTP/1.1\r\n" +
"Host: localhost:" + connector.getLocalPort() + "\r\n" + "Host: localhost:" + connector.getLocalPort() + "\r\n" +
"\r\n" + "\r\n" +
"").getBytes("UTF-8")); "").getBytes(StandardCharsets.UTF_8));
output.flush(); output.flush();
// Simulate a slow reader // Simulate a slow reader

View File

@ -27,6 +27,7 @@ import java.io.IOException;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.io.OutputStream; import java.io.OutputStream;
import java.net.Socket; import java.net.Socket;
import java.nio.charset.StandardCharsets;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
@ -124,7 +125,7 @@ public class IPAccessHandlerTest
OutputStream output = socket.getOutputStream(); OutputStream output = socket.getOutputStream();
BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream())); BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
output.write(request.getBytes("UTF-8")); output.write(request.getBytes(StandardCharsets.UTF_8));
output.flush(); output.flush();
Response response = readResponse(input); Response response = readResponse(input);

View File

@ -24,6 +24,7 @@ import java.io.IOException;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.io.OutputStream; import java.io.OutputStream;
import java.net.Socket; import java.net.Socket;
import java.nio.charset.StandardCharsets;
import javax.net.ssl.SSLContext; import javax.net.ssl.SSLContext;
import javax.servlet.ServletException; 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+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++) for (int i=0;i<2;i++)
{ {

View File

@ -23,6 +23,7 @@ import java.io.IOException;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.io.OutputStream; import java.io.OutputStream;
import java.net.Socket; import java.net.Socket;
import java.nio.charset.StandardCharsets;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
import javax.servlet.AsyncContext; import javax.servlet.AsyncContext;
import javax.servlet.AsyncEvent; import javax.servlet.AsyncEvent;
@ -109,10 +110,10 @@ public class AsyncContextListenersTest
"GET " + path + " HTTP/1.1\r\n" + "GET " + path + " HTTP/1.1\r\n" +
"Host: localhost\r\n" + "Host: localhost\r\n" +
"\r\n"; "\r\n";
output.write(request.getBytes("UTF-8")); output.write(request.getBytes(StandardCharsets.UTF_8));
output.flush(); 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(); SimpleHttpParser parser = new SimpleHttpParser();
SimpleHttpResponse response = parser.readResponse(reader); SimpleHttpResponse response = parser.readResponse(reader);
Assert.assertEquals("200", response.getCode()); Assert.assertEquals("200", response.getCode());
@ -120,7 +121,7 @@ public class AsyncContextListenersTest
// Send a second request // Send a second request
completes.set(0); completes.set(0);
output.write(request.getBytes("UTF-8")); output.write(request.getBytes(StandardCharsets.UTF_8));
output.flush(); output.flush();
response = parser.readResponse(reader); response = parser.readResponse(reader);
@ -180,10 +181,10 @@ public class AsyncContextListenersTest
"GET " + path + " HTTP/1.1\r\n" + "GET " + path + " HTTP/1.1\r\n" +
"Host: localhost\r\n" + "Host: localhost\r\n" +
"\r\n"; "\r\n";
output.write(request.getBytes("UTF-8")); output.write(request.getBytes(StandardCharsets.UTF_8));
output.flush(); 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(); SimpleHttpParser parser = new SimpleHttpParser();
SimpleHttpResponse response = parser.readResponse(reader); SimpleHttpResponse response = parser.readResponse(reader);
Assert.assertEquals("200", response.getCode()); Assert.assertEquals("200", response.getCode());
@ -191,7 +192,7 @@ public class AsyncContextListenersTest
// Send a second request // Send a second request
completes.set(0); completes.set(0);
output.write(request.getBytes("UTF-8")); output.write(request.getBytes(StandardCharsets.UTF_8));
output.flush(); output.flush();
response = parser.readResponse(reader); response = parser.readResponse(reader);
@ -258,10 +259,10 @@ public class AsyncContextListenersTest
"GET " + path + "/one HTTP/1.1\r\n" + "GET " + path + "/one HTTP/1.1\r\n" +
"Host: localhost\r\n" + "Host: localhost\r\n" +
"\r\n"; "\r\n";
output.write(request.getBytes("UTF-8")); output.write(request.getBytes(StandardCharsets.UTF_8));
output.flush(); 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(); SimpleHttpParser parser = new SimpleHttpParser();
SimpleHttpResponse response = parser.readResponse(reader); SimpleHttpResponse response = parser.readResponse(reader);
Assert.assertEquals("200", response.getCode()); Assert.assertEquals("200", response.getCode());
@ -269,7 +270,7 @@ public class AsyncContextListenersTest
// Send a second request // Send a second request
completes.set(0); completes.set(0);
output.write(request.getBytes("UTF-8")); output.write(request.getBytes(StandardCharsets.UTF_8));
output.flush(); output.flush();
response = parser.readResponse(reader); response = parser.readResponse(reader);

View File

@ -23,6 +23,7 @@ import java.io.IOException;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.io.OutputStream; import java.io.OutputStream;
import java.net.Socket; import java.net.Socket;
import java.nio.charset.StandardCharsets;
import java.util.concurrent.CountDownLatch; import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import javax.servlet.AsyncContext; import javax.servlet.AsyncContext;
@ -122,7 +123,7 @@ public class AsyncServletLongPollTest
"Host: localhost:" + connector.getLocalPort() + "\r\n" + "Host: localhost:" + connector.getLocalPort() + "\r\n" +
"\r\n"; "\r\n";
OutputStream output1 = socket1.getOutputStream(); OutputStream output1 = socket1.getOutputStream();
output1.write(request1.getBytes("UTF-8")); output1.write(request1.getBytes(StandardCharsets.UTF_8));
output1.flush(); output1.flush();
Assert.assertTrue(asyncLatch.await(5, TimeUnit.SECONDS)); Assert.assertTrue(asyncLatch.await(5, TimeUnit.SECONDS));
@ -134,18 +135,18 @@ public class AsyncServletLongPollTest
"Host: localhost:" + connector.getLocalPort() + "\r\n" + "Host: localhost:" + connector.getLocalPort() + "\r\n" +
"\r\n"; "\r\n";
OutputStream output2 = socket2.getOutputStream(); OutputStream output2 = socket2.getOutputStream();
output2.write(request2.getBytes("UTF-8")); output2.write(request2.getBytes(StandardCharsets.UTF_8));
output2.flush(); output2.flush();
SimpleHttpParser parser2 = new SimpleHttpParser(); 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); SimpleHttpResponse response2 = parser2.readResponse(input2);
Assert.assertEquals("200", response2.getCode()); Assert.assertEquals("200", response2.getCode());
} }
socket1.setSoTimeout(2 * wait); socket1.setSoTimeout(2 * wait);
SimpleHttpParser parser1 = new SimpleHttpParser(); 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); SimpleHttpResponse response1 = parser1.readResponse(input1);
Assert.assertEquals(error, response1.getCode()); Assert.assertEquals(error, response1.getCode());
@ -154,7 +155,7 @@ public class AsyncServletLongPollTest
String request3 = "GET " + uri + " HTTP/1.1\r\n" + String request3 = "GET " + uri + " HTTP/1.1\r\n" +
"Host: localhost:" + connector.getLocalPort() + "\r\n" + "Host: localhost:" + connector.getLocalPort() + "\r\n" +
"\r\n"; "\r\n";
output1.write(request3.getBytes("UTF-8")); output1.write(request3.getBytes(StandardCharsets.UTF_8));
output1.flush(); output1.flush();
SimpleHttpResponse response3 = parser1.readResponse(input1); SimpleHttpResponse response3 = parser1.readResponse(input1);

View File

@ -21,6 +21,7 @@ package org.eclipse.jetty.servlet;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.net.Socket; import java.net.Socket;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Timer; import java.util.Timer;
@ -420,7 +421,7 @@ public class AsyncServletTest
try (Socket socket = new Socket("localhost",port)) try (Socket socket = new Socket("localhost",port))
{ {
socket.setSoTimeout(1000000); socket.setSoTimeout(1000000);
socket.getOutputStream().write(request.getBytes("UTF-8")); socket.getOutputStream().write(request.getBytes(StandardCharsets.UTF_8));
return IO.toString(socket.getInputStream()); return IO.toString(socket.getInputStream());
} }
catch(Exception e) catch(Exception e)

View File

@ -23,6 +23,7 @@ import static org.junit.Assert.assertTrue;
import java.io.File; import java.io.File;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.nio.charset.StandardCharsets;
import org.eclipse.jetty.server.HttpConfiguration; import org.eclipse.jetty.server.HttpConfiguration;
import org.eclipse.jetty.server.LocalConnector; import org.eclipse.jetty.server.LocalConnector;
@ -220,7 +221,7 @@ public class DefaultServletRangesTest
try try
{ {
out = new FileOutputStream(file); out = new FileOutputStream(file);
out.write(str.getBytes(StringUtil.__UTF8)); out.write(str.getBytes(StandardCharsets.UTF_8));
out.flush(); out.flush();
} }
finally finally

View File

@ -23,6 +23,7 @@ import static org.junit.Assert.assertTrue;
import java.io.File; import java.io.File;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files; import java.nio.file.Files;
import java.util.EnumSet; import java.util.EnumSet;
import java.util.regex.Matcher; import java.util.regex.Matcher;
@ -883,7 +884,7 @@ public class DefaultServletTest
try try
{ {
out = new FileOutputStream(file); out = new FileOutputStream(file);
out.write(str.getBytes(StringUtil.__UTF8)); out.write(str.getBytes(StandardCharsets.UTF_8));
out.flush(); out.flush();
} }
finally finally

View File

@ -25,6 +25,7 @@ import java.io.InputStream;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.net.HttpURLConnection; import java.net.HttpURLConnection;
import java.net.URI; import java.net.URI;
import java.nio.charset.StandardCharsets;
import javax.servlet.ServletException; import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServlet;
@ -109,7 +110,7 @@ public class RequestHeadersTest
try (InputStream in = http.getInputStream()) 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")); Assert.assertThat("Response", resp, is("X-Camel-Type = bactrian"));
} }
} }

View File

@ -22,8 +22,7 @@ package org.eclipse.jetty.servlets;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.IOException; import java.io.IOException;
import java.io.StringReader; import java.io.StringReader;
import java.io.UnsupportedEncodingException; import java.nio.charset.StandardCharsets;
import java.nio.charset.Charset;
import java.util.Enumeration; import java.util.Enumeration;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
import java.util.concurrent.Future; import java.util.concurrent.Future;
@ -54,24 +53,10 @@ import javax.servlet.http.HttpServletResponse;
*/ */
public abstract class EventSourceServlet extends HttpServlet 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[] CRLF = new byte[]{'\r', '\n'};
private static final byte[] EVENT_FIELD; private static final byte[] EVENT_FIELD = "event: ".getBytes(StandardCharsets.UTF_8);
private static final byte[] DATA_FIELD; private static final byte[] DATA_FIELD = "data: ".getBytes(StandardCharsets.UTF_8);
private static final byte[] COMMENT_FIELD; private static final byte[] COMMENT_FIELD = ": ".getBytes(StandardCharsets.UTF_8);
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 ScheduledExecutorService scheduler; private ScheduledExecutorService scheduler;
private int heartBeatPeriod = 10; private int heartBeatPeriod = 10;
@ -129,7 +114,7 @@ public abstract class EventSourceServlet extends HttpServlet
protected void respond(HttpServletRequest request, HttpServletResponse response) throws IOException protected void respond(HttpServletRequest request, HttpServletResponse response) throws IOException
{ {
response.setStatus(HttpServletResponse.SC_OK); response.setStatus(HttpServletResponse.SC_OK);
response.setCharacterEncoding(UTF_8.name()); response.setCharacterEncoding(StandardCharsets.UTF_8.name());
response.setContentType("text/event-stream"); response.setContentType("text/event-stream");
// By adding this header, and not closing the connection, // By adding this header, and not closing the connection,
// we disable HTTP chunking, and we can use write()+flush() // we disable HTTP chunking, and we can use write()+flush()
@ -164,7 +149,7 @@ public abstract class EventSourceServlet extends HttpServlet
synchronized (this) synchronized (this)
{ {
output.write(EVENT_FIELD); output.write(EVENT_FIELD);
output.write(name.getBytes(UTF_8.name())); output.write(name.getBytes(StandardCharsets.UTF_8));
output.write(CRLF); output.write(CRLF);
data(data); data(data);
} }
@ -180,7 +165,7 @@ public abstract class EventSourceServlet extends HttpServlet
while ((line = reader.readLine()) != null) while ((line = reader.readLine()) != null)
{ {
output.write(DATA_FIELD); output.write(DATA_FIELD);
output.write(line.getBytes(UTF_8.name())); output.write(line.getBytes(StandardCharsets.UTF_8));
output.write(CRLF); output.write(CRLF);
} }
output.write(CRLF); output.write(CRLF);
@ -194,7 +179,7 @@ public abstract class EventSourceServlet extends HttpServlet
synchronized (this) synchronized (this)
{ {
output.write(COMMENT_FIELD); output.write(COMMENT_FIELD);
output.write(comment.getBytes(UTF_8.name())); output.write(comment.getBytes(StandardCharsets.UTF_8));
output.write(CRLF); output.write(CRLF);
output.write(CRLF); output.write(CRLF);
flush(); flush();

View File

@ -24,6 +24,9 @@ import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.UnsupportedEncodingException; 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.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.Enumeration; import java.util.Enumeration;
@ -223,7 +226,7 @@ public class MultiPartFilter implements Filter
/* ------------------------------------------------------------------------------- */ /* ------------------------------------------------------------------------------- */
private static class Wrapper extends HttpServletRequestWrapper private static class Wrapper extends HttpServletRequestWrapper
{ {
String _encoding=StringUtil.__UTF8; Charset _encoding=StandardCharsets.UTF_8;
MultiMap<Object> _params; MultiMap<Object> _params;
/* ------------------------------------------------------------------------------- */ /* ------------------------------------------------------------------------------- */
@ -339,7 +342,14 @@ public class MultiPartFilter implements Filter
public void setCharacterEncoding(String enc) public void setCharacterEncoding(String enc)
throws UnsupportedEncodingException 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 //check if there is a specific encoding for the parameter
Object ct = _params.getValue(name+CONTENT_TYPE_SUFFIX,0); Object ct = _params.getValue(name+CONTENT_TYPE_SUFFIX,0);
//use default if not //use default if not
String contentType = _encoding; Charset contentType = _encoding;
if (ct != null) if (ct != null)
{ {
String tmp = MimeTypes.getCharsetFromContentType((String)ct); 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); return new String(bytes,contentType);

View File

@ -27,6 +27,7 @@ import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
import java.net.Socket; import java.net.Socket;
import java.nio.charset.StandardCharsets;
import java.util.EnumSet; import java.util.EnumSet;
import javax.servlet.DispatcherType; import javax.servlet.DispatcherType;
@ -122,7 +123,7 @@ public abstract class AbstractDoSFilterTest
for (int i = loops; i-- > 0;) for (int i = loops; i-- > 0;)
{ {
out.write(loopRequests.getBytes("UTF-8")); out.write(loopRequests.getBytes(StandardCharsets.UTF_8));
out.flush(); out.flush();
if (i > 0 && pauseBetweenLoops > 0) if (i > 0 && pauseBetweenLoops > 0)
{ {
@ -133,7 +134,7 @@ public abstract class AbstractDoSFilterTest
{ {
Thread.sleep(pauseBeforeLast); Thread.sleep(pauseBeforeLast);
} }
out.write(lastRequest.getBytes("UTF-8")); out.write(lastRequest.getBytes(StandardCharsets.UTF_8));
out.flush(); out.flush();
InputStream in = socket.getInputStream(); InputStream in = socket.getInputStream();
@ -142,7 +143,7 @@ public abstract class AbstractDoSFilterTest
// don't read in anything, forcing the request to time out // don't read in anything, forcing the request to time out
Thread.sleep(_requestMaxTime * 2); Thread.sleep(_requestMaxTime * 2);
} }
String response = IO.toString(in,"UTF-8"); String response = IO.toString(in,StandardCharsets.UTF_8);
return response; return response;
} }
} }

View File

@ -24,6 +24,7 @@ import java.io.InputStream;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.io.OutputStream; import java.io.OutputStream;
import java.net.Socket; import java.net.Socket;
import java.nio.charset.StandardCharsets;
import java.util.concurrent.CountDownLatch; import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.atomic.AtomicReference;
@ -326,7 +327,7 @@ public class EventSourceServletTest
handshake += "Host: localhost:" + serverPort + "\r\n"; handshake += "Host: localhost:" + serverPort + "\r\n";
handshake += "Accept: text/event-stream\r\n"; handshake += "Accept: text/event-stream\r\n";
handshake += "\r\n"; handshake += "\r\n";
output.write(handshake.getBytes("UTF-8")); output.write(handshake.getBytes(StandardCharsets.UTF_8));
output.flush(); output.flush();
} }
@ -334,7 +335,7 @@ public class EventSourceServletTest
{ {
// Read and discard the HTTP response // Read and discard the HTTP response
InputStream input = socket.getInputStream(); 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(); String line = reader.readLine();
while (line != null) while (line != null)
{ {

View File

@ -31,6 +31,7 @@ import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.IOException; import java.io.IOException;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.nio.charset.StandardCharsets;
import java.util.EnumSet; import java.util.EnumSet;
import java.util.Map; import java.util.Map;
@ -867,7 +868,7 @@ public class MultipartFilterTest
baos.write(("--" + boundary + "\r\n"+ baos.write(("--" + boundary + "\r\n"+
"Content-Disposition: form-data; name=\"ttt\"\r\n"+ "Content-Disposition: form-data; name=\"ttt\"\r\n"+
"Content-Type: application/octet-stream; charset=UTF-8\r\n\r\n").getBytes()); "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()); baos.write(("\r\n--" + boundary + "--\r\n\r\n").getBytes());

View File

@ -208,9 +208,20 @@ public abstract class DataInfo extends Info
* @return a String with the content of this {@link DataInfo} * @return a String with the content of this {@link DataInfo}
*/ */
public String asString(String charset, boolean consume) 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); ByteBuffer buffer = asByteBuffer(consume);
return Charset.forName(charset).decode(buffer).toString(); return charset.decode(buffer).toString();
} }
/** /**

View File

@ -20,7 +20,7 @@ package org.eclipse.jetty.spdy.generator;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.charset.Charset; import java.nio.charset.StandardCharsets;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
@ -43,7 +43,7 @@ public class HeadersBlockGenerator
public ByteBuffer generate(short version, Fields headers) public ByteBuffer generate(short version, Fields headers)
{ {
// TODO: ByteArrayOutputStream is quite inefficient, but grows on demand; optimize using ByteBuffer ? // TODO: ByteArrayOutputStream is quite inefficient, but grows on demand; optimize using ByteBuffer ?
Charset iso1 = StandardCharsets.ISO_8859_1; final Charset iso1 = StandardCharsets.ISO_8859_1;
ByteArrayOutputStream buffer = new ByteArrayOutputStream(headers.getSize() * 64); ByteArrayOutputStream buffer = new ByteArrayOutputStream(headers.getSize() * 64);
writeCount(version, buffer, headers.getSize()); writeCount(version, buffer, headers.getSize());
for (Fields.Field header : headers) for (Fields.Field header : headers)

View File

@ -19,7 +19,7 @@
package org.eclipse.jetty.spdy.parser; package org.eclipse.jetty.spdy.parser;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.charset.Charset; import java.nio.charset.StandardCharsets;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.util.zip.ZipException; import java.util.zip.ZipException;
@ -59,7 +59,6 @@ public abstract class HeadersBlockParser
ByteBuffer decompressedHeaders = decompress(version, compressedHeaders); ByteBuffer decompressedHeaders = decompress(version, compressedHeaders);
Charset iso1 = StandardCharsets.ISO_8859_1; Charset iso1 = StandardCharsets.ISO_8859_1;
// We know the decoded bytes contain the full headers, // We know the decoded bytes contain the full headers,
// so optimize instead of looping byte by byte // so optimize instead of looping byte by byte
int count = readCount(version, decompressedHeaders); int count = readCount(version, decompressedHeaders);

View File

@ -19,6 +19,7 @@
package org.eclipse.jetty.spdy.api; package org.eclipse.jetty.spdy.api;
import java.nio.charset.Charset; import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException; import java.util.concurrent.TimeoutException;
@ -242,7 +243,7 @@ public class ClientUsageTest
public void onData(Stream stream, DataInfo dataInfo) public void onData(Stream stream, DataInfo dataInfo)
{ {
StringBuilder builder = (StringBuilder)stream.getAttribute("builder"); 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>() }, new Promise.Adapter<Stream>()
@ -250,9 +251,9 @@ public class ClientUsageTest
@Override @Override
public void succeeded(Stream stream) 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 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());
} }
} }
); );

View File

@ -20,6 +20,7 @@ package org.eclipse.jetty.spdy.parser;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.charset.Charset; import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
@ -43,8 +44,7 @@ public class ParseVersusCacheBenchmarkTest
String name = "Content-Type"; String name = "Content-Type";
String value = "application/octect-stream"; String value = "application/octect-stream";
Charset charset = Charset.forName("ISO-8859-1"); ByteBuffer buffer = ByteBuffer.wrap((name + value).getBytes(StandardCharsets.ISO_8859_1));
ByteBuffer buffer = ByteBuffer.wrap((name + value).getBytes(charset));
int iterations = 100_000_000; int iterations = 100_000_000;
long begin = System.nanoTime(); long begin = System.nanoTime();
@ -52,12 +52,12 @@ public class ParseVersusCacheBenchmarkTest
{ {
byte[] nameBytes = new byte[name.length()]; byte[] nameBytes = new byte[name.length()];
buffer.get(nameBytes); buffer.get(nameBytes);
String name2 = new String(nameBytes, charset); String name2 = new String(nameBytes, StandardCharsets.ISO_8859_1);
Assert.assertEquals(name2, name); Assert.assertEquals(name2, name);
byte[] valueBytes = new byte[value.length()]; byte[] valueBytes = new byte[value.length()];
buffer.get(valueBytes); buffer.get(valueBytes);
String value2 = new String(valueBytes, charset); String value2 = new String(valueBytes, StandardCharsets.ISO_8859_1);
Assert.assertEquals(value2, value); Assert.assertEquals(value2, value);
buffer.flip(); buffer.flip();
@ -66,8 +66,8 @@ public class ParseVersusCacheBenchmarkTest
System.err.printf("parse time: %d%n", TimeUnit.NANOSECONDS.toMillis(end - begin)); System.err.printf("parse time: %d%n", TimeUnit.NANOSECONDS.toMillis(end - begin));
Map<ByteBuffer, String> map = new HashMap<>(); Map<ByteBuffer, String> map = new HashMap<>();
map.put(ByteBuffer.wrap(name.getBytes(charset)), name); map.put(ByteBuffer.wrap(name.getBytes(StandardCharsets.ISO_8859_1)), name);
map.put(ByteBuffer.wrap(value.getBytes(charset)), value); map.put(ByteBuffer.wrap(value.getBytes(StandardCharsets.ISO_8859_1)), value);
final Map<ByteBuffer, String> cache = Collections.unmodifiableMap(map); final Map<ByteBuffer, String> cache = Collections.unmodifiableMap(map);
begin = System.nanoTime(); begin = System.nanoTime();

View File

@ -24,6 +24,7 @@ import java.io.InputStream;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.io.OutputStream; import java.io.OutputStream;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.nio.charset.StandardCharsets;
import java.util.List; import java.util.List;
import javax.net.ssl.SSLContext; import javax.net.ssl.SSLContext;
@ -129,11 +130,11 @@ public class ProtocolNegotiationTest
"GET / HTTP/1.1\r\n" + "GET / HTTP/1.1\r\n" +
"Host: localhost:" + address.getPort() + "\r\n" + "Host: localhost:" + address.getPort() + "\r\n" +
"\r\n" + "\r\n" +
"").getBytes("UTF-8")); "").getBytes(StandardCharsets.UTF_8));
output.flush(); output.flush();
InputStream input = client.getInputStream(); 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(); String line = reader.readLine();
Assert.assertTrue(line.contains(" 404 ")); Assert.assertTrue(line.contains(" 404 "));
@ -188,11 +189,11 @@ public class ProtocolNegotiationTest
"GET / HTTP/1.1\r\n" + "GET / HTTP/1.1\r\n" +
"Host: localhost:" + address.getPort() + "\r\n" + "Host: localhost:" + address.getPort() + "\r\n" +
"\r\n" + "\r\n" +
"").getBytes("UTF-8")); "").getBytes(StandardCharsets.UTF_8));
output.flush(); output.flush();
InputStream input = client.getInputStream(); 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(); String line = reader.readLine();
Assert.assertTrue(line.contains(" 404 ")); Assert.assertTrue(line.contains(" 404 "));
@ -241,11 +242,11 @@ public class ProtocolNegotiationTest
"GET / HTTP/1.1\r\n" + "GET / HTTP/1.1\r\n" +
"Host: localhost:" + address.getPort() + "\r\n" + "Host: localhost:" + address.getPort() + "\r\n" +
"\r\n" + "\r\n" +
"").getBytes("UTF-8")); "").getBytes(StandardCharsets.UTF_8));
output.flush(); output.flush();
InputStream input = client.getInputStream(); 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(); String line = reader.readLine();
Assert.assertTrue(line.contains(" 404 ")); Assert.assertTrue(line.contains(" 404 "));

View File

@ -24,6 +24,7 @@ import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.charset.Charset; import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.Arrays; import java.util.Arrays;
import java.util.concurrent.CountDownLatch; import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
@ -438,7 +439,7 @@ public class ServerHTTPSPDYTest extends AbstractHTTPSPDYTest
request.setHandled(true); request.setHandled(true);
httpResponse.setStatus(HttpServletResponse.SC_OK); httpResponse.setStatus(HttpServletResponse.SC_OK);
ServletOutputStream output = httpResponse.getOutputStream(); ServletOutputStream output = httpResponse.getOutputStream();
output.write(data.getBytes("UTF-8")); output.write(data.getBytes(StandardCharsets.UTF_8));
handlerLatch.countDown(); handlerLatch.countDown();
} }
}, 30000), null); }, 30000), null);
@ -461,7 +462,7 @@ public class ServerHTTPSPDYTest extends AbstractHTTPSPDYTest
public void onData(Stream stream, DataInfo dataInfo) public void onData(Stream stream, DataInfo dataInfo)
{ {
assertTrue(dataInfo.isClose()); assertTrue(dataInfo.isClose());
assertEquals(data, dataInfo.asString("UTF-8", true)); assertEquals(data, dataInfo.asString(StandardCharsets.UTF_8, true));
dataLatch.countDown(); dataLatch.countDown();
} }
}); });
@ -533,9 +534,9 @@ public class ServerHTTPSPDYTest extends AbstractHTTPSPDYTest
request.setHandled(true); request.setHandled(true);
httpResponse.setStatus(HttpServletResponse.SC_OK); httpResponse.setStatus(HttpServletResponse.SC_OK);
ServletOutputStream output = httpResponse.getOutputStream(); ServletOutputStream output = httpResponse.getOutputStream();
output.write(data1.getBytes("UTF-8")); output.write(data1.getBytes(StandardCharsets.UTF_8));
output.flush(); output.flush();
output.write(data2.getBytes("UTF-8")); output.write(data2.getBytes(StandardCharsets.UTF_8));
handlerLatch.countDown(); handlerLatch.countDown();
} }
}, 30000), null); }, 30000), null);
@ -564,9 +565,9 @@ public class ServerHTTPSPDYTest extends AbstractHTTPSPDYTest
int data = dataFrames.incrementAndGet(); int data = dataFrames.incrementAndGet();
assertTrue(data >= 1 && data <= 2); assertTrue(data >= 1 && data <= 2);
if (data == 1) if (data == 1)
assertEquals(data1, dataInfo.asString("UTF8", true)); assertEquals(data1, dataInfo.asString(StandardCharsets.UTF_8, true));
else else
assertEquals(data2, dataInfo.asString("UTF8", true)); assertEquals(data2, dataInfo.asString(StandardCharsets.UTF_8, true));
dataLatch.countDown(); dataLatch.countDown();
} }
}); });
@ -750,7 +751,7 @@ public class ServerHTTPSPDYTest extends AbstractHTTPSPDYTest
request.setHandled(true); request.setHandled(true);
httpResponse.setStatus(HttpServletResponse.SC_OK); httpResponse.setStatus(HttpServletResponse.SC_OK);
ServletOutputStream output = httpResponse.getOutputStream(); ServletOutputStream output = httpResponse.getOutputStream();
output.write(data.getBytes("UTF-8")); output.write(data.getBytes(StandardCharsets.UTF_8));
output.flush(); output.flush();
output.close(); output.close();
handlerLatch.countDown(); handlerLatch.countDown();
@ -781,7 +782,7 @@ public class ServerHTTPSPDYTest extends AbstractHTTPSPDYTest
buffer.write(byteBuffer.get()); buffer.write(byteBuffer.get());
if (dataInfo.isClose()) if (dataInfo.isClose())
{ {
assertEquals(data, new String(buffer.toByteArray(), Charset.forName("UTF-8"))); assertEquals(data, new String(buffer.toByteArray(), StandardCharsets.UTF_8));
dataLatch.countDown(); dataLatch.countDown();
} }
} }
@ -807,10 +808,10 @@ public class ServerHTTPSPDYTest extends AbstractHTTPSPDYTest
httpResponse.setStatus(HttpServletResponse.SC_OK); httpResponse.setStatus(HttpServletResponse.SC_OK);
ServletOutputStream output = httpResponse.getOutputStream(); ServletOutputStream output = httpResponse.getOutputStream();
// Write some // Write some
output.write(data1.getBytes("UTF-8")); output.write(data1.getBytes(StandardCharsets.UTF_8));
// But then change your mind and reset the buffer // But then change your mind and reset the buffer
httpResponse.resetBuffer(); httpResponse.resetBuffer();
output.write(data2.getBytes("UTF-8")); output.write(data2.getBytes(StandardCharsets.UTF_8));
handlerLatch.countDown(); handlerLatch.countDown();
} }
}, 30000), null); }, 30000), null);
@ -839,7 +840,7 @@ public class ServerHTTPSPDYTest extends AbstractHTTPSPDYTest
buffer.write(byteBuffer.get()); buffer.write(byteBuffer.get());
if (dataInfo.isClose()) if (dataInfo.isClose())
{ {
assertEquals(data2, new String(buffer.toByteArray(), Charset.forName("UTF-8"))); assertEquals(data2, new String(buffer.toByteArray(), StandardCharsets.UTF_8));
dataLatch.countDown(); dataLatch.countDown();
} }
} }
@ -996,10 +997,10 @@ public class ServerHTTPSPDYTest extends AbstractHTTPSPDYTest
request.setHandled(true); request.setHandled(true);
httpResponse.setHeader("Transfer-Encoding", "chunked"); httpResponse.setHeader("Transfer-Encoding", "chunked");
ServletOutputStream output = httpResponse.getOutputStream(); ServletOutputStream output = httpResponse.getOutputStream();
output.write(pangram1.getBytes("UTF-8")); output.write(pangram1.getBytes(StandardCharsets.UTF_8));
httpResponse.setHeader("EXTRA", "X"); httpResponse.setHeader("EXTRA", "X");
output.flush(); output.flush();
output.write(pangram2.getBytes("UTF-8")); output.write(pangram2.getBytes(StandardCharsets.UTF_8));
handlerLatch.countDown(); handlerLatch.countDown();
} }
}, 30000), null); }, 30000), null);
@ -1030,12 +1031,12 @@ public class ServerHTTPSPDYTest extends AbstractHTTPSPDYTest
if (count == 1) if (count == 1)
{ {
Assert.assertFalse(dataInfo.isClose()); Assert.assertFalse(dataInfo.isClose());
assertEquals(pangram1, dataInfo.asString("UTF-8", true)); assertEquals(pangram1, dataInfo.asString(StandardCharsets.UTF_8, true));
} }
else if (count == 2) else if (count == 2)
{ {
assertTrue(dataInfo.isClose()); assertTrue(dataInfo.isClose());
assertEquals(pangram2, dataInfo.asString("UTF-8", true)); assertEquals(pangram2, dataInfo.asString(StandardCharsets.UTF_8, true));
} }
dataLatch.countDown(); dataLatch.countDown();
} }

View File

@ -19,6 +19,7 @@
package org.eclipse.jetty.spdy.server.proxy; package org.eclipse.jetty.spdy.server.proxy;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.nio.charset.StandardCharsets;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.concurrent.CountDownLatch; import java.util.concurrent.CountDownLatch;
@ -251,7 +252,7 @@ public class ProxyHTTPToSPDYTest
@Test @Test
public void testGETThenSmallResponseContent() throws Exception 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() InetSocketAddress proxyAddress = startProxy(startServer(new ServerSessionFrameListener.Adapter()
{ {
@Override @Override
@ -328,7 +329,7 @@ public class ProxyHTTPToSPDYTest
public void testPOSTWithSmallRequestContentThenSmallResponseContent() throws Exception public void testPOSTWithSmallRequestContentThenSmallResponseContent() throws Exception
{ {
String dataString = "0123456789ABCDEF"; 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() InetSocketAddress proxyAddress = startProxy(startServer(new ServerSessionFrameListener.Adapter()
{ {
@Override @Override
@ -370,7 +371,7 @@ public class ProxyHTTPToSPDYTest
@Test @Test
public void testGETThenSPDYPushIsIgnored() throws Exception 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() InetSocketAddress proxyAddress = startProxy(startServer(new ServerSessionFrameListener.Adapter()
{ {
@Override @Override

View File

@ -22,6 +22,7 @@ import java.io.BufferedReader;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.IOException; import java.io.IOException;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.nio.charset.StandardCharsets;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.concurrent.CountDownLatch; import java.util.concurrent.CountDownLatch;
@ -197,7 +198,7 @@ public class ProxySPDYToHTTPTest
@Test @Test
public void testSYNThenREPLYAndDATA() throws Exception public void testSYNThenREPLYAndDATA() throws Exception
{ {
final byte[] data = "0123456789ABCDEF".getBytes("UTF-8"); final byte[] data = "0123456789ABCDEF".getBytes(StandardCharsets.UTF_8);
final String header = "foo"; final String header = "foo";
InetSocketAddress proxyAddress = startProxy(startServer(new TestServerHandler(header, data)), 30000, 30000); InetSocketAddress proxyAddress = startProxy(startServer(new TestServerHandler(header, data)), 30000, 30000);

View File

@ -20,6 +20,7 @@ package org.eclipse.jetty.spdy.server.proxy;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.nio.charset.StandardCharsets;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.concurrent.CountDownLatch; import java.util.concurrent.CountDownLatch;
@ -227,7 +228,7 @@ public class ProxySPDYToSPDYTest
@Test @Test
public void testSYNThenREPLYAndDATA() throws Exception public void testSYNThenREPLYAndDATA() throws Exception
{ {
final byte[] data = "0123456789ABCDEF".getBytes("UTF-8"); final byte[] data = "0123456789ABCDEF".getBytes(StandardCharsets.UTF_8);
final String header = "foo"; final String header = "foo";
InetSocketAddress proxyAddress = startProxy(startServer(new ServerSessionFrameListener.Adapter() InetSocketAddress proxyAddress = startProxy(startServer(new ServerSessionFrameListener.Adapter()
{ {
@ -287,7 +288,7 @@ public class ProxySPDYToSPDYTest
@Test @Test
public void testSYNThenSPDYPushIsReceived() throws Exception 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() InetSocketAddress proxyAddress = startProxy(startServer(new ServerSessionFrameListener.Adapter()
{ {
@Override @Override
@ -368,7 +369,7 @@ public class ProxySPDYToSPDYTest
@Test @Test
public void testSYNThenSPDYNestedPushIsReceived() throws Exception 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() InetSocketAddress proxyAddress = startProxy(startServer(new ServerSessionFrameListener.Adapter()
{ {
@Override @Override

View File

@ -21,6 +21,7 @@ package org.eclipse.jetty.spdy.server;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.charset.Charset; import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.Arrays; import java.util.Arrays;
import java.util.concurrent.CountDownLatch; import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
@ -118,7 +119,7 @@ public class SynReplyTest extends AbstractTest
@Test @Test
public void testSynDataReply() throws Exception 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 synLatch = new CountDownLatch(1);
final CountDownLatch dataLatch = new CountDownLatch(1); final CountDownLatch dataLatch = new CountDownLatch(1);
@ -235,13 +236,13 @@ public class SynReplyTest extends AbstractTest
int dataCount = this.dataCount.incrementAndGet(); int dataCount = this.dataCount.incrementAndGet();
if (dataCount == 1) if (dataCount == 1)
{ {
String chunk1 = dataInfo.asString("UTF-8", true); String chunk1 = dataInfo.asString(StandardCharsets.UTF_8, true);
Assert.assertEquals(data1, chunk1); Assert.assertEquals(data1, chunk1);
dataLatch1.countDown(); dataLatch1.countDown();
} }
else if (dataCount == 2) else if (dataCount == 2)
{ {
String chunk2 = dataInfo.asString("UTF-8", true); String chunk2 = dataInfo.asString(StandardCharsets.UTF_8, true);
Assert.assertEquals(data2, chunk2); Assert.assertEquals(data2, chunk2);
dataLatch2.countDown(); dataLatch2.countDown();
} }
@ -277,7 +278,7 @@ public class SynReplyTest extends AbstractTest
@Override @Override
public void onData(Stream stream, DataInfo dataInfo) 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); Assert.assertEquals(clientData, data);
clientDataLatch.countDown(); clientDataLatch.countDown();
} }
@ -311,7 +312,7 @@ public class SynReplyTest extends AbstractTest
public void onData(Stream stream, DataInfo dataInfo) public void onData(Stream stream, DataInfo dataInfo)
{ {
ByteBuffer buffer = dataInfo.asByteBuffer(false); 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); Assert.assertEquals(serverData, data);
serverDataLatch.countDown(); serverDataLatch.countDown();
} }
@ -361,7 +362,7 @@ public class SynReplyTest extends AbstractTest
@Override @Override
public void onData(Stream stream, DataInfo dataInfo) 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); Assert.assertEquals(data, chunk);
dataLatch.countDown(); dataLatch.countDown();
} }

View File

@ -20,6 +20,7 @@
package org.eclipse.jetty.spring; package org.eclipse.jetty.spring;
import java.net.URL; import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.Arrays; import java.util.Arrays;
import java.util.Map; import java.util.Map;
import java.util.ServiceLoader; import java.util.ServiceLoader;
@ -80,7 +81,7 @@ public class SpringConfigurationProcessor implements ConfigurationProcessor
: new ByteArrayResource(("" + : new ByteArrayResource(("" +
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
"<!DOCTYPE beans PUBLIC \"-//SPRING//DTD BEAN//EN\" \"http://www.springframework.org/dtd/spring-beans.dtd\">" + "<!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() _beanFactory = new DefaultListableBeanFactory()
{ {

View File

@ -19,6 +19,7 @@
package org.eclipse.jetty.util; package org.eclipse.jetty.util;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
/* ------------------------------------------------------------ */ /* ------------------------------------------------------------ */
@ -72,7 +73,7 @@ public abstract class AbstractTrie<V> implements Trie<V>
@Override @Override
public V getBest(byte[] b, int offset, int len) 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 @Override

View File

@ -21,6 +21,7 @@ package org.eclipse.jetty.util;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.IOException; import java.io.IOException;
import java.nio.charset.Charset; import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.nio.charset.UnsupportedCharsetException; import java.nio.charset.UnsupportedCharsetException;
@ -65,7 +66,7 @@ public class B64Code
*/ */
public static String encode(String s) public static String encode(String s)
{ {
return encode(s,null); return encode(s, (Charset)null);
} }
/** /**
@ -80,12 +81,25 @@ public class B64Code
{ {
byte[] bytes; byte[] bytes;
if (charEncoding==null) if (charEncoding==null)
bytes=s.getBytes(Charset.forName(StringUtil.__ISO_8859_1)); bytes=s.getBytes(StandardCharsets.ISO_8859_1);
else else
bytes=s.getBytes(Charset.forName(charEncoding)); bytes=s.getBytes(Charset.forName(charEncoding));
return new String(encode(bytes)); 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. * Fast Base 64 encode as described in RFC 1421.
* <p>Does not insert whitespace as described in RFC 1521. * <p>Does not insert whitespace as described in RFC 1521.
@ -236,6 +250,24 @@ public class B64Code
return new String(decoded,Charset.forName(charEncoding)); return new String(decoded,Charset.forName(charEncoding));
} }
/**
* 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. * Fast Base 64 decode as described in RFC 1421.
* *

View File

@ -29,6 +29,7 @@ import java.nio.ByteBuffer;
import java.nio.channels.FileChannel; import java.nio.channels.FileChannel;
import java.nio.channels.FileChannel.MapMode; import java.nio.channels.FileChannel.MapMode;
import java.nio.charset.Charset; import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import org.eclipse.jetty.util.resource.Resource; import org.eclipse.jetty.util.resource.Resource;
@ -456,7 +457,7 @@ public class BufferUtil
*/ */
public static String toString(ByteBuffer buffer) public static String toString(ByteBuffer buffer)
{ {
return toString(buffer, StringUtil.__ISO_8859_1_CHARSET); return toString(buffer, StandardCharsets.ISO_8859_1);
} }
/* ------------------------------------------------------------ */ /* ------------------------------------------------------------ */
@ -466,7 +467,7 @@ public class BufferUtil
*/ */
public static String toUTF8String(ByteBuffer buffer) public static String toUTF8String(ByteBuffer buffer)
{ {
return toString(buffer, StringUtil.__UTF8_CHARSET); return toString(buffer, StandardCharsets.UTF_8);
} }
/* ------------------------------------------------------------ */ /* ------------------------------------------------------------ */
@ -735,12 +736,12 @@ public class BufferUtil
public static ByteBuffer toBuffer(String s) 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) 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); ByteBuffer buf = ByteBuffer.allocateDirect(bytes.length);
buf.put(bytes); buf.put(bytes);
buf.flip(); buf.flip();

View File

@ -21,6 +21,7 @@ import java.io.IOException;
import java.io.OutputStream; import java.io.OutputStream;
import java.io.OutputStreamWriter; import java.io.OutputStreamWriter;
import java.io.Writer; import java.io.Writer;
import java.nio.charset.StandardCharsets;
/* ------------------------------------------------------------ */ /* ------------------------------------------------------------ */
@ -211,7 +212,7 @@ public class ByteArrayISO8859Writer extends Writer
if (_bout==null) if (_bout==null)
{ {
_bout = new ByteArrayOutputStream2(2*length); _bout = new ByteArrayOutputStream2(2*length);
_writer = new OutputStreamWriter(_bout,StringUtil.__ISO_8859_1); _writer = new OutputStreamWriter(_bout,StandardCharsets.ISO_8859_1);
} }
else else
_bout.reset(); _bout.reset();

View File

@ -29,6 +29,7 @@ import java.io.PrintWriter;
import java.io.Reader; import java.io.Reader;
import java.io.StringWriter; import java.io.StringWriter;
import java.io.Writer; import java.io.Writer;
import java.nio.charset.Charset;
import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger; import org.eclipse.jetty.util.log.Logger;
@ -311,7 +312,7 @@ public class IO
public static String toString(InputStream in) public static String toString(InputStream in)
throws IOException throws IOException
{ {
return toString(in,null); return toString(in,(Charset)null);
} }
/* ------------------------------------------------------------ */ /* ------------------------------------------------------------ */
@ -319,6 +320,14 @@ public class IO
*/ */
public static String toString(InputStream in,String encoding) public static String toString(InputStream in,String encoding)
throws IOException 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(); StringWriter writer=new StringWriter();
InputStreamReader reader = encoding==null?new InputStreamReader(in):new InputStreamReader(in,encoding); InputStreamReader reader = encoding==null?new InputStreamReader(in):new InputStreamReader(in,encoding);

View File

@ -29,6 +29,7 @@ import java.io.FilterInputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
@ -480,7 +481,7 @@ public class MultiPartInputStreamParser
} }
String boundary="--"+contentTypeBoundary; String boundary="--"+contentTypeBoundary;
byte[] byteBoundary=(boundary+"--").getBytes(StringUtil.__ISO_8859_1); byte[] byteBoundary=(boundary+"--").getBytes(StandardCharsets.ISO_8859_1);
// Get first boundary // Get first boundary
String line = null; String line = null;

View File

@ -21,6 +21,7 @@ package org.eclipse.jetty.util;
import java.io.FilterOutputStream; import java.io.FilterOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.OutputStream; import java.io.OutputStream;
import java.nio.charset.StandardCharsets;
/* ================================================================ */ /* ================================================================ */
@ -53,7 +54,7 @@ public class MultiPartOutputStream extends FilterOutputStream
boundary = "jetty"+System.identityHashCode(this)+ boundary = "jetty"+System.identityHashCode(this)+
Long.toString(System.currentTimeMillis(),36); 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) public MultiPartOutputStream(OutputStream out, String boundary)
@ -62,7 +63,7 @@ public class MultiPartOutputStream extends FilterOutputStream
super(out); super(out);
this.boundary = boundary; 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(boundaryBytes);
out.write(__CRLF); out.write(__CRLF);
if (contentType != null) 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);
out.write(__CRLF); out.write(__CRLF);
} }
@ -128,11 +129,11 @@ public class MultiPartOutputStream extends FilterOutputStream
out.write(boundaryBytes); out.write(boundaryBytes);
out.write(__CRLF); out.write(__CRLF);
if (contentType != null) 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);
for (int i=0;headers!=null && i<headers.length;i++) 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);
} }
out.write(__CRLF); out.write(__CRLF);

View File

@ -21,6 +21,7 @@ package org.eclipse.jetty.util;
import java.io.BufferedInputStream; import java.io.BufferedInputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.nio.charset.StandardCharsets;
/** /**
* ReadLineInputStream * ReadLineInputStream
@ -58,7 +59,7 @@ public class ReadLineInputStream extends BufferedInputStream
int m=markpos; int m=markpos;
markpos=-1; markpos=-1;
if (pos>m) 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; return null;
} }
@ -77,7 +78,7 @@ public class ReadLineInputStream extends BufferedInputStream
_skipLF=true; _skipLF=true;
int m=markpos; int m=markpos;
markpos=-1; 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') if (b=='\n')
@ -91,7 +92,7 @@ public class ReadLineInputStream extends BufferedInputStream
} }
int m=markpos; int m=markpos;
markpos=-1; markpos=-1;
return new String(buf,m,pos-m-1,StringUtil.__UTF8_CHARSET); return new String(buf,m,pos-m-1,StandardCharsets.UTF_8);
} }
} }
} }

View File

@ -21,13 +21,14 @@ package org.eclipse.jetty.util;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.charset.Charset; import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger; import org.eclipse.jetty.util.log.Logger;
/** Fast String Utilities. /** 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 * performance improvements over most standard library versions. The
* main aim of the optimizations is to avoid object creation unless * main aim of the optimizations is to avoid object creation unless
* absolutely required. * absolutely required.
@ -50,18 +51,29 @@ public class StringUtil
public final static String __UTF8="UTF-8"; public final static String __UTF8="UTF-8";
public final static String __UTF16="UTF-16"; public final static String __UTF16="UTF-16";
public final static Charset __UTF8_CHARSET; /**
public final static Charset __ISO_8859_1_CHARSET; * @deprecated Use {@link StandardCharsets#UTF_8}
public final static Charset __UTF16_CHARSET; */
public final static Charset __US_ASCII_CHARSET; @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 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("UTF-8",__UTF8);
CHARSETS.put("UTF8",__UTF8); CHARSETS.put("UTF8",__UTF8);
CHARSETS.put("UTF-16",__UTF16); CHARSETS.put("UTF-16",__UTF16);
@ -343,7 +355,7 @@ public class StringUtil
/* ------------------------------------------------------------ */ /* ------------------------------------------------------------ */
public static String toUTF8String(byte[] b,int offset,int length) 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) 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) 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) public static byte[] getBytes(String s,String charset)

View File

@ -20,6 +20,7 @@ package org.eclipse.jetty.util;
import java.io.IOException; import java.io.IOException;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
@ -215,7 +216,7 @@ public class TreeTrie<V> extends AbstractTrie<V>
public V getBest(String s, int offset, int len) public V getBest(String s, int offset, int len)
{ {
// TODO inefficient // 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); return getBest(b,0,b.length);
} }

View File

@ -19,6 +19,7 @@
package org.eclipse.jetty.util; package org.eclipse.jetty.util;
import java.nio.charset.Charset; import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
@ -43,7 +44,13 @@ public class URIUtil
public static final String HTTPS_COLON="https:"; public static final String HTTPS_COLON="https:";
// Use UTF-8 as per http://www.w3.org/TR/html40/appendix/notes.html#non-ascii-chars // 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() private URIUtil()
{} {}

View File

@ -25,6 +25,7 @@ import java.io.InputStream;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.io.StringWriter; import java.io.StringWriter;
import java.nio.charset.Charset; import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -59,15 +60,16 @@ public class UrlEncoded extends MultiMap<String> implements Cloneable
public static final Charset ENCODING; public static final Charset ENCODING;
static static
{ {
Charset encoding=null; Charset encoding;
try 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) catch(Exception e)
{ {
LOG.warn(e); LOG.warn(e);
encoding=StringUtil.__UTF8_CHARSET; encoding=StandardCharsets.UTF_8;
} }
ENCODING=encoding; ENCODING=encoding;
} }
@ -598,11 +600,11 @@ public class UrlEncoded extends MultiMap<String> implements Cloneable
/* -------------------------------------------------------------- */ /* -------------------------------------------------------------- */
public static void decodeUtf16To(InputStream in, MultiMap<String> map, int maxLength, int maxKeys) throws IOException 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); StringWriter buf = new StringWriter(8192);
IO.copy(input,buf,maxLength); IO.copy(input,buf,maxLength);
decodeTo(buf.getBuffer().toString(),map,StringUtil.__UTF16,maxKeys); decodeTo(buf.getBuffer().toString(),map,StandardCharsets.UTF_16,maxKeys);
} }
/* -------------------------------------------------------------- */ /* -------------------------------------------------------------- */
@ -614,7 +616,7 @@ public class UrlEncoded extends MultiMap<String> implements Cloneable
{ {
if (charset==null) if (charset==null)
{ {
if (ENCODING==StringUtil.__UTF8_CHARSET) if (ENCODING.equals(StandardCharsets.UTF_8))
decodeUtf8To(in,map,maxLength,maxKeys); decodeUtf8To(in,map,maxLength,maxKeys);
else else
decodeTo(in,map,ENCODING,maxLength,maxKeys); decodeTo(in,map,ENCODING,maxLength,maxKeys);
@ -640,19 +642,19 @@ public class UrlEncoded extends MultiMap<String> implements Cloneable
if (charset==null) if (charset==null)
charset=ENCODING; charset=ENCODING;
if (StringUtil.__UTF8_CHARSET.equals(charset)) if (StandardCharsets.UTF_8.equals(charset))
{ {
decodeUtf8To(in,map,maxLength,maxKeys); decodeUtf8To(in,map,maxLength,maxKeys);
return; return;
} }
if (StringUtil.__ISO_8859_1_CHARSET.equals(charset)) if (StandardCharsets.ISO_8859_1.equals(charset))
{ {
decode88591To(in,map,maxLength,maxKeys); decode88591To(in,map,maxLength,maxKeys);
return; 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); decodeUtf16To(in,map,maxLength,maxKeys);
return; return;
@ -757,7 +759,7 @@ public class UrlEncoded extends MultiMap<String> implements Cloneable
*/ */
public static String decodeString(String encoded,int offset,int length,Charset charset) 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; Utf8StringBuffer buffer=null;

View File

@ -19,6 +19,7 @@
package org.eclipse.jetty.util.security; package org.eclipse.jetty.util.security;
import java.io.Serializable; import java.io.Serializable;
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest; import java.security.MessageDigest;
import org.eclipse.jetty.util.StringUtil; import org.eclipse.jetty.util.StringUtil;
@ -156,7 +157,7 @@ public abstract class Credential implements Serializable
{ {
if (__md == null) __md = MessageDigest.getInstance("MD5"); if (__md == null) __md = MessageDigest.getInstance("MD5");
__md.reset(); __md.reset();
__md.update(credentials.toString().getBytes(StringUtil.__ISO_8859_1)); __md.update(credentials.toString().getBytes(StandardCharsets.ISO_8859_1));
digest = __md.digest(); digest = __md.digest();
} }
if (digest == null || digest.length != _digest.length) return false; if (digest == null || digest.length != _digest.length) return false;
@ -213,7 +214,7 @@ public abstract class Credential implements Serializable
} }
__md.reset(); __md.reset();
__md.update(password.getBytes(StringUtil.__ISO_8859_1)); __md.update(password.getBytes(StandardCharsets.ISO_8859_1));
digest = __md.digest(); digest = __md.digest();
} }

View File

@ -23,6 +23,8 @@ import junit.framework.Assert;
import org.junit.Test; import org.junit.Test;
import java.nio.charset.StandardCharsets;
public class B64CodeTest 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."; 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 @Test
public void testRFC1421() throws Exception 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"+ Assert.assertEquals("TWFuIGlzIGRpc3Rpbmd1aXNoZWQsIG5vdCBvbmx5IGJ5IGhpcyByZWFzb24sIGJ1dCBieSB0aGlz"+
"IHNpbmd1bGFyIHBhc3Npb24gZnJvbSBvdGhlciBhbmltYWxzLCB3aGljaCBpcyBhIGx1c3Qgb2Yg"+ "IHNpbmd1bGFyIHBhc3Npb24gZnJvbSBvdGhlciBhbmltYWxzLCB3aGljaCBpcyBhIGx1c3Qgb2Yg"+
"dGhlIG1pbmQsIHRoYXQgYnkgYSBwZXJzZXZlcmFuY2Ugb2YgZGVsaWdodCBpbiB0aGUgY29udGlu"+ "dGhlIG1pbmQsIHRoYXQgYnkgYSBwZXJzZXZlcmFuY2Ugb2YgZGVsaWdodCBpbiB0aGUgY29udGlu"+
"dWVkIGFuZCBpbmRlZmF0aWdhYmxlIGdlbmVyYXRpb24gb2Yga25vd2xlZGdlLCBleGNlZWRzIHRo"+ "dWVkIGFuZCBpbmRlZmF0aWdhYmxlIGdlbmVyYXRpb24gb2Yga25vd2xlZGdlLCBleGNlZWRzIHRo"+
"ZSBzaG9ydCB2ZWhlbWVuY2Ugb2YgYW55IGNhcm5hbCBwbGVhc3VyZS4=",b64); "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); b64 = new String(chars,0,chars.length);
Assert.assertEquals("TWFuIGlzIGRpc3Rpbmd1aXNoZWQsIG5vdCBvbmx5IGJ5IGhpcyByZWFzb24sIGJ1dCBieSB0aGlz"+ Assert.assertEquals("TWFuIGlzIGRpc3Rpbmd1aXNoZWQsIG5vdCBvbmx5IGJ5IGhpcyByZWFzb24sIGJ1dCBieSB0aGlz"+
"IHNpbmd1bGFyIHBhc3Npb24gZnJvbSBvdGhlciBhbmltYWxzLCB3aGljaCBpcyBhIGx1c3Qgb2Yg"+ "IHNpbmd1bGFyIHBhc3Npb24gZnJvbSBvdGhlciBhbmltYWxzLCB3aGljaCBpcyBhIGx1c3Qgb2Yg"+
@ -50,7 +52,7 @@ public class B64CodeTest
@Test @Test
public void testRFC2045() throws Exception 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); String b64 = new String(chars,0,chars.length);
Assert.assertEquals("TWFuIGlzIGRpc3Rpbmd1aXNoZWQsIG5vdCBvbmx5IGJ5IGhpcyByZWFzb24sIGJ1dCBieSB0aGlz\r\n"+ Assert.assertEquals("TWFuIGlzIGRpc3Rpbmd1aXNoZWQsIG5vdCBvbmx5IGJ5IGhpcyByZWFzb24sIGJ1dCBieSB0aGlz\r\n"+
"IHNpbmd1bGFyIHBhc3Npb24gZnJvbSBvdGhlciBhbmltYWxzLCB3aGljaCBpcyBhIGx1c3Qgb2Yg\r\n"+ "IHNpbmd1bGFyIHBhc3Npb24gZnJvbSBvdGhlciBhbmltYWxzLCB3aGljaCBpcyBhIGx1c3Qgb2Yg\r\n"+
@ -64,7 +66,7 @@ public class B64CodeTest
@Test @Test
public void testInteger() throws Exception 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]); int value=(bytes[0]<<24)+(bytes[1]<<16)+(bytes[2]<<8)+(bytes[3]);
StringBuilder b = new StringBuilder(); StringBuilder b = new StringBuilder();
@ -74,7 +76,7 @@ public class B64CodeTest
@Test @Test
public void testLong() throws Exception 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)+ 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]); ((0xffL&bytes[4])<<24)+((0xffL&bytes[5])<<16)+((0xffL&bytes[6])<<8)+(0xffL&bytes[7]);

View File

@ -21,6 +21,7 @@ package org.eclipse.jetty.util;
import java.io.OutputStream; import java.io.OutputStream;
import java.io.PipedInputStream; import java.io.PipedInputStream;
import java.io.PipedOutputStream; import java.io.PipedOutputStream;
import java.nio.charset.StandardCharsets;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import org.junit.After; import org.junit.After;
@ -60,7 +61,7 @@ public class ReadLineInputStreamTest
_pout.close(); _pout.close();
else else
{ {
_pout.write(s.getBytes(StringUtil.__UTF8_CHARSET)); _pout.write(s.getBytes(StandardCharsets.UTF_8));
Thread.sleep(50); Thread.sleep(50);
} }
} }
@ -196,7 +197,7 @@ public class ReadLineInputStreamTest
byte[] body = new byte[6]; byte[] body = new byte[6];
_in.read(body); _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("",_in.readLine());
Assert.assertEquals(null,_in.readLine()); Assert.assertEquals(null,_in.readLine());
@ -216,7 +217,7 @@ public class ReadLineInputStreamTest
byte[] body = new byte[6]; byte[] body = new byte[6];
_in.read(body); _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("",_in.readLine());
Assert.assertEquals(null,_in.readLine()); Assert.assertEquals(null,_in.readLine());
@ -236,7 +237,7 @@ public class ReadLineInputStreamTest
byte[] body = new byte[6]; byte[] body = new byte[6];
_in.read(body); _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("",_in.readLine());
Assert.assertEquals(null,_in.readLine()); Assert.assertEquals(null,_in.readLine());

View File

@ -25,6 +25,8 @@ import static org.junit.Assert.assertTrue;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Test; import org.junit.Test;
import java.nio.charset.StandardCharsets;
public class StringUtilTest public class StringUtilTest
{ {
@Test @Test
@ -160,7 +162,7 @@ public class StringUtilTest
{ {
String string = "Now \u0690xxxxxxxx"; String string = "Now \u0690xxxxxxxx";
System.err.println(string); 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(new String(bytes));
System.err.println(bytes.length); System.err.println(bytes.length);
long calc=0; long calc=0;
@ -170,7 +172,7 @@ public class StringUtilTest
long s1=System.currentTimeMillis(); long s1=System.currentTimeMillis();
for (int j=1000000; j-->0;) 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(); long s2=System.currentTimeMillis();
for (int j=1000000; j-->0;) for (int j=1000000; j-->0;)

View File

@ -21,6 +21,7 @@ package org.eclipse.jetty.util;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import java.nio.charset.Charset; import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import org.junit.Test; import org.junit.Test;
@ -65,7 +66,7 @@ public class URITest
// Test for null character (real world ugly test case) // Test for null character (real world ugly test case)
byte oddBytes[] = { '/', 0x00, '/' }; 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/")); assertEquals(odd,URIUtil.decodePath("/%00/"));
} }

View File

@ -23,6 +23,7 @@ import static org.junit.Assert.assertTrue;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.nio.charset.Charset; import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Test; import org.junit.Test;
@ -121,22 +122,22 @@ public class URLEncodedTest
assertEquals("encoded get", url_encoded.getString("Name8"),"xx, yy ,zz"); assertEquals("encoded get", url_encoded.getString("Name8"),"xx, yy ,zz");
url_encoded.clear(); 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 param size",1, url_encoded.size());
assertEquals("encoded get", "?xxVerdi \u00c6 og 2zz",url_encoded.getString("Name11")); assertEquals("encoded get", "?xxVerdi \u00c6 og 2zz",url_encoded.getString("Name11"));
url_encoded.clear(); 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 param size",1, url_encoded.size());
assertEquals("encoded get", url_encoded.getString("Name12"),"\u30edxxVerdi / og 2zz"); assertEquals("encoded get", url_encoded.getString("Name12"),"\u30edxxVerdi / og 2zz");
url_encoded.clear(); 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 param size",1, url_encoded.size());
assertEquals("encoded get","?a?b?c?d", url_encoded.getString("Name14")); assertEquals("encoded get","?a?b?c?d", url_encoded.getString("Name14"));
url_encoded.clear(); 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 param size",1, url_encoded.size());
assertEquals("encoded get", "\ufffd\ufffd\ufffd\ufffd",url_encoded.getString("Name14")); assertEquals("encoded get", "\ufffd\ufffd\ufffd\ufffd",url_encoded.getString("Name14"));
@ -160,38 +161,38 @@ public class URLEncodedTest
public void testBadEncoding() public void testBadEncoding()
{ {
UrlEncoded url_encoded = new UrlEncoded(); 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 param size",1, url_encoded.size());
assertEquals("encoded get", "xx\ufffdyy", url_encoded.getString("Name15")); 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>(); MultiMap<String> map = new MultiMap<String>();
UrlEncoded.decodeUtf8To(bad,0,bad.length,map); UrlEncoded.decodeUtf8To(bad,0,bad.length,map);
assertEquals("encoded param size",1, map.size()); assertEquals("encoded param size",1, map.size());
assertEquals("encoded get", "\ufffd\ufffd\ufffd", map.getString("Name")); assertEquals("encoded get", "\ufffd\ufffd\ufffd", map.getString("Name"));
url_encoded.clear(); 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 param size",1, url_encoded.size());
assertEquals("encoded get", "\ufffd\ufffd\ufffd", url_encoded.getString("Name")); assertEquals("encoded get", "\ufffd\ufffd\ufffd", url_encoded.getString("Name"));
url_encoded.clear(); 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 param size",1, url_encoded.size());
assertEquals("encoded get", "\ufffd\ufffd", url_encoded.getString("Name")); assertEquals("encoded get", "\ufffd\ufffd", url_encoded.getString("Name"));
assertEquals("x",UrlEncoded.decodeString("x",0,1,StringUtil.__UTF8_CHARSET)); assertEquals("x",UrlEncoded.decodeString("x",0,1,StandardCharsets.UTF_8));
assertEquals("x\ufffd",UrlEncoded.decodeString("x%",0,2,StringUtil.__UTF8_CHARSET)); assertEquals("x\ufffd",UrlEncoded.decodeString("x%",0,2,StandardCharsets.UTF_8));
assertEquals("x\ufffd",UrlEncoded.decodeString("x%2",0,3,StringUtil.__UTF8_CHARSET)); assertEquals("x\ufffd",UrlEncoded.decodeString("x%2",0,3,StandardCharsets.UTF_8));
assertEquals("x ",UrlEncoded.decodeString("x%20",0,4,StringUtil.__UTF8_CHARSET)); assertEquals("x ",UrlEncoded.decodeString("x%20",0,4,StandardCharsets.UTF_8));
assertEquals("xxx",UrlEncoded.decodeString("xxx",0,3,StringUtil.__UTF8_CHARSET)); assertEquals("xxx",UrlEncoded.decodeString("xxx",0,3,StandardCharsets.UTF_8));
assertEquals("xxx\ufffd",UrlEncoded.decodeString("xxx%",0,4,StringUtil.__UTF8_CHARSET)); assertEquals("xxx\ufffd",UrlEncoded.decodeString("xxx%",0,4,StandardCharsets.UTF_8));
assertEquals("xxx\ufffd",UrlEncoded.decodeString("xxx%u",0,5,StringUtil.__UTF8_CHARSET)); assertEquals("xxx\ufffd",UrlEncoded.decodeString("xxx%u",0,5,StandardCharsets.UTF_8));
assertEquals("xxx\ufffd",UrlEncoded.decodeString("xxx%u1",0,6,StringUtil.__UTF8_CHARSET)); assertEquals("xxx\ufffd",UrlEncoded.decodeString("xxx%u1",0,6,StandardCharsets.UTF_8));
assertEquals("xxx\ufffd",UrlEncoded.decodeString("xxx%u12",0,7,StringUtil.__UTF8_CHARSET)); assertEquals("xxx\ufffd",UrlEncoded.decodeString("xxx%u12",0,7,StandardCharsets.UTF_8));
assertEquals("xxx\ufffd",UrlEncoded.decodeString("xxx%u123",0,8,StringUtil.__UTF8_CHARSET)); assertEquals("xxx\ufffd",UrlEncoded.decodeString("xxx%u123",0,8,StandardCharsets.UTF_8));
assertEquals("xxx\u1234",UrlEncoded.decodeString("xxx%u1234",0,9,StringUtil.__UTF8_CHARSET)); 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")) 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<>(); MultiMap<String> m2 = new MultiMap<>();
UrlEncoded.decodeTo(in2, m2, Charset.forName("Shift_JIS"), -1,-1); UrlEncoded.decodeTo(in2, m2, Charset.forName("Shift_JIS"), -1,-1);
assertEquals("stream length",1,m2.size()); assertEquals("stream length",1,m2.size());
@ -278,12 +279,12 @@ public class URLEncodedTest
MultiMap<String> map = new MultiMap<>(); MultiMap<String> map = new MultiMap<>();
UrlEncoded.LOG.info("EXPECT 4 Not Valid UTF8 warnings..."); 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)); assertEquals("X"+Utf8Appendable.REPLACEMENT+Utf8Appendable.REPLACEMENT+"Z",map.getValue("name",0));
map.clear(); 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)); assertEquals("X"+Utf8Appendable.REPLACEMENT+Utf8Appendable.REPLACEMENT+"Z",map.getValue("name",0));
} }
} }

View File

@ -32,7 +32,7 @@ public class Utf8LineParserTest
{ {
private void appendUtf8(ByteBuffer buf, String line) 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) private void assertEquals(List<String> expected, List<String> actual)

View File

@ -22,6 +22,7 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.nio.charset.StandardCharsets;
import org.junit.Test; import org.junit.Test;
@ -31,7 +32,7 @@ public class Utf8StringBufferTest
public void testUtfStringBuffer() throws Exception public void testUtfStringBuffer() throws Exception
{ {
String source = "abcd012345\n\r\u0000\u00a4\u10fb\ufffdjetty"; 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(); Utf8StringBuffer buffer = new Utf8StringBuffer();
for (byte aByte : bytes) for (byte aByte : bytes)
buffer.append(aByte); buffer.append(aByte);
@ -43,7 +44,7 @@ public class Utf8StringBufferTest
public void testUtf8WithMissingByte() throws Exception public void testUtf8WithMissingByte() throws Exception
{ {
String source = "abc\u10fb"; String source = "abc\u10fb";
byte[] bytes = source.getBytes(StringUtil.__UTF8); byte[] bytes = source.getBytes(StandardCharsets.UTF_8);
Utf8StringBuffer buffer = new Utf8StringBuffer(); Utf8StringBuffer buffer = new Utf8StringBuffer();
for (int i = 0; i < bytes.length - 1; i++) for (int i = 0; i < bytes.length - 1; i++)
buffer.append(bytes[i]); buffer.append(bytes[i]);
@ -54,7 +55,7 @@ public class Utf8StringBufferTest
public void testUtf8WithAdditionalByte() throws Exception public void testUtf8WithAdditionalByte() throws Exception
{ {
String source = "abcXX"; String source = "abcXX";
byte[] bytes = source.getBytes(StringUtil.__UTF8); byte[] bytes = source.getBytes(StandardCharsets.UTF_8);
bytes[3] = (byte)0xc0; bytes[3] = (byte)0xc0;
bytes[4] = (byte)0x00; bytes[4] = (byte)0x00;
@ -68,9 +69,9 @@ public class Utf8StringBufferTest
public void testUTF32codes() throws Exception public void testUTF32codes() throws Exception
{ {
String source = "\uD842\uDF9F"; 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); assertEquals(source,jvmcheck);
Utf8StringBuffer buffer = new Utf8StringBuffer(); Utf8StringBuffer buffer = new Utf8StringBuffer();

View File

@ -24,6 +24,8 @@ import static org.junit.Assert.assertTrue;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Test; import org.junit.Test;
import java.nio.charset.StandardCharsets;
public class Utf8StringBuilderTest public class Utf8StringBuilderTest
{ {
@Test @Test
@ -76,7 +78,7 @@ public class Utf8StringBuilderTest
public void testUtfStringBuilder() throws Exception public void testUtfStringBuilder() throws Exception
{ {
String source = "abcd012345\n\r\u0000\u00a4\u10fb\ufffdjetty"; 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(); Utf8StringBuilder buffer = new Utf8StringBuilder();
for (byte aByte : bytes) for (byte aByte : bytes)
buffer.append(aByte); buffer.append(aByte);
@ -88,7 +90,7 @@ public class Utf8StringBuilderTest
public void testShort() throws Exception public void testShort() throws Exception
{ {
String source = "abc\u10fb"; String source = "abc\u10fb";
byte[] bytes = source.getBytes(StringUtil.__UTF8); byte[] bytes = source.getBytes(StandardCharsets.UTF_8);
Utf8StringBuilder buffer = new Utf8StringBuilder(); Utf8StringBuilder buffer = new Utf8StringBuilder();
for (int i = 0; i < bytes.length - 1; i++) for (int i = 0; i < bytes.length - 1; i++)
buffer.append(bytes[i]); buffer.append(bytes[i]);
@ -99,7 +101,7 @@ public class Utf8StringBuilderTest
public void testLong() throws Exception public void testLong() throws Exception
{ {
String source = "abcXX"; String source = "abcXX";
byte[] bytes = source.getBytes(StringUtil.__UTF8); byte[] bytes = source.getBytes(StandardCharsets.UTF_8);
bytes[3] = (byte)0xc0; bytes[3] = (byte)0xc0;
bytes[4] = (byte)0x00; bytes[4] = (byte)0x00;
@ -122,9 +124,9 @@ public class Utf8StringBuilderTest
public void testUTF32codes() throws Exception public void testUTF32codes() throws Exception
{ {
String source = "\uD842\uDF9F"; 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); assertEquals(source,jvmcheck);
Utf8StringBuilder buffer = new Utf8StringBuilder(); Utf8StringBuilder buffer = new Utf8StringBuilder();

View File

@ -26,6 +26,7 @@ import java.io.PrintStream;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.io.StringWriter; import java.io.StringWriter;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.nio.charset.StandardCharsets;
import java.util.Properties; import java.util.Properties;
import org.junit.Assert; import org.junit.Assert;
@ -647,7 +648,7 @@ public class StdErrLogTest
log.debug("Show me the source!"); 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); // System.err.print(output);
Assert.assertThat(output, containsString(".StdErrLogTest#testPrintSource(StdErrLogTest.java:")); Assert.assertThat(output, containsString(".StdErrLogTest#testPrintSource(StdErrLogTest.java:"));

Some files were not shown because too many files have changed in this diff Show More