if (doneLoading)
return;
doneLoading = true;
FileInputStream fin = null;
BufferedInputStream bin = null;
makeSpecialCategories();
try {
//open the file
File configFile = FileUtil.getUserFile("categories.config");
fin = new FileInputStream(configFile);
bin = new BufferedInputStream(fin, 8192);
Map map = BDecoder.decode(bin);
List catList = (List) map.get("categories");
for (int i = 0; i < catList.size(); i++) {
Map mCategory = (Map) catList.get(i);
try {
String catName = new String((byte[]) mCategory.get("name"), Constants.DEFAULT_ENCODING);
Long l_maxup = (Long)mCategory.get( "maxup" );
Long l_maxdown = (Long)mCategory.get( "maxdown" );
Map<String,String> attributes = BDecoder.decodeStrings((Map)mCategory.get( "attr" ));
if ( attributes == null ){
attributes = new HashMap<String, String>();
}
if ( catName.equals( UNCAT_NAME )){
catUncategorized.setUploadSpeed(l_maxup==null?0:l_maxup.intValue());
catUncategorized.setDownloadSpeed(l_maxdown==null?0:l_maxdown.intValue());
catUncategorized.setAttributes( attributes );
}else if ( catName.equals( ALL_NAME )){
catAll.setAttributes( attributes );
}else{
categories.put(
catName,
new CategoryImpl(
catName,
l_maxup==null?0:l_maxup.intValue(),
l_maxdown==null?0:l_maxdown.intValue(),
attributes ));
}
}
catch (UnsupportedEncodingException e1) {
//Do nothing and process next.
}
}
}
catch (FileNotFoundException e) {
//Do nothing
}
catch (Exception e) {
Debug.printStackTrace( e );
}
finally {
try {
if (bin != null)
bin.close();
}
catch (Exception e) {}
try {
if (fin != null)
fin.close();