📄 integratedresourcebundle.java
字号:
// Decompiled by Jad v1.5.8e2. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://kpdus.tripod.com/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi space
// Source File Name: IntegratedResourceBundle.java
package org.gudy.azureus2.core3.internat;
import java.io.*;
import java.util.*;
import org.gudy.azureus2.core3.util.*;
// Referenced classes of package org.gudy.azureus2.core3.internat:
// MessageText
public class IntegratedResourceBundle extends ResourceBundle
{
private static final boolean DEBUG = false;
private static final Object NULL_OBJECT = new Object();
private static final Map bundle_map = new WeakHashMap();
private static TimerEventPeriodic compact_timer;
private Locale locale;
private Map messages;
private Map used_messages;
private List null_values;
private int clean_count;
private boolean one_off_discard_done;
private File scratch_file;
protected static void resetCompactTimer()
{
synchronized (bundle_map)
{
if (compact_timer == null && System.getProperty("transitory.startup", "0").equals("0"))
compact_timer = SimpleTimer.addPeriodicEvent("IRB:compactor", 60000L, new TimerEventPerformer() {
public void perform(TimerEvent event)
{
synchronized (IntegratedResourceBundle.bundle_map)
{
Iterator it = IntegratedResourceBundle.bundle_map.keySet().iterator();
boolean did_something = false;
do
{
if (!it.hasNext())
break;
IntegratedResourceBundle rb = (IntegratedResourceBundle)it.next();
if (rb.compact())
did_something = true;
} while (true);
if (!did_something)
{
IntegratedResourceBundle.compact_timer.cancel();
IntegratedResourceBundle.compact_timer = null;
}
}
}
});
}
}
public IntegratedResourceBundle(ResourceBundle main, Map localizationPaths)
{
this(main, localizationPaths, null);
}
public IntegratedResourceBundle(ResourceBundle main, Map localizationPaths, Collection resource_bundles)
{
messages = new LightHashMap();
clean_count = 0;
locale = main.getLocale();
addResourceMessages(main);
synchronized (localizationPaths)
{
String localizationPath;
ClassLoader classLoader;
for (Iterator iter = localizationPaths.keySet().iterator(); iter.hasNext(); addPluginBundle(localizationPath, classLoader))
{
localizationPath = (String)iter.next();
classLoader = (ClassLoader)localizationPaths.get(localizationPath);
}
}
if (resource_bundles != null)
synchronized (resource_bundles)
{
for (Iterator itr = resource_bundles.iterator(); itr.hasNext(); addResourceMessages((ResourceBundle)itr.next()));
}
used_messages = new LightHashMap(messages.size());
synchronized (bundle_map)
{
bundle_map.put(this, NULL_OBJECT);
resetCompactTimer();
}
}
public Locale getLocale()
{
return locale;
}
private Map getMessages()
{
return loadMessages();
}
public Enumeration getKeys()
{
(new Exception("Don't call me, call getKeysLight")).printStackTrace();
Map m = loadMessages();
return (new Vector(m.keySet())).elements();
}
protected Iterator getKeysLight()
{
Map m = new LightHashMap(loadMessages());
return m.keySet().iterator();
}
public String getString(String key, String def)
{
String s = (String)handleGetObject(key);
if (s == null)
{
if (parent != null)
s = parent.getString(key);
if (s == null)
return def;
}
return s;
}
protected Object handleGetObject(String key)
{
Object res;
synchronized (bundle_map)
{
res = used_messages.get(key);
}
Integer keyHash = null;
if (null_values != null)
{
keyHash = new Integer(key.hashCode());
int index = Collections.binarySearch(null_values, keyHash);
if (index >= 0)
return null;
}
if (res == NULL_OBJECT)
return null;
if (res == null)
synchronized (bundle_map)
{
loadMessages();
if (messages != null)
res = messages.get(key);
if (res == null && null_values != null)
{
int index = Collections.binarySearch(null_values, keyHash);
if (index < 0)
index = -1 * index - 1;
if (index > null_values.size())
index = null_values.size();
null_values.add(index, keyHash);
} else
{
used_messages.put(key, res != null ? res : NULL_OBJECT);
}
clean_count = 0;
resetCompactTimer();
}
return res;
}
public void addPluginBundle(String localizationPath, ClassLoader classLoader)
{
ResourceBundle newResourceBundle = null;
try
{
if (classLoader != null)
newResourceBundle = ResourceBundle.getBundle(localizationPath, locale, classLoader);
else
newResourceBundle = ResourceBundle.getBundle(localizationPath, locale, org/gudy/azureus2/core3/internat/IntegratedResourceBundle.getClassLoader());
}
catch (Exception e)
{
try
{
if (classLoader != null)
newResourceBundle = ResourceBundle.getBundle(localizationPath, MessageText.LOCALE_DEFAULT, classLoader);
else
newResourceBundle = ResourceBundle.getBundle(localizationPath, MessageText.LOCALE_DEFAULT, org/gudy/azureus2/core3/internat/IntegratedResourceBundle.getClassLoader());
}
catch (Exception e2)
{
System.out.println((new StringBuilder()).append(localizationPath).append(": no default resource bundle").toString());
return;
}
}
addResourceMessages(newResourceBundle);
}
public void addResourceMessages(ResourceBundle bundle)
{
synchronized (bundle_map)
{
loadMessages();
if (bundle != null)
if (bundle instanceof IntegratedResourceBundle)
{
messages.putAll(((IntegratedResourceBundle)bundle).getMessages());
} else
{
String key;
for (Enumeration enumeration = bundle.getKeys(); enumeration.hasMoreElements(); messages.put(key, bundle.getObject(key)))
key = (String)enumeration.nextElement();
}
}
}
protected boolean compact()
{
clean_count++;
if (clean_count == 1)
return true;
if (scratch_file == null)
{
File temp_file = null;
FileOutputStream fos = null;
try
{
Properties props = new Properties();
props.putAll(messages);
temp_file = AETemporaryFileHandler.createTempFile();
fos = new FileOutputStream(temp_file);
props.store(fos, "message cache");
fos.close();
fos = null;
scratch_file = temp_file;
}
catch (Throwable e)
{
if (fos != null)
try
{
fos.close();
}
catch (Throwable f) { }
if (temp_file != null)
temp_file.delete();
}
}
if (scratch_file != null)
{
if (clean_count >= 2)
messages = null;
if (clean_count == 5 && !one_off_discard_done)
{
one_off_discard_done = true;
used_messages.clear();
}
}
if (clean_count > 5)
{
Map compact_um = new LightHashMap(used_messages.size() + 16);
compact_um.putAll(used_messages);
used_messages = compact_um;
return false;
} else
{
return true;
}
}
protected Map loadMessages()
{
Map map = bundle_map;
JVM INSTR monitorenter ;
if (messages != null)
return messages;
if (scratch_file != null) goto _L2; else goto _L1
_L1:
new LightHashMap();
map;
JVM INSTR monitorexit ;
return;
_L2:
Properties p;
FileInputStream fis;
p = new Properties();
fis = null;
fis = new FileInputStream(scratch_file);
p.load(fis);
fis.close();
messages = new LightHashMap();
messages.putAll(p);
messages;
map;
JVM INSTR monitorexit ;
return;
Throwable e;
e;
if (fis != null)
try
{
fis.close();
}
catch (Throwable f) { }
Debug.out("Failed to load message bundle scratch file", e);
scratch_file.delete();
scratch_file = null;
new LightHashMap();
map;
JVM INSTR monitorexit ;
return;
Exception exception;
exception;
throw exception;
}
protected String getString()
{
return (new StringBuilder()).append(locale).append(": use=").append(used_messages.size()).append(",map=").append(messages != null ? String.valueOf(messages.size()) : "").append(null_values != null ? (new StringBuilder()).append(",null=").append(null_values.size()).toString() : "").toString();
}
public void addString(String key, String value)
{
messages.put(key, value);
}
public boolean getUseNullList()
{
return null_values != null;
}
public void setUseNullList(boolean useNullList)
{
if (useNullList && null_values == null)
null_values = new ArrayList(0);
else
if (!useNullList && null_values != null)
null_values = null;
}
public void clearUsedMessagesMap(int initialCapacity)
{
used_messages = new LightHashMap(initialCapacity);
if (null_values != null)
null_values = new ArrayList(0);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -