import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;
+import java.nio.charset.Charset;
import org.apache.catalina.util.Base64;
import org.apache.tools.ant.BuildException;
// Set up an authorization header with our credentials
String input = username + ":" + password;
- String output = Base64.encode(input.getBytes());
+ String output =
+ Base64.encode(input.getBytes(Charset.defaultCharset()));
hconn.setRequestProperty("Authorization",
"Basic " + output);
import java.io.IOException;
+import java.nio.charset.Charset;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.security.Principal;
byte[] buffer;
synchronized (md5Helper) {
- buffer = md5Helper.digest(ipTimeKey.getBytes());
+ buffer = md5Helper.digest(
+ ipTimeKey.getBytes(Charset.defaultCharset()));
}
return currentTime + ":" + md5Encoder.encode(buffer);
request.getRemoteAddr() + ":" + nOnceTime + ":" + key;
byte[] buffer = null;
synchronized (md5Helper) {
- buffer = md5Helper.digest(serverIpTimeKey.getBytes());
+ buffer = md5Helper.digest(
+ serverIpTimeKey.getBytes(Charset.defaultCharset()));
}
String md5ServerIpTimeKey = md5Encoder.encode(buffer);
if (!md5ServerIpTimeKey.equals(md5clientIpTimeKey)) {
byte[] buffer;
synchronized (md5Helper) {
- buffer = md5Helper.digest(a2.getBytes());
+ buffer = md5Helper.digest(a2.getBytes(Charset.defaultCharset()));
}
String md5a2 = md5Encoder.encode(buffer);
import java.io.IOException;
import java.io.UnsupportedEncodingException;
+import java.nio.charset.Charset;
import java.util.EnumSet;
import javax.servlet.RequestDispatcher;
if (enc == null) {
enc = "ISO-8859-1";
}
+ Charset charset = null;
+ try {
+ charset = B2CConverter.getCharset(enc);
+ } catch (UnsupportedEncodingException e1) {
+ log.warn(sm.getString("coyoteAdapter.parsePathParam",
+ enc));
+ }
if (log.isDebugEnabled()) {
log.debug(sm.getString("coyoteAdapter.debug", "uriBC",
String pv = null;
if (pathParamEnd >= 0) {
- try {
- pv = (new String(uriBC.getBuffer(), start + pathParamStart,
- pathParamEnd - pathParamStart, enc));
- } catch (UnsupportedEncodingException e) {
- if (!warnedEncoding) {
- log.warn(sm.getString("coyoteAdapter.parsePathParam",
- enc));
- warnedEncoding = true;
- }
+ if (charset != null) {
+ pv = new String(uriBC.getBuffer(), start + pathParamStart,
+ pathParamEnd - pathParamStart, charset);
}
// Extract path param from decoded request URI
byte[] buf = uriBC.getBuffer();
uriBC.setBytes(buf, start,
end - start - pathParamEnd + semicolon);
} else {
- try {
- pv = (new String(uriBC.getBuffer(), start + pathParamStart,
- (end - start) - pathParamStart, enc));
- } catch (UnsupportedEncodingException e) {
- if (!warnedEncoding) {
- log.warn(sm.getString("coyoteAdapter.parsePathParam",
- enc));
- warnedEncoding = true;
- }
+ if (charset != null) {
+ pv = new String(uriBC.getBuffer(), start + pathParamStart,
+ (end - start) - pathParamStart, charset);
}
uriBC.setEnd(start + semicolon);
}
package org.apache.catalina.ha.backend;
-import java.io.UnsupportedEncodingException;
import java.net.DatagramPacket;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.MulticastSocket;
+import java.nio.charset.Charset;
import org.apache.juli.logging.Log;
import org.apache.juli.logging.LogFactory;
implements Sender {
private static final Log log = LogFactory.getLog(HeartbeatListener.class);
+ private static final Charset US_ASCII = Charset.forName("US-ASCII");
HeartbeatListener config = null;
}
byte[] buf;
- try {
- buf = mess.getBytes("US-ASCII");
- } catch (UnsupportedEncodingException ex) {
- buf = mess.getBytes();
- }
+ buf = mess.getBytes(US_ASCII);
DatagramPacket data = new DatagramPacket(buf, buf.length, group, config.getMultiport());
try {
s.send(data);
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;
+import java.nio.charset.Charset;
import java.security.AccessControlException;
import java.security.AccessController;
import java.security.CodeSource;
private static final org.apache.juli.logging.Log log=
org.apache.juli.logging.LogFactory.getLog( WebappClassLoader.class );
+ private static final Charset CHARSET_UTF8 = Charset.forName("UTF-8");
/**
* List of ThreadGroup names to ignore when scanning for web application
* started threads that need to be shut down.
// http://svn.apache.org/viewvc?view=revision&revision=303915
String str = new String(binaryContent,0,pos);
try {
- binaryContent = str.getBytes("UTF-8");
+ binaryContent = str.getBytes(CHARSET_UTF8);
} catch (Exception e) {
return null;
}
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
+import java.nio.charset.Charset;
import java.security.Principal;
import java.text.MessageFormat;
import java.util.ArrayList;
synchronized (this) {
password = password.substring(5);
md.reset();
- md.update(credentials.getBytes());
+ md.update(credentials.getBytes(Charset.defaultCharset()));
String digestedPassword = Base64.encode(md.digest());
validated = password.equals(digestedPassword);
}
password = password.substring(6);
md.reset();
- md.update(credentials.getBytes());
+ md.update(credentials.getBytes(Charset.defaultCharset()));
// Decode stored password.
ByteChunk pwbc = new ByteChunk(password.length());
try {
- pwbc.append(password.getBytes(), 0, password.length());
+ pwbc.append(password.getBytes(Charset.defaultCharset()),
+ 0, password.length());
} catch (IOException e) {
// Should never happen
containerLog.error("Could not append password bytes to chunk: ", e);
import java.beans.PropertyChangeSupport;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
+import java.nio.charset.Charset;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.security.Principal;
import org.apache.catalina.util.MD5Encoder;
import org.apache.juli.logging.Log;
import org.apache.juli.logging.LogFactory;
+import org.apache.tomcat.util.buf.B2CConverter;
import org.apache.tomcat.util.buf.HexUtils;
import org.apache.tomcat.util.res.StringManager;
import org.ietf.jgss.GSSContext;
digestEncoding = charset;
}
+ protected Charset getDigestCharset() throws UnsupportedEncodingException {
+ if (digestEncoding == null) {
+ return Charset.defaultCharset();
+ } else {
+ return B2CConverter.getCharset(getDigestEncoding());
+ }
+ }
+
/**
* Return descriptive information about this Realm implementation and
* the corresponding version number, in the format
}
byte[] valueBytes = null;
- if(getDigestEncoding() == null) {
- valueBytes = serverDigestValue.getBytes();
- } else {
- try {
- valueBytes = serverDigestValue.getBytes(getDigestEncoding());
- } catch (UnsupportedEncodingException uee) {
- log.error("Illegal digestEncoding: " + getDigestEncoding(), uee);
- throw new IllegalArgumentException(uee.getMessage());
- }
+ try {
+ valueBytes = serverDigestValue.getBytes(getDigestCharset());
+ } catch (UnsupportedEncodingException uee) {
+ log.error("Illegal digestEncoding: " + getDigestEncoding(), uee);
+ throw new IllegalArgumentException(uee.getMessage());
}
String serverDigest = null;
md.reset();
byte[] bytes = null;
- if(getDigestEncoding() == null) {
- bytes = credentials.getBytes();
- } else {
- try {
- bytes = credentials.getBytes(getDigestEncoding());
- } catch (UnsupportedEncodingException uee) {
- log.error("Illegal digestEncoding: " + getDigestEncoding(), uee);
- throw new IllegalArgumentException(uee.getMessage());
- }
+ try {
+ bytes = credentials.getBytes(getDigestCharset());
+ } catch (UnsupportedEncodingException uee) {
+ log.error("Illegal digestEncoding: " + getDigestEncoding(), uee);
+ throw new IllegalArgumentException(uee.getMessage());
}
md.update(bytes);
+ getPassword(username);
byte[] valueBytes = null;
- if(getDigestEncoding() == null) {
- valueBytes = digestValue.getBytes();
- } else {
- try {
- valueBytes = digestValue.getBytes(getDigestEncoding());
- } catch (UnsupportedEncodingException uee) {
- log.error("Illegal digestEncoding: " + getDigestEncoding(), uee);
- throw new IllegalArgumentException(uee.getMessage());
- }
+ try {
+ valueBytes = digestValue.getBytes(getDigestCharset());
+ } catch (UnsupportedEncodingException uee) {
+ log.error("Illegal digestEncoding: " + getDigestEncoding(), uee);
+ throw new IllegalArgumentException(uee.getMessage());
}
byte[] digest = null;
import java.io.StringReader;
import java.io.StringWriter;
import java.io.Writer;
+import java.nio.charset.Charset;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.text.SimpleDateFormat;
+ lock.depth + "-" + lock.owner + "-" + lock.tokens + "-"
+ lock.expiresAt + "-" + System.currentTimeMillis() + "-"
+ secret;
- String lockToken =
- md5Encoder.encode(md5Helper.digest(lockTokenStr.getBytes()));
+ String lockToken = md5Encoder.encode(md5Helper.digest(
+ lockTokenStr.getBytes(Charset.defaultCharset())));
if ( (exists) && (object instanceof DirContext) &&
(lock.depth == maxDepth) ) {
package org.apache.catalina.tribes.membership;
+import java.nio.charset.Charset;
+
import org.apache.catalina.tribes.util.Arrays;
public static final String Package = "org.apache.catalina.tribes.membership";
public static void main(String[] args) throws Exception {
- System.out.println(Arrays.toString("TRIBES-B".getBytes()));
- System.out.println(Arrays.toString("TRIBES-E".getBytes()));
+ System.out.println(Arrays.toString(
+ "TRIBES-B".getBytes(Charset.defaultCharset())));
+ System.out.println(Arrays.toString(
+ "TRIBES-E".getBytes(Charset.defaultCharset())));
}
}
import java.io.ObjectInput;
import java.io.ObjectOutput;
import java.io.Serializable;
-import java.io.UnsupportedEncodingException;
+import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
/**
* Used to identify the map
*/
- final String chset = "ISO-8859-1";
+ private static final Charset CHARSET_ISO_8859_1 =
+ Charset.forName("ISO-8859-1");
//------------------------------------------------------------------------------
// INSTANCE VARIABLES
this.channel = channel;
this.rpcTimeout = timeout;
- try {
- this.mapname = mapContextName;
- //unique context is more efficient if it is stored as bytes
- this.mapContextName = mapContextName.getBytes(chset);
- } catch (UnsupportedEncodingException x) {
- log.warn("Unable to encode mapContextName[" + mapContextName + "] using getBytes(" + chset +") using default getBytes()", x);
- this.mapContextName = mapContextName.getBytes();
- }
+ this.mapname = mapContextName;
+ //unique context is more efficient if it is stored as bytes
+ this.mapContextName = mapContextName.getBytes(CHARSET_ISO_8859_1);
if ( log.isTraceEnabled() ) log.trace("Created Lazy Map with name:"+mapContextName+", bytes:"+Arrays.toString(this.mapContextName));
//create an rpc channel and add the map as a listener
protected void printMap(String header) {
try {
System.out.println("\nDEBUG MAP:"+header);
- System.out.println("Map["+ new String(mapContextName, chset) + ", Map Size:" + super.size());
+ System.out.println("Map[" +
+ new String(mapContextName, CHARSET_ISO_8859_1) +
+ ", Map Size:" + super.size());
Member[] mbrs = getMapMembers();
for ( int i=0; i<mbrs.length;i++ ) {
System.out.println("Mbr["+(i+1)+"="+mbrs[i].getName());
*/
package org.apache.catalina.tribes.util;
-import java.io.UnsupportedEncodingException;
+import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;
import org.apache.catalina.tribes.group.AbsoluteOrder;
import org.apache.catalina.tribes.membership.MemberImpl;
import org.apache.catalina.tribes.membership.Membership;
-import org.apache.juli.logging.Log;
-import org.apache.juli.logging.LogFactory;
/**
* @author Filip Hanik
* @version 1.0
*/
public class Arrays {
- private static final Log log = LogFactory.getLog(Arrays.class);
+ private static final Charset CHARSET_ISO_8859_1 =
+ Charset.forName("ISO-8859-1");
public static boolean contains(byte[] source, int srcoffset, byte[] key, int keyoffset, int length) {
if ( srcoffset < 0 || srcoffset >= source.length) throw new ArrayIndexOutOfBoundsException("srcoffset is out of bounds.");
public static byte[] convert(String s) {
- try {
- return s.getBytes("ISO-8859-1");
- }catch (UnsupportedEncodingException ux ) {
- log.error("Unable to convert ["+s+"] into a byte[] using ISO-8859-1 encoding, falling back to default encoding.");
- return s.getBytes();
- }
+ return s.getBytes(CHARSET_ISO_8859_1);
}
-
-
}
\ No newline at end of file
package org.apache.catalina.util;
import java.io.UnsupportedEncodingException;
+import java.nio.charset.Charset;
import java.text.SimpleDateFormat;
import java.util.Map;
import java.util.TimeZone;
import org.apache.juli.logging.Log;
import org.apache.juli.logging.LogFactory;
+import org.apache.tomcat.util.buf.B2CConverter;
import org.apache.tomcat.util.res.StringManager;
byte[] bytes = null;
try {
if (encoding == null) {
- bytes = data.getBytes();
+ bytes = data.getBytes(Charset.defaultCharset());
} else {
- bytes = data.getBytes(encoding);
+ bytes = data.getBytes(B2CConverter.getCharset(encoding));
}
parseParameters(map, bytes, encoding);
} catch (UnsupportedEncodingException uee) {
byte[] bytes = null;
try {
if (enc == null) {
- bytes = str.getBytes();
+ bytes = str.getBytes(Charset.defaultCharset());
} else {
- bytes = str.getBytes(enc);
+ bytes = str.getBytes(B2CConverter.getCharset(enc));
}
} catch (UnsupportedEncodingException uee) {
log.debug(sm.getString("requestUtil.urlDecode.uee", enc), uee);
}
if (enc != null) {
try {
- return new String(bytes, 0, ox, enc);
+ return new String(bytes, 0, ox, B2CConverter.getCharset(enc));
} catch (UnsupportedEncodingException uee) {
log.debug(sm.getString("requestUtil.urlDecode.uee", enc), uee);
return null;
public static void parseParameters(Map<String,String[]> map, byte[] data,
String encoding) throws UnsupportedEncodingException {
+ Charset charset = B2CConverter.getCharset(encoding);
+
if (data != null && data.length > 0) {
int ix = 0;
int ox = 0;
byte c = data[ix++];
switch ((char) c) {
case '&':
- value = new String(data, 0, ox, encoding);
+ value = new String(data, 0, ox, charset);
if (key != null) {
putMapEntry(map, key, value);
key = null;
break;
case '=':
if (key == null) {
- key = new String(data, 0, ox, encoding);
+ key = new String(data, 0, ox, charset);
ox = 0;
} else {
data[ox++] = c;
}
//The last value does not end in '&'. So save it now.
if (key != null) {
- value = new String(data, 0, ox, encoding);
+ value = new String(data, 0, ox, charset);
putMapEntry(map, key, value);
}
}
import java.io.ByteArrayInputStream;
import java.io.IOException;
+import java.nio.charset.Charset;
import java.security.NoSuchProviderException;
import java.security.cert.CertificateFactory;
import java.security.cert.X509Certificate;
String strcert4 = strcert3.concat(strcert2);
String strcerts = strcert4.concat("\n-----END CERTIFICATE-----\n");
// ByteArrayInputStream bais = new ByteArrayInputStream(strcerts.getBytes("UTF-8"));
- ByteArrayInputStream bais = new ByteArrayInputStream(strcerts.getBytes());
+ ByteArrayInputStream bais = new ByteArrayInputStream(
+ strcerts.getBytes(Charset.defaultCharset()));
X509Certificate jsseCerts[] = null;
String providerName = (String) request.getConnector().getProperty(
"clientCertProvider");
import java.io.EOFException;
import java.io.IOException;
import java.nio.channels.Selector;
+import java.nio.charset.Charset;
import org.apache.coyote.InputBuffer;
import org.apache.coyote.Request;
private static final org.apache.juli.logging.Log log =
org.apache.juli.logging.LogFactory.getLog(InternalNioInputBuffer.class);
+ private static final Charset DEFAULT_CHARSET =
+ Charset.forName("ISO-8859-1");
+
// -------------------------------------------------------------- Constants
enum HeaderParseStatus {DONE, HAVE_MORE_HEADERS, NEED_MORE_DATA}
parsingRequestLinePhase = 2;
if (log.isDebugEnabled()) {
log.debug("Received ["
- + new String(buf, pos, lastValid - pos, "ISO-8859-1")
+ + new String(buf, pos, lastValid - pos, DEFAULT_CHARSET)
+ "]");
}
}
package org.apache.coyote.http11.filters;
import java.io.IOException;
+import java.nio.charset.Charset;
import org.apache.coyote.InputBuffer;
import org.apache.coyote.Request;
// ----------------------------------------------------- Static Initializer
static {
- ENCODING.setBytes(ENCODING_NAME.getBytes(), 0, ENCODING_NAME.length());
+ ENCODING.setBytes(ENCODING_NAME.getBytes(Charset.defaultCharset()), 0,
+ ENCODING_NAME.length());
}
import java.io.EOFException;
import java.io.IOException;
+import java.nio.charset.Charset;
import org.apache.coyote.InputBuffer;
import org.apache.coyote.Request;
static {
- ENCODING.setBytes(ENCODING_NAME.getBytes(), 0, ENCODING_NAME.length());
+ ENCODING.setBytes(ENCODING_NAME.getBytes(Charset.defaultCharset()), 0,
+ ENCODING_NAME.length());
}
package org.apache.coyote.http11.filters;
import java.io.IOException;
+import java.nio.charset.Charset;
import org.apache.coyote.InputBuffer;
import org.apache.coyote.Request;
static {
- ENCODING.setBytes(ENCODING_NAME.getBytes(), 0, ENCODING_NAME.length());
+ ENCODING.setBytes(ENCODING_NAME.getBytes(Charset.defaultCharset()), 0,
+ ENCODING_NAME.length());
}
package org.apache.coyote.http11.filters;
import java.io.IOException;
+import java.nio.charset.Charset;
import org.apache.coyote.InputBuffer;
import org.apache.coyote.Request;
static {
- ENCODING.setBytes(ENCODING_NAME.getBytes(), 0, ENCODING_NAME.length());
+ ENCODING.setBytes(ENCODING_NAME.getBytes(Charset.defaultCharset()), 0,
+ ENCODING_NAME.length());
}
import java.io.ByteArrayInputStream;
import java.io.CharArrayWriter;
import java.io.InputStream;
-import java.io.UnsupportedEncodingException;
+import java.nio.charset.Charset;
import java.util.ListIterator;
import javax.servlet.jsp.tagext.PageData;
private static final String JSP_VERSION = "2.0";
private static final String CDATA_START_SECTION = "<![CDATA[\n";
private static final String CDATA_END_SECTION = "]]>\n";
+ private static final Charset CHARSET_UTF8 = Charset.forName("UTF-8");
// string buffer used to build XML view
private StringBuilder buf;
*/
@Override
public InputStream getInputStream() {
- // Turn StringBuilder into InputStream
- try {
- return new ByteArrayInputStream(buf.toString().getBytes("UTF-8"));
- } catch (UnsupportedEncodingException uee) {
- // should never happen
- throw new RuntimeException(uee.toString());
- }
+ return new ByteArrayInputStream(buf.toString().getBytes(CHARSET_UTF8));
}
/*
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
+import java.nio.charset.Charset;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
for (int i = 0; i < smap.length; i += 2) {
File outServlet = new File(smap[i]);
- SDEInstaller.install(outServlet, smap[i+1].getBytes());
+ SDEInstaller.install(outServlet,
+ smap[i+1].getBytes(Charset.defaultCharset()));
}
}
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
+import java.nio.charset.Charset;
import java.util.Hashtable;
import javax.naming.Binding;
return object;
} else {
return new Resource(new ByteArrayInputStream
- (object.toString().getBytes()));
+ (object.toString().getBytes(Charset.defaultCharset())));
}
}
entry.resource = (Resource) object;
} else {
entry.resource = new Resource(new ByteArrayInputStream
- (object.toString().getBytes()));
+ (object.toString().getBytes(Charset.defaultCharset())));
}
Attributes attributes = dirContext.getAttributes(parseName(name));
if (!(attributes instanceof ResourceAttributes)) {
entry.resource = (Resource) object;
} else {
entry.resource = new Resource(new ByteArrayInputStream
- (object.toString().getBytes()));
+ (object.toString().getBytes(Charset.defaultCharset())));
}
} catch (NamingException e) {
exists = false;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
+import java.nio.charset.Charset;
+import java.nio.charset.IllegalCharsetNameException;
+import java.nio.charset.UnsupportedCharsetException;
+import java.util.concurrent.ConcurrentHashMap;
/** Efficient conversion of bytes to character .
*
private static final org.apache.juli.logging.Log log=
org.apache.juli.logging.LogFactory.getLog( B2CConverter.class );
+ private static final ConcurrentHashMap<String, Charset> encodingToCharsetCache =
+ new ConcurrentHashMap<String, Charset>();
+
+ public static Charset getCharset(String enc)
+ throws UnsupportedEncodingException{
+
+ Charset charset = encodingToCharsetCache.get(enc);
+ if (charset == null) {
+ try {
+ charset = Charset.forName(enc);
+ } catch (IllegalCharsetNameException icne) {
+ UnsupportedEncodingException uee =
+ new UnsupportedEncodingException();
+ uee.initCause(icne);
+ throw uee;
+ } catch (UnsupportedCharsetException uce) {
+ UnsupportedEncodingException uee =
+ new UnsupportedEncodingException();
+ uee.initCause(uce);
+ throw uee;
+ }
+ encodingToCharsetCache.put(enc, charset);
+ }
+ return charset;
+ }
+
private IntermediateInputStream iis;
private ReadConvertor conv;
private String encoding;
{
// destroy the reader/iis
iis=new IntermediateInputStream();
- conv=new ReadConvertor( iis, encoding );
+ conv = new ReadConvertor(iis, getCharset(encoding));
}
}
/** Create a converter.
*/
- public ReadConvertor( IntermediateInputStream in, String enc )
- throws UnsupportedEncodingException
- {
- super( in, enc );
+ public ReadConvertor(IntermediateInputStream in, Charset charset) {
+ super(in, charset);
}
/** Overridden - will do nothing but reset internal state.
public String toStringInternal() {
String strValue=null;
try {
- if( enc==null ) enc=DEFAULT_CHARACTER_ENCODING;
- strValue = new String( buff, start, end-start, enc );
+ if (enc == null) {
+ enc = DEFAULT_CHARACTER_ENCODING;
+ }
+ strValue = new String(buff, start, end-start,
+ B2CConverter.getCharset(enc));
/*
Does not improve the speed too much on most systems,
it's safer to use the "classical" new String().
import java.io.IOException;
import java.io.Serializable;
+import java.nio.charset.Charset;
import java.util.Locale;
/**
}
toString();
type=T_BYTES;
- byte bb[] = strValue.getBytes();
+ byte bb[] = strValue.getBytes(Charset.defaultCharset());
byteC.setBytes(bb, 0, bb.length);
}
package org.apache.tomcat.util.http;
import java.io.IOException;
-import java.io.UnsupportedEncodingException;
+import java.nio.charset.Charset;
import java.util.Enumeration;
import java.util.Hashtable;
private ByteChunk origValue=new ByteChunk();
CharChunk tmpNameC=new CharChunk(1024);
public static final String DEFAULT_ENCODING = "ISO-8859-1";
+ public static final Charset DEFAULT_CHARSET =
+ Charset.forName(DEFAULT_ENCODING);
+
public void processParameters( byte bytes[], int start, int len ) {
processParameters(bytes, start, len, encoding);
int pos=start;
if(log.isDebugEnabled()) {
- try {
- log.debug("Bytes: " +
- new String(bytes, start, len, DEFAULT_ENCODING));
- } catch (UnsupportedEncodingException e) {
- // Should never happen...
- log.error("Unable to convert bytes", e);
- }
+ log.debug("Bytes: " +
+ new String(bytes, start, len, DEFAULT_CHARSET));
}
do {
valStart=nameEnd;
valEnd=nameEnd;
if(log.isDebugEnabled()) {
- try {
- log.debug("no equal " + nameStart + " " + nameEnd + " " +
- new String(bytes, nameStart, nameEnd-nameStart,
- DEFAULT_ENCODING) );
- } catch (UnsupportedEncodingException e) {
- // Should never happen...
- log.error("Unable to convert bytes", e);
- }
+ log.debug("no equal " + nameStart + " " + nameEnd + " " +
+ new String(bytes, nameStart, nameEnd-nameStart,
+ DEFAULT_CHARSET));
}
}
if( nameEnd== -1 )
// No name eg ...&=xx&... will trigger this
if (valEnd >= nameStart) {
msg.append('\'');
- try {
- msg.append(new String(bytes, nameStart,
- valEnd - nameStart, DEFAULT_ENCODING));
- } catch (UnsupportedEncodingException e) {
- // Should never happen...
- log.error("Unable to convert bytes", e);
- }
+ msg.append(new String(bytes, nameStart,
+ valEnd - nameStart, DEFAULT_CHARSET));
msg.append("' ");
}
msg.append("ignored.");
import java.io.IOException;
import java.io.InputStream;
-import java.io.UnsupportedEncodingException;
+import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
// ---------------------------------------------------------- Class methods
+ private static final Charset CHARSET_ISO_8859_1 =
+ Charset.forName("ISO-8859-1");
/**
* <p>Utility method that determines whether the request contains multipart
return null;
}
byte[] boundary;
- try {
- boundary = boundaryStr.getBytes("ISO-8859-1");
- } catch (UnsupportedEncodingException e) {
- boundary = boundaryStr.getBytes();
- }
+ boundary = boundaryStr.getBytes(CHARSET_ISO_8859_1);
return boundary;
}
JSP servlet has been configured via code when embedding Tomcat. (markt)
</fix>
<fix>
+ <bug>51400</bug>: Avoid known bottleneck in JVM when converting between
+ Strings and bytes by always providing a Charset rather than an encoding
+ name. Based on a patch by Dave Engberg. (markt)
+ </fix>
+ <fix>
<bug>51401</bug>: Correctly initialise shared WebRuleSet instance used
by the digesters that parse web.xml and prevent incorrect warnings about
multiple occurrences of elements that are only allowed to appear once in