1 18 19 package org.apache.jmeter.protocol.http.util; 20 21 import java.io.UnsupportedEncodingException ; 22 23 import org.apache.jorphan.util.JOrphanUtils; 24 import org.apache.oro.util.Cache; 25 import org.apache.oro.util.CacheLRU; 26 27 32 public class EncoderCache 33 { 34 Cache cache; 35 36 public EncoderCache(int cacheSize) 37 { 38 cache = new CacheLRU(cacheSize); 39 } 40 41 public String getEncoded(String k) 42 { 43 Object encodedValue = cache.getElement(k); 44 if(encodedValue != null) 45 { 46 return (String )encodedValue; 47 } 48 try 49 { 50 encodedValue = JOrphanUtils.encode(k, "utf8"); 51 } 52 catch (UnsupportedEncodingException e) 53 { 54 throw new Error ("Should not happen: "+e.toString()); 57 } 58 cache.addElement(k,encodedValue); 59 return (String )encodedValue; 60 } 61 } 62 | Popular Tags |