1 7 package com.sun.corba.se.impl.encoding; 8 9 import java.nio.charset.CharsetDecoder ; 10 import java.nio.charset.CharsetEncoder ; 11 import java.util.Map ; 12 import java.util.WeakHashMap ; 13 14 23 class CodeSetCache 24 { 25 29 private ThreadLocal converterCaches = new ThreadLocal () { 30 public java.lang.Object initialValue() { 31 return new Map [] { new WeakHashMap (), new WeakHashMap () }; 32 } 33 }; 34 35 40 private static final int BTC_CACHE_MAP = 0; 41 42 47 private static final int CTB_CACHE_MAP = 1; 48 49 52 CharsetDecoder getByteToCharConverter(Object key) { 53 Map btcMap = ((Map [])converterCaches.get())[BTC_CACHE_MAP]; 54 55 return (CharsetDecoder )btcMap.get(key); 56 } 57 58 61 CharsetEncoder getCharToByteConverter(Object key) { 62 Map ctbMap = ((Map [])converterCaches.get())[CTB_CACHE_MAP]; 63 64 return (CharsetEncoder )ctbMap.get(key); 65 } 66 67 71 CharsetDecoder setConverter(Object key, CharsetDecoder converter) { 72 Map btcMap = ((Map [])converterCaches.get())[BTC_CACHE_MAP]; 73 74 btcMap.put(key, converter); 75 76 return converter; 77 } 78 79 83 CharsetEncoder setConverter(Object key, CharsetEncoder converter) { 84 85 Map ctbMap = ((Map [])converterCaches.get())[CTB_CACHE_MAP]; 86 87 ctbMap.put(key, converter); 88 89 return converter; 90 } 91 } 92 | Popular Tags |