⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 categorymanagerimpl.java

📁 java 文件下载器。可自定义
💻 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:   CategoryManagerImpl.java

package org.gudy.azureus2.core3.category.impl;

import java.io.*;
import java.util.*;
import org.gudy.azureus2.core3.category.Category;
import org.gudy.azureus2.core3.category.CategoryManagerListener;
import org.gudy.azureus2.core3.util.*;

// Referenced classes of package org.gudy.azureus2.core3.category.impl:
//			CategoryImpl

public class CategoryManagerImpl
{

	private static final String UNCAT_NAME = "__uncategorised__";
	private static CategoryManagerImpl catMan;
	private static Category catAll = null;
	private static Category catUncategorized = null;
	private static boolean doneLoading = false;
	private static AEMonitor class_mon = new AEMonitor("CategoryManager:class");
	private Map categories;
	private AEMonitor categories_mon;
	private static final int LDT_CATEGORY_ADDED = 1;
	private static final int LDT_CATEGORY_REMOVED = 2;
	private ListenerManager category_listeners;

	protected CategoryManagerImpl()
	{
		categories = new HashMap();
		categories_mon = new AEMonitor("Categories");
		category_listeners = ListenerManager.createManager("CatListenDispatcher", new ListenerManagerDispatcher() {

			final CategoryManagerImpl this$0;

			public void dispatch(Object _listener, int type, Object value)
			{
				CategoryManagerListener target = (CategoryManagerListener)_listener;
				if (type == 1)
					target.categoryAdded((Category)value);
				else
				if (type == 2)
					target.categoryRemoved((Category)value);
			}

			
			{
				this$0 = CategoryManagerImpl.this;
				super();
			}
		});
		loadCategories();
	}

	public void addCategoryManagerListener(CategoryManagerListener l)
	{
		category_listeners.addListener(l);
	}

	public void removeCategoryManagerListener(CategoryManagerListener l)
	{
		category_listeners.removeListener(l);
	}

	public static CategoryManagerImpl getInstance()
	{
		CategoryManagerImpl categorymanagerimpl;
		class_mon.enter();
		if (catMan == null)
			catMan = new CategoryManagerImpl();
		categorymanagerimpl = catMan;
		class_mon.exit();
		return categorymanagerimpl;
		Exception exception;
		exception;
		class_mon.exit();
		throw exception;
	}

	protected void loadCategories()
	{
		FileInputStream fin;
		BufferedInputStream bin;
		if (doneLoading)
			return;
		doneLoading = true;
		fin = null;
		bin = null;
		makeSpecialCategories();
		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[])(byte[])mCategory.get("name"), "UTF8");
				Long l_maxup = (Long)mCategory.get("maxup");
				Long l_maxdown = (Long)mCategory.get("maxdown");
				if (catName.equals("__uncategorised__"))
				{
					catUncategorized.setUploadSpeed(l_maxup != null ? l_maxup.intValue() : 0);
					catUncategorized.setDownloadSpeed(l_maxdown != null ? l_maxdown.intValue() : 0);
				} else
				{
					categories.put(catName, new CategoryImpl(catName, l_maxup != null ? l_maxup.intValue() : 0, l_maxdown != null ? l_maxdown.intValue() : 0));
				}
			}
			catch (UnsupportedEncodingException e1) { }
		}

		Exception e;
		try
		{
			if (bin != null)
				bin.close();
		}
		// Misplaced declaration of an exception variable
		catch (Exception e) { }
		try
		{
			if (fin != null)
				fin.close();
		}
		// Misplaced declaration of an exception variable
		catch (Exception e) { }
		break MISSING_BLOCK_LABEL_384;
		e;
		try
		{
			if (bin != null)
				bin.close();
		}
		// Misplaced declaration of an exception variable
		catch (Exception e) { }
		try
		{
			if (fin != null)
				fin.close();
		}
		// Misplaced declaration of an exception variable
		catch (Exception e) { }
		break MISSING_BLOCK_LABEL_384;
		e;
		Debug.printStackTrace(e);
		try
		{
			if (bin != null)
				bin.close();
		}
		// Misplaced declaration of an exception variable
		catch (Exception e) { }
		try
		{
			if (fin != null)
				fin.close();
		}
		// Misplaced declaration of an exception variable
		catch (Exception e) { }
		break MISSING_BLOCK_LABEL_384;
		Exception exception;
		exception;
		try
		{
			if (bin != null)
				bin.close();
		}
		catch (Exception e) { }
		try
		{
			if (fin != null)
				fin.close();
		}
		catch (Exception e) { }
		throw exception;
	}

	public void saveCategories()
	{
		Map map;
		FileOutputStream fos;
		categories_mon.enter();
		map = new HashMap();
		List list = new ArrayList(categories.size());
		Iterator iter = categories.values().iterator();
		do
		{
			if (!iter.hasNext())
				break;
			Category cat = (Category)iter.next();
			if (cat.getType() == 0)
			{
				Map catMap = new HashMap();
				catMap.put("name", cat.getName());
				catMap.put("maxup", new Long(cat.getUploadSpeed()));
				catMap.put("maxdown", new Long(cat.getDownloadSpeed()));
				list.add(catMap);
			}
		} while (true);
		Map uncat = new HashMap();
		uncat.put("name", "__uncategorised__");
		uncat.put("maxup", new Long(catUncategorized.getUploadSpeed()));
		uncat.put("maxdown", new Long(catUncategorized.getDownloadSpeed()));
		list.add(uncat);
		map.put("categories", list);
		fos = null;
		byte torrentData[] = BEncoder.encode(map);
		File oldFile = FileUtil.getUserFile("categories.config");
		File newFile = FileUtil.getUserFile("categories.config.new");
		fos = new FileOutputStream(newFile);
		fos.write(torrentData);
		fos.flush();
		fos.getFD().sync();
		fos.close();
		fos = null;
		if (!oldFile.exists() || oldFile.delete())
			newFile.renameTo(oldFile);
		Exception e;
		try
		{
			if (fos != null)
				fos.close();
		}
		// Misplaced declaration of an exception variable
		catch (Exception e) { }
		break MISSING_BLOCK_LABEL_406;
		e;
		Debug.printStackTrace(e);
		try
		{
			if (fos != null)
				fos.close();
		}
		// Misplaced declaration of an exception variable
		catch (Exception e) { }
		break MISSING_BLOCK_LABEL_406;
		Exception exception;
		exception;
		try
		{
			if (fos != null)
				fos.close();
		}
		catch (Exception e) { }
		throw exception;
		categories_mon.exit();
		break MISSING_BLOCK_LABEL_428;
		Exception exception1;
		exception1;
		categories_mon.exit();
		throw exception1;
	}

	public Category createCategory(String name)
	{
		makeSpecialCategories();
		Category newCategory = getCategory(name);
		if (newCategory == null)
		{
			newCategory = new CategoryImpl(name, 0, 0);
			categories.put(name, newCategory);
			saveCategories();
			category_listeners.dispatch(1, newCategory);
			return (Category)categories.get(name);
		} else
		{
			return newCategory;
		}
	}

	public void removeCategory(Category category)
	{
		if (categories.containsKey(category.getName()))
		{
			categories.remove(category.getName());
			saveCategories();
			category_listeners.dispatch(2, category);
		}
	}

	public Category[] getCategories()
	{
		if (categories.size() > 0)
			return (Category[])(Category[])categories.values().toArray(new Category[categories.size()]);
		else
			return new Category[0];
	}

	public Category getCategory(String name)
	{
		return (Category)categories.get(name);
	}

	public Category getCategory(int type)
	{
		if (type == 1)
			return catAll;
		if (type == 2)
			return catUncategorized;
		else
			return null;
	}

	private void makeSpecialCategories()
	{
		if (catAll == null)
		{
			catAll = new CategoryImpl("Categories.all", 1);
			categories.put("Categories.all", catAll);
		}
		if (catUncategorized == null)
		{
			catUncategorized = new CategoryImpl("Categories.uncategorized", 2);
			categories.put("Categories.uncategorized", catUncategorized);
		}
	}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -