-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Alejandro,

On 7/29/2011 11:55 AM, Alejandro Henao González wrote:
> public class HTMLEncoder { private static Map mapChar2HTMLEntity;
> 
> private final static char [] characters = { 
> 'á','ú','ó','é','í','ñ','Á','Ú','Ó','É','Í','°','ü' }; private final
> static String[] entities = { 
> "á","ú","ó","é","í","ñ","Á","Ú","Ó","É","Í","°","ü"
>  };
> 
> public HTMLEncoder() { mapChar2HTMLEntity= new HashMap(); int
> longueur = characters.length;
> 
> for (int i = 0; i < longueur; i++) mapChar2HTMLEntity.put(new
> Character(characters[i]), entities[i]); }

So you have Character -> String (entity reference). Your Map is not
synchronized, but it doesn't have to be: you are only calling get() on
it so there shouldn't be any synchronization issues here.

> public String encode(String s) { int longueur = s.length(); final
> StringBuffer sb = new StringBuffer(longueur * 2);

Big buffer every time?

> char ch;
> 
> for (int i =0; i < longueur ; ++i) { ch = s.charAt(i);
> 
> if ((ch >= 63 && ch <= 90) || (ch >= 97 && ch <= 122)) sb.append(ch);
>  else { String ss = (String)mapChar2HTMLEntity.get(new
> Character(ch));

New Character object every time? Mmm. You might want to choose a more
optimized storage system so you don't have to create a new object every
time.

> if(ss==null) sb.append(ch); else sb.append(ss); } } return
> sb.toString(); }

Aside from any other strange issues you are having, you might be wasting
a lot of time (and invoking a lot of GC) by creating a large
StringBuffer for every invocation. You might want some more complicated
logic to determine if you even need to create such a buffer.

Honestly, I don't see much wrong with this class. I don't see any use of
System.gc and I don't see any connection reset. Was there a post that I
missed?

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk43Tr4ACgkQ9CaO5/Lv0PBk4QCglB4MNYVbEvwsqZFwiOYupAUv
J84AnRAnw2o6PwTRiaNnNFc9iyNq0pUS
=UWQu
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org

Reply via email to