You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by ol...@apache.org on 2012/04/17 23:47:27 UTC
svn commit: r1327298 [2/2] - in /httpcomponents/httpcore/trunk:
httpcore-ab/src/main/java/org/apache/http/benchmark/
httpcore-nio/src/examples/org/apache/http/examples/nio/
httpcore-nio/src/main/java/org/apache/http/nio/entity/
httpcore-nio/src/main/ja...
Modified: httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/entity/TestInputStreamEntity.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/entity/TestInputStreamEntity.java?rev=1327298&r1=1327297&r2=1327298&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/entity/TestInputStreamEntity.java (original)
+++ httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/entity/TestInputStreamEntity.java Tue Apr 17 21:47:26 2012
@@ -31,7 +31,7 @@ import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
-import org.apache.http.protocol.HTTP;
+import org.apache.http.Consts;
import org.junit.Assert;
import org.junit.Test;
@@ -43,7 +43,7 @@ public class TestInputStreamEntity {
@Test
public void testBasics() throws Exception {
- byte[] bytes = "Message content".getBytes(HTTP.ISO_8859_1);
+ byte[] bytes = "Message content".getBytes(Consts.ISO_8859_1.name());
InputStream instream = new ByteArrayInputStream(bytes);
InputStreamEntity httpentity = new InputStreamEntity(instream, bytes.length);
@@ -66,7 +66,7 @@ public class TestInputStreamEntity {
@Test
public void testWriteTo() throws Exception {
- byte[] bytes = "Message content".getBytes(HTTP.ISO_8859_1);
+ byte[] bytes = "Message content".getBytes(Consts.ISO_8859_1.name());
InputStream instream = new ByteArrayInputStream(bytes);
InputStreamEntity httpentity = new InputStreamEntity(instream, 7);
@@ -75,7 +75,7 @@ public class TestInputStreamEntity {
byte[] bytes2 = out.toByteArray();
Assert.assertNotNull(bytes2);
Assert.assertEquals(7, bytes2.length);
- String s = new String(bytes2, HTTP.ISO_8859_1);
+ String s = new String(bytes2, Consts.ISO_8859_1.name());
Assert.assertEquals("Message", s);
instream = new ByteArrayInputStream(bytes);
Modified: httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/entity/TestStringEntity.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/entity/TestStringEntity.java?rev=1327298&r1=1327297&r2=1327298&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/entity/TestStringEntity.java (original)
+++ httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/entity/TestStringEntity.java Tue Apr 17 21:47:26 2012
@@ -29,7 +29,7 @@ package org.apache.http.entity;
import java.io.ByteArrayOutputStream;
-import org.apache.http.protocol.HTTP;
+import org.apache.http.Consts;
import org.junit.Assert;
import org.junit.Test;
@@ -42,9 +42,9 @@ public class TestStringEntity {
@Test
public void testBasics() throws Exception {
String s = "Message content";
- StringEntity httpentity = new StringEntity(s, HTTP.ISO_8859_1);
+ StringEntity httpentity = new StringEntity(s, ContentType.TEXT_PLAIN);
- byte[] bytes = s.getBytes(HTTP.ISO_8859_1);
+ byte[] bytes = s.getBytes(Consts.ISO_8859_1.name());
Assert.assertEquals(bytes.length, httpentity.getContentLength());
Assert.assertNotNull(httpentity.getContent());
Assert.assertTrue(httpentity.isRepeatable());
@@ -65,10 +65,10 @@ public class TestStringEntity {
public void testDefaultContent() throws Exception {
String s = "Message content";
StringEntity httpentity = new StringEntity(s, ContentType.create("text/csv", "ANSI_X3.4-1968"));
- Assert.assertEquals("text/csv; charset=ansi_x3.4-1968",
+ Assert.assertEquals("text/csv; charset=US-ASCII",
httpentity.getContentType().getValue());
- httpentity = new StringEntity(s, HTTP.US_ASCII);
- Assert.assertEquals("text/plain; charset=us-ascii",
+ httpentity = new StringEntity(s, Consts.ASCII.name());
+ Assert.assertEquals("text/plain; charset=US-ASCII",
httpentity.getContentType().getValue());
httpentity = new StringEntity(s);
Assert.assertEquals("text/plain; charset=ISO-8859-1",
@@ -78,7 +78,7 @@ public class TestStringEntity {
@Test
public void testWriteTo() throws Exception {
String s = "Message content";
- byte[] bytes = s.getBytes(HTTP.ISO_8859_1);
+ byte[] bytes = s.getBytes(Consts.ISO_8859_1.name());
StringEntity httpentity = new StringEntity(s);
ByteArrayOutputStream out = new ByteArrayOutputStream();
Modified: httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/impl/io/TestSessionBuffers.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/impl/io/TestSessionBuffers.java?rev=1327298&r1=1327297&r2=1327298&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/impl/io/TestSessionBuffers.java (original)
+++ httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/impl/io/TestSessionBuffers.java Tue Apr 17 21:47:26 2012
@@ -34,6 +34,7 @@ import java.io.InputStream;
import java.nio.charset.CharacterCodingException;
import java.nio.charset.CodingErrorAction;
+import org.apache.http.Consts;
import org.apache.http.impl.SessionInputBufferMock;
import org.apache.http.impl.SessionOutputBufferMock;
import org.apache.http.io.HttpTransportMetrics;
@@ -41,7 +42,6 @@ import org.apache.http.params.BasicHttpP
import org.apache.http.params.CoreConnectionPNames;
import org.apache.http.params.HttpParams;
import org.apache.http.params.HttpProtocolParams;
-import org.apache.http.protocol.HTTP;
import org.apache.http.util.CharArrayBuffer;
import org.junit.Assert;
import org.junit.Test;
@@ -495,7 +495,7 @@ public class TestSessionBuffers {
String s1 = constructString(SWISS_GERMAN_HELLO);
HttpParams params = new BasicHttpParams();
- HttpProtocolParams.setHttpElementCharset(params, HTTP.ISO_8859_1);
+ HttpProtocolParams.setHttpElementCharset(params, Consts.ISO_8859_1.name());
SessionOutputBufferMock outbuffer = new SessionOutputBufferMock(params);
@@ -512,13 +512,13 @@ public class TestSessionBuffers {
outbuffer.writeLine(chbuffer);
outbuffer.flush();
long bytesWritten = outbuffer.getMetrics().getBytesTransferred();
- long expected = ((s1.toString().getBytes(HTTP.ISO_8859_1).length + 2)) * 10 + 2;
+ long expected = ((s1.toString().getBytes(Consts.ISO_8859_1.name()).length + 2)) * 10 + 2;
Assert.assertEquals(expected, bytesWritten);
SessionInputBufferMock inbuffer = new SessionInputBufferMock(
outbuffer.getData(),
params);
- HttpProtocolParams.setHttpElementCharset(params, HTTP.ISO_8859_1);
+ HttpProtocolParams.setHttpElementCharset(params, Consts.ISO_8859_1.name());
CharArrayBuffer buf = new CharArrayBuffer(64);
for (int i = 0; i < 10; i++) {
@@ -539,7 +539,7 @@ public class TestSessionBuffers {
public void testUnmappableInputAction() throws Exception {
BasicHttpParams params = new BasicHttpParams();
String s = "In valid ISO-8859-1 character string because of Ŵ and ŵ";
- HttpProtocolParams.setHttpElementCharset(params, HTTP.ISO_8859_1);
+ HttpProtocolParams.setHttpElementCharset(params, Consts.ISO_8859_1.name());
// Action with report
HttpProtocolParams.setUnmappableInputAction(params, CodingErrorAction.REPORT);
Modified: httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/integration/TestSyncHttp.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/integration/TestSyncHttp.java?rev=1327298&r1=1327297&r2=1327298&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/integration/TestSyncHttp.java (original)
+++ httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/integration/TestSyncHttp.java Tue Apr 17 21:47:26 2012
@@ -34,6 +34,7 @@ import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.net.Socket;
+import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
@@ -615,7 +616,7 @@ public class TestSyncHttp {
private final byte[] raw;
private int n;
- public RepeatingEntity(final String content, String charset, int n) {
+ public RepeatingEntity(final String content, Charset charset, int n) {
super();
if (content == null) {
throw new IllegalArgumentException("Content may not be null");
@@ -624,11 +625,14 @@ public class TestSyncHttp {
throw new IllegalArgumentException("N may not be negative or zero");
}
if (charset == null) {
- charset = "US-ASCII";
+ charset = Charset.forName("US-ASCII"); // US-ASCII is built-in
}
byte[] b;
+ // Java 6 only:
+ // b = content.getBytes(charset);
+ // Java 5 OK:
try {
- b = content.getBytes(charset);
+ b = content.getBytes(charset.name());
} catch (UnsupportedEncodingException ex) {
b = content.getBytes();
}
@@ -714,9 +718,9 @@ public class TestSyncHttp {
HttpEntity incoming = ((HttpEntityEnclosingRequest) request).getEntity();
String line = EntityUtils.toString(incoming);
ContentType contentType = ContentType.getOrDefault(incoming);
- String charset = contentType.getCharset();
+ Charset charset = contentType.getCharset();
if (charset == null) {
- charset = HTTP.DEFAULT_CONTENT_CHARSET;
+ charset = HTTP.DEF_CONTENT_CHARSET;
}
RepeatingEntity outgoing = new RepeatingEntity(line, charset, n);
outgoing.setChunked(n % 2 == 0);
@@ -752,9 +756,9 @@ public class TestSyncHttp {
Assert.assertNotNull(incoming);
InputStream instream = incoming.getContent();
ContentType contentType = ContentType.getOrDefault(incoming);
- String charset = contentType.getCharset();
+ Charset charset = contentType.getCharset();
if (charset == null) {
- charset = HTTP.DEFAULT_CONTENT_CHARSET;
+ charset = HTTP.DEF_CONTENT_CHARSET;
}
Assert.assertNotNull(instream);
BufferedReader reader = new BufferedReader(new InputStreamReader(instream, charset));