Use String methods and constructors that require Charset instead of String

git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk@1561066 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Oleg Kalnichevski 2014-01-24 17:04:04 +00:00
parent 715a34c860
commit e9c8797108
11 changed files with 71 additions and 123 deletions

View File

@ -32,7 +32,6 @@ import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.nio.charset.Charset; import java.nio.charset.Charset;
import java.util.Arrays; import java.util.Arrays;
import java.util.Date; import java.util.Date;
@ -80,7 +79,7 @@ public class TestHttpCacheEntrySerializers {
assertTrue(areEqual(readEntry, writeEntry)); assertTrue(areEqual(readEntry, writeEntry));
} }
private HttpCacheEntry makeCacheEntryWithVariantMap() throws UnsupportedEncodingException { private HttpCacheEntry makeCacheEntryWithVariantMap() {
final Header[] headers = new Header[5]; final Header[] headers = new Header[5];
for (int i = 0; i < headers.length; i++) { for (int i = 0; i < headers.length; i++) {
headers[i] = new BasicHeader("header" + i, "value" + i); headers[i] = new BasicHeader("header" + i, "value" + i);
@ -94,7 +93,7 @@ public class TestHttpCacheEntrySerializers {
variantMap.put("test variant 2","true"); variantMap.put("test variant 2","true");
final HttpCacheEntry cacheEntry = new HttpCacheEntry(new Date(), new Date(), final HttpCacheEntry cacheEntry = new HttpCacheEntry(new Date(), new Date(),
slObj, headers, new HeapResource(Base64.decodeBase64(body slObj, headers, new HeapResource(Base64.decodeBase64(body
.getBytes(UTF8.name()))), variantMap); .getBytes(UTF8))), variantMap);
return cacheEntry; return cacheEntry;
} }

View File

@ -26,6 +26,7 @@
*/ */
package org.apache.http.impl.client.cache; package org.apache.http.impl.client.cache;
import org.apache.http.Consts;
import org.apache.http.HttpEntity; import org.apache.http.HttpEntity;
import org.apache.http.HttpException; import org.apache.http.HttpException;
import org.apache.http.HttpRequest; import org.apache.http.HttpRequest;
@ -50,7 +51,6 @@ import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import java.io.IOException; import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.Locale; import java.util.Locale;
@ -283,11 +283,7 @@ public class TestStaleWhileRevalidationReleasesConnection {
public byte[] getHeaderContent(final HttpRequest request) { public byte[] getHeaderContent(final HttpRequest request) {
final Header contentHeader = request.getFirstHeader(DEFAULT_CLIENT_CONTROLLED_CONTENT_HEADER); final Header contentHeader = request.getFirstHeader(DEFAULT_CLIENT_CONTROLLED_CONTENT_HEADER);
if(contentHeader!=null) { if(contentHeader!=null) {
try { return contentHeader.getValue().getBytes(Consts.UTF_8);
return contentHeader.getValue().getBytes("UTF-8");
} catch(final UnsupportedEncodingException e) {
return contentHeader.getValue().getBytes();
}
} else { } else {
return DEFAULT_CONTENT; return DEFAULT_CONTENT;
} }

View File

@ -27,6 +27,7 @@
package org.apache.http.impl.auth; package org.apache.http.impl.auth;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.nio.charset.Charset;
import java.security.Key; import java.security.Key;
import java.security.MessageDigest; import java.security.MessageDigest;
import java.util.Arrays; import java.util.Arrays;
@ -36,7 +37,9 @@ import javax.crypto.Cipher;
import javax.crypto.spec.SecretKeySpec; import javax.crypto.spec.SecretKeySpec;
import org.apache.commons.codec.binary.Base64; import org.apache.commons.codec.binary.Base64;
import org.apache.http.Consts;
import org.apache.http.annotation.NotThreadSafe; import org.apache.http.annotation.NotThreadSafe;
import org.apache.http.util.CharsetUtils;
import org.apache.http.util.EncodingUtils; import org.apache.http.util.EncodingUtils;
/** /**
@ -48,6 +51,8 @@ import org.apache.http.util.EncodingUtils;
@NotThreadSafe @NotThreadSafe
final class NTLMEngineImpl implements NTLMEngine { final class NTLMEngineImpl implements NTLMEngine {
private static final Charset UNICODE_LITTLE_UNMARKED = CharsetUtils.lookup("UnicodeLittleUnmarked");
// Flags we use; descriptions according to: // Flags we use; descriptions according to:
// http://davenport.sourceforge.net/ntlm.html // http://davenport.sourceforge.net/ntlm.html
// and // and
@ -81,16 +86,13 @@ final class NTLMEngineImpl implements NTLMEngine {
} }
/** Character encoding */ /** Character encoding */
static final String DEFAULT_CHARSET = "ASCII"; static final Charset DEFAULT_CHARSET = Consts.ASCII;
/** The character set to use for encoding the credentials */
private String credentialCharset = DEFAULT_CHARSET;
/** The signature string as bytes in the default encoding */ /** The signature string as bytes in the default encoding */
private static final byte[] SIGNATURE; private static final byte[] SIGNATURE;
static { static {
final byte[] bytesWithoutNull = EncodingUtils.getBytes("NTLMSSP", "ASCII"); final byte[] bytesWithoutNull = "NTLMSSP".getBytes(Consts.ASCII);
SIGNATURE = new byte[bytesWithoutNull.length + 1]; SIGNATURE = new byte[bytesWithoutNull.length + 1];
System.arraycopy(bytesWithoutNull, 0, SIGNATURE, 0, bytesWithoutNull.length); System.arraycopy(bytesWithoutNull, 0, SIGNATURE, 0, bytesWithoutNull.length);
SIGNATURE[bytesWithoutNull.length] = (byte) 0x00; SIGNATURE[bytesWithoutNull.length] = (byte) 0x00;
@ -169,21 +171,6 @@ final class NTLMEngineImpl implements NTLMEngine {
targetInformation).getResponse(); targetInformation).getResponse();
} }
/**
* @return Returns the credentialCharset.
*/
String getCredentialCharset() {
return credentialCharset;
}
/**
* @param credentialCharset
* The credentialCharset to set.
*/
void setCredentialCharset(final String credentialCharset) {
this.credentialCharset = credentialCharset;
}
/** Strip dot suffix from a name */ /** Strip dot suffix from a name */
private static String stripDotSuffix(final String value) { private static String stripDotSuffix(final String value) {
if (value == null) { if (value == null) {
@ -608,13 +595,13 @@ final class NTLMEngineImpl implements NTLMEngine {
*/ */
private static byte[] lmHash(final String password) throws NTLMEngineException { private static byte[] lmHash(final String password) throws NTLMEngineException {
try { try {
final byte[] oemPassword = password.toUpperCase(Locale.US).getBytes("US-ASCII"); final byte[] oemPassword = password.toUpperCase(Locale.US).getBytes(Consts.ASCII);
final int length = Math.min(oemPassword.length, 14); final int length = Math.min(oemPassword.length, 14);
final byte[] keyBytes = new byte[14]; final byte[] keyBytes = new byte[14];
System.arraycopy(oemPassword, 0, keyBytes, 0, length); System.arraycopy(oemPassword, 0, keyBytes, 0, length);
final Key lowKey = createDESKey(keyBytes, 0); final Key lowKey = createDESKey(keyBytes, 0);
final Key highKey = createDESKey(keyBytes, 7); final Key highKey = createDESKey(keyBytes, 7);
final byte[] magicConstant = "KGS!@#$%".getBytes("US-ASCII"); final byte[] magicConstant = "KGS!@#$%".getBytes(Consts.ASCII);
final Cipher des = Cipher.getInstance("DES/ECB/NoPadding"); final Cipher des = Cipher.getInstance("DES/ECB/NoPadding");
des.init(Cipher.ENCRYPT_MODE, lowKey); des.init(Cipher.ENCRYPT_MODE, lowKey);
final byte[] lowHash = des.doFinal(magicConstant); final byte[] lowHash = des.doFinal(magicConstant);
@ -639,14 +626,13 @@ final class NTLMEngineImpl implements NTLMEngine {
* the NTLM Response and the NTLMv2 and LMv2 Hashes. * the NTLM Response and the NTLMv2 and LMv2 Hashes.
*/ */
private static byte[] ntlmHash(final String password) throws NTLMEngineException { private static byte[] ntlmHash(final String password) throws NTLMEngineException {
try { if (UNICODE_LITTLE_UNMARKED == null) {
final byte[] unicodePassword = password.getBytes("UnicodeLittleUnmarked"); throw new NTLMEngineException("Unicode not supported");
}
final byte[] unicodePassword = password.getBytes(UNICODE_LITTLE_UNMARKED);
final MD4 md4 = new MD4(); final MD4 md4 = new MD4();
md4.update(unicodePassword); md4.update(unicodePassword);
return md4.getOutput(); return md4.getOutput();
} catch (final UnsupportedEncodingException e) {
throw new NTLMEngineException("Unicode not supported: " + e.getMessage(), e);
}
} }
/** /**
@ -657,17 +643,16 @@ final class NTLMEngineImpl implements NTLMEngine {
*/ */
private static byte[] lmv2Hash(final String domain, final String user, final byte[] ntlmHash) private static byte[] lmv2Hash(final String domain, final String user, final byte[] ntlmHash)
throws NTLMEngineException { throws NTLMEngineException {
try { if (UNICODE_LITTLE_UNMARKED == null) {
throw new NTLMEngineException("Unicode not supported");
}
final HMACMD5 hmacMD5 = new HMACMD5(ntlmHash); final HMACMD5 hmacMD5 = new HMACMD5(ntlmHash);
// Upper case username, upper case domain! // Upper case username, upper case domain!
hmacMD5.update(user.toUpperCase(Locale.US).getBytes("UnicodeLittleUnmarked")); hmacMD5.update(user.toUpperCase(Locale.US).getBytes(UNICODE_LITTLE_UNMARKED));
if (domain != null) { if (domain != null) {
hmacMD5.update(domain.toUpperCase(Locale.US).getBytes("UnicodeLittleUnmarked")); hmacMD5.update(domain.toUpperCase(Locale.US).getBytes(UNICODE_LITTLE_UNMARKED));
} }
return hmacMD5.getOutput(); return hmacMD5.getOutput();
} catch (final UnsupportedEncodingException e) {
throw new NTLMEngineException("Unicode not supported! " + e.getMessage(), e);
}
} }
/** /**
@ -678,17 +663,16 @@ final class NTLMEngineImpl implements NTLMEngine {
*/ */
private static byte[] ntlmv2Hash(final String domain, final String user, final byte[] ntlmHash) private static byte[] ntlmv2Hash(final String domain, final String user, final byte[] ntlmHash)
throws NTLMEngineException { throws NTLMEngineException {
try { if (UNICODE_LITTLE_UNMARKED == null) {
throw new NTLMEngineException("Unicode not supported");
}
final HMACMD5 hmacMD5 = new HMACMD5(ntlmHash); final HMACMD5 hmacMD5 = new HMACMD5(ntlmHash);
// Upper case username, mixed case target!! // Upper case username, mixed case target!!
hmacMD5.update(user.toUpperCase(Locale.US).getBytes("UnicodeLittleUnmarked")); hmacMD5.update(user.toUpperCase(Locale.US).getBytes(UNICODE_LITTLE_UNMARKED));
if (domain != null) { if (domain != null) {
hmacMD5.update(domain.getBytes("UnicodeLittleUnmarked")); hmacMD5.update(domain.getBytes(UNICODE_LITTLE_UNMARKED));
} }
return hmacMD5.getOutput(); return hmacMD5.getOutput();
} catch (final UnsupportedEncodingException e) {
throw new NTLMEngineException("Unicode not supported! " + e.getMessage(), e);
}
} }
/** /**
@ -848,8 +832,7 @@ final class NTLMEngineImpl implements NTLMEngine {
/** Constructor to use when message contents are known */ /** Constructor to use when message contents are known */
NTLMMessage(final String messageBody, final int expectedType) throws NTLMEngineException { NTLMMessage(final String messageBody, final int expectedType) throws NTLMEngineException {
messageContents = Base64.decodeBase64(EncodingUtils.getBytes(messageBody, messageContents = Base64.decodeBase64(messageBody.getBytes(DEFAULT_CHARSET));
DEFAULT_CHARSET));
// Look for NTLM message // Look for NTLM message
if (messageContents.length < SIGNATURE.length) { if (messageContents.length < SIGNATURE.length) {
throw new NTLMEngineException("NTLM message decoding error - packet too short"); throw new NTLMEngineException("NTLM message decoding error - packet too short");
@ -1001,18 +984,14 @@ final class NTLMEngineImpl implements NTLMEngine {
/** Constructor. Include the arguments the message will need */ /** Constructor. Include the arguments the message will need */
Type1Message(final String domain, final String host) throws NTLMEngineException { Type1Message(final String domain, final String host) throws NTLMEngineException {
super(); super();
try {
// Strip off domain name from the host! // Strip off domain name from the host!
final String unqualifiedHost = convertHost(host); final String unqualifiedHost = convertHost(host);
// Use only the base domain name! // Use only the base domain name!
final String unqualifiedDomain = convertDomain(domain); final String unqualifiedDomain = convertDomain(domain);
hostBytes = unqualifiedHost != null? unqualifiedHost.getBytes("ASCII") : null; hostBytes = unqualifiedHost != null? unqualifiedHost.getBytes(Consts.ASCII) : null;
domainBytes = unqualifiedDomain != null ? unqualifiedDomain domainBytes = unqualifiedDomain != null ? unqualifiedDomain
.toUpperCase(Locale.US).getBytes("ASCII") : null; .toUpperCase(Locale.US).getBytes(Consts.ASCII) : null;
} catch (final UnsupportedEncodingException e) {
throw new NTLMEngineException("Unicode unsupported: " + e.getMessage(), e);
}
} }
/** /**
@ -1260,16 +1239,13 @@ final class NTLMEngineImpl implements NTLMEngine {
} else { } else {
sessionKey = null; sessionKey = null;
} }
if (UNICODE_LITTLE_UNMARKED == null) {
try { throw new NTLMEngineException("Unicode not supported");
hostBytes = unqualifiedHost != null ? unqualifiedHost
.getBytes("UnicodeLittleUnmarked") : null;
domainBytes = unqualifiedDomain != null ? unqualifiedDomain
.toUpperCase(Locale.US).getBytes("UnicodeLittleUnmarked") : null;
userBytes = user.getBytes("UnicodeLittleUnmarked");
} catch (final UnsupportedEncodingException e) {
throw new NTLMEngineException("Unicode not supported: " + e.getMessage(), e);
} }
hostBytes = unqualifiedHost != null ? unqualifiedHost.getBytes(UNICODE_LITTLE_UNMARKED) : null;
domainBytes = unqualifiedDomain != null ? unqualifiedDomain
.toUpperCase(Locale.US).getBytes(UNICODE_LITTLE_UNMARKED) : null;
userBytes = user.getBytes(UNICODE_LITTLE_UNMARKED);
} }
/** Assemble the response */ /** Assemble the response */

View File

@ -35,6 +35,7 @@ import java.util.zip.CRC32;
import java.util.zip.CheckedInputStream; import java.util.zip.CheckedInputStream;
import java.util.zip.Checksum; import java.util.zip.Checksum;
import org.apache.http.Consts;
import org.apache.http.HttpEntity; import org.apache.http.HttpEntity;
import org.apache.http.entity.InputStreamEntity; import org.apache.http.entity.InputStreamEntity;
import org.apache.http.entity.StringEntity; import org.apache.http.entity.StringEntity;
@ -61,7 +62,7 @@ public class TestDecompressingEntity {
@Test @Test
public void testStreaming() throws Exception { public void testStreaming() throws Exception {
final CRC32 crc32 = new CRC32(); final CRC32 crc32 = new CRC32();
final ByteArrayInputStream in = new ByteArrayInputStream("1234567890".getBytes("ASCII")); final ByteArrayInputStream in = new ByteArrayInputStream("1234567890".getBytes(Consts.ASCII));
final InputStreamEntity wrapped = new InputStreamEntity(in, -1); final InputStreamEntity wrapped = new InputStreamEntity(in, -1);
final ChecksumEntity entity = new ChecksumEntity(wrapped, crc32); final ChecksumEntity entity = new ChecksumEntity(wrapped, crc32);
Assert.assertTrue(entity.isStreaming()); Assert.assertTrue(entity.isStreaming());

View File

@ -26,6 +26,7 @@
*/ */
package org.apache.http.impl.auth; package org.apache.http.impl.auth;
import org.apache.http.Consts;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Test; import org.junit.Test;
@ -69,7 +70,7 @@ public class TestNTLMEngineImpl {
static void checkMD4(final String input, final String hexOutput) throws Exception { static void checkMD4(final String input, final String hexOutput) throws Exception {
NTLMEngineImpl.MD4 md4; NTLMEngineImpl.MD4 md4;
md4 = new NTLMEngineImpl.MD4(); md4 = new NTLMEngineImpl.MD4();
md4.update(input.getBytes("ASCII")); md4.update(input.getBytes(Consts.ASCII));
final byte[] answer = md4.getOutput(); final byte[] answer = md4.getOutput();
final byte[] correctAnswer = toBytes(hexOutput); final byte[] correctAnswer = toBytes(hexOutput);
if (answer.length != correctAnswer.length) { if (answer.length != correctAnswer.length) {

View File

@ -39,6 +39,7 @@ import java.util.concurrent.Executors;
import java.util.zip.Deflater; import java.util.zip.Deflater;
import java.util.zip.GZIPOutputStream; import java.util.zip.GZIPOutputStream;
import org.apache.http.Consts;
import org.apache.http.Header; import org.apache.http.Header;
import org.apache.http.HeaderElement; import org.apache.http.HeaderElement;
import org.apache.http.HttpException; import org.apache.http.HttpException;
@ -310,7 +311,7 @@ public class TestContentCodings extends IntegrationTestBase {
// response.setEntity(new InputStreamEntity(new DeflaterInputStream(new // response.setEntity(new InputStreamEntity(new DeflaterInputStream(new
// ByteArrayInputStream( // ByteArrayInputStream(
// entityText.getBytes("utf-8"))), -1)); // entityText.getBytes("utf-8"))), -1));
final byte[] uncompressed = entityText.getBytes("utf-8"); final byte[] uncompressed = entityText.getBytes(Consts.UTF_8);
final Deflater compressor = new Deflater(Deflater.DEFAULT_COMPRESSION, rfc1951); final Deflater compressor = new Deflater(Deflater.DEFAULT_COMPRESSION, rfc1951);
compressor.setInput(uncompressed); compressor.setInput(uncompressed);
compressor.finish(); compressor.finish();
@ -368,7 +369,7 @@ public class TestContentCodings extends IntegrationTestBase {
final OutputStream out = new GZIPOutputStream(bytes); final OutputStream out = new GZIPOutputStream(bytes);
final ByteArrayInputStream uncompressed = new ByteArrayInputStream( final ByteArrayInputStream uncompressed = new ByteArrayInputStream(
entityText.getBytes("utf-8")); entityText.getBytes(Consts.UTF_8));
final byte[] buf = new byte[60]; final byte[] buf = new byte[60];

View File

@ -100,7 +100,7 @@ public class SessionInputBufferMock extends SessionInputBufferImpl {
public SessionInputBufferMock( public SessionInputBufferMock(
final String s, final String s,
final Charset charset) throws UnsupportedEncodingException { final Charset charset) throws UnsupportedEncodingException {
this(s.getBytes(charset.name()), charset); this(s.getBytes(charset), charset);
} }
@Override @Override

View File

@ -30,9 +30,9 @@ package org.apache.http.localserver;
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.io.UnsupportedEncodingException;
import java.util.Locale; import java.util.Locale;
import org.apache.http.Consts;
import org.apache.http.HttpException; import org.apache.http.HttpException;
import org.apache.http.HttpRequest; import org.apache.http.HttpRequest;
import org.apache.http.HttpResponse; import org.apache.http.HttpResponse;
@ -42,19 +42,10 @@ import org.apache.http.entity.AbstractHttpEntity;
import org.apache.http.protocol.HttpContext; import org.apache.http.protocol.HttpContext;
import org.apache.http.protocol.HttpRequestHandler; import org.apache.http.protocol.HttpRequestHandler;
/** /**
* A handler that generates random data. * A handler that generates random data.
*
*
*
* <!-- empty lines to avoid 'svn diff' problems -->
*/ */
public class RandomHandler public class RandomHandler implements HttpRequestHandler {
implements HttpRequestHandler {
// public default constructor
/** /**
* Handles a request by generating random data. * Handles a request by generating random data.
@ -131,19 +122,8 @@ public class RandomHandler
public static class RandomEntity extends AbstractHttpEntity { public static class RandomEntity extends AbstractHttpEntity {
/** The range from which to generate random data. */ /** The range from which to generate random data. */
private final static byte[] RANGE; private final static byte[] RANGE = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
static { .getBytes(Consts.ASCII);
byte[] range = null;
try {
range = ("abcdefghijklmnopqrstuvwxyz" +
"ABCDEFGHIJKLMNOPQRSTUVWXYZ" + "0123456789"
).getBytes("US-ASCII");
} catch (final UnsupportedEncodingException uex) {
// never, US-ASCII is guaranteed
}
RANGE = range;
}
/** The length of the random data to generate. */ /** The length of the random data to generate. */
protected final long length; protected final long length;

View File

@ -35,7 +35,6 @@ import java.io.OutputStream;
import java.io.Reader; import java.io.Reader;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.nio.charset.Charset; import java.nio.charset.Charset;
import java.nio.charset.UnsupportedCharsetException;
import org.apache.http.Consts; import org.apache.http.Consts;
import org.apache.http.entity.ContentType; import org.apache.http.entity.ContentType;
@ -154,13 +153,7 @@ public class StringBody extends AbstractContentBody {
public StringBody(final String text, final ContentType contentType) { public StringBody(final String text, final ContentType contentType) {
super(contentType); super(contentType);
final Charset charset = contentType.getCharset(); final Charset charset = contentType.getCharset();
final String csname = charset != null ? charset.name() : Consts.ASCII.name(); this.content = text.getBytes(charset != null ? charset : Consts.ASCII);
try {
this.content = text.getBytes(csname);
} catch (final UnsupportedEncodingException ex) {
// Should never happen
throw new UnsupportedCharsetException(csname);
}
} }
public Reader getReader() { public Reader getReader() {

View File

@ -29,6 +29,7 @@ package org.apache.http.entity.mime;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import org.apache.http.Consts;
import org.apache.http.entity.ContentType; import org.apache.http.entity.ContentType;
import org.apache.http.entity.mime.content.InputStreamBody; import org.apache.http.entity.mime.content.InputStreamBody;
import org.apache.http.entity.mime.content.StringBody; import org.apache.http.entity.mime.content.StringBody;
@ -66,7 +67,7 @@ public class TestMultipartContentBody {
@Test @Test
public void testInputStreamBody() throws Exception { public void testInputStreamBody() throws Exception {
final byte[] stuff = "Stuff".getBytes("US-ASCII"); final byte[] stuff = "Stuff".getBytes(Consts.ASCII);
final InputStreamBody b1 = new InputStreamBody(new ByteArrayInputStream(stuff), "stuff"); final InputStreamBody b1 = new InputStreamBody(new ByteArrayInputStream(stuff), "stuff");
Assert.assertEquals(-1, b1.getContentLength()); Assert.assertEquals(-1, b1.getContentLength());

View File

@ -341,17 +341,17 @@ public class TestMultipartForm {
"Content-Disposition: form-data; name=\"field1\"\r\n" + "Content-Disposition: form-data; name=\"field1\"\r\n" +
"Content-Type: text/plain; charset=ISO-8859-1\r\n" + "Content-Type: text/plain; charset=ISO-8859-1\r\n" +
"Content-Transfer-Encoding: 8bit\r\n" + "Content-Transfer-Encoding: 8bit\r\n" +
"\r\n").getBytes("US-ASCII")); "\r\n").getBytes(Consts.ASCII));
out2.write(s1.getBytes("ISO-8859-1")); out2.write(s1.getBytes(Consts.ISO_8859_1));
out2.write(("\r\n" + out2.write(("\r\n" +
"--foo\r\n" + "--foo\r\n" +
"Content-Disposition: form-data; name=\"field2\"\r\n" + "Content-Disposition: form-data; name=\"field2\"\r\n" +
"Content-Type: text/plain; charset=KOI8-R\r\n" + "Content-Type: text/plain; charset=KOI8-R\r\n" +
"Content-Transfer-Encoding: 8bit\r\n" + "Content-Transfer-Encoding: 8bit\r\n" +
"\r\n").getBytes("US-ASCII")); "\r\n").getBytes(Consts.ASCII));
out2.write(s2.getBytes("KOI8-R")); out2.write(s2.getBytes(Charset.forName("KOI8-R")));
out2.write(("\r\n" + out2.write(("\r\n" +
"--foo--\r\n").getBytes("US-ASCII")); "--foo--\r\n").getBytes(Consts.ASCII));
out2.close(); out2.close();
final byte[] actual = out1.toByteArray(); final byte[] actual = out1.toByteArray();