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

📄 shareresourceimpl.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:   ShareResourceImpl.java

package org.gudy.azureus2.pluginsimpl.local.sharing;

import java.io.File;
import java.util.*;
import org.gudy.azureus2.core3.internat.MessageText;
import org.gudy.azureus2.core3.util.*;
import org.gudy.azureus2.plugins.sharing.*;
import org.gudy.azureus2.plugins.torrent.TorrentAttribute;
import org.gudy.azureus2.pluginsimpl.local.torrent.TorrentManagerImpl;

// Referenced classes of package org.gudy.azureus2.pluginsimpl.local.sharing:
//			ShareConfigImpl, ShareManagerImpl, ShareItemImpl

public abstract class ShareResourceImpl
	implements ShareResource
{

	protected static BrokenMd5Hasher hasher = new BrokenMd5Hasher();
	protected ShareManagerImpl manager;
	protected int type;
	protected ShareResourceDirContents parent;
	protected Map attributes;
	protected List change_listeners;
	protected List deletion_listeners;

	protected ShareResourceImpl(ShareManagerImpl _manager, int _type)
	{
		attributes = new HashMap();
		change_listeners = new ArrayList();
		deletion_listeners = new ArrayList();
		manager = _manager;
		type = _type;
	}

	protected ShareResourceImpl(ShareManagerImpl _manager, int _type, Map _map)
	{
		attributes = new HashMap();
		change_listeners = new ArrayList();
		deletion_listeners = new ArrayList();
		manager = _manager;
		type = _type;
		Map attrs = (Map)_map.get("attributes");
		if (attrs != null)
		{
			for (Iterator keys = attrs.keySet().iterator(); keys.hasNext();)
			{
				String key = (String)keys.next();
				try
				{
					String value = new String((byte[])(byte[])attrs.get(key), "UTF8");
					TorrentAttribute ta = TorrentManagerImpl.getSingleton().getAttribute(key);
					if (ta == null)
						Debug.out((new StringBuilder()).append("Invalid attribute '").append(key).toString());
					else
						attributes.put(ta, value);
				}
				catch (Throwable e)
				{
					Debug.printStackTrace(e);
				}
			}

		}
	}

	protected void serialiseResource(Map map)
	{
		Iterator it = attributes.keySet().iterator();
		Map attrs = new HashMap();
		map.put("attributes", attrs);
		do
		{
			if (!it.hasNext())
				break;
			TorrentAttribute ta = (TorrentAttribute)it.next();
			String value = (String)attributes.get(ta);
			try
			{
				if (value != null)
					attrs.put(ta.getName(), value.getBytes("UTF8"));
			}
			catch (Throwable e)
			{
				Debug.printStackTrace(e);
			}
		} while (true);
	}

	public ShareResourceDirContents getParent()
	{
		return parent;
	}

	protected void setParent(ShareResourceDirContents _parent)
	{
		parent = _parent;
	}

	public ShareResource[] getChildren()
	{
		return new ShareResource[0];
	}

	public int getType()
	{
		return type;
	}

	public void setAttribute(final TorrentAttribute attribute, String value)
	{
		ShareConfigImpl config = manager.getShareConfig();
		String old_value;
		config.suspendSaving();
		ShareResource kids[] = getChildren();
		for (int i = 0; i < kids.length; i++)
			kids[i].setAttribute(attribute, value);

		old_value = (String)attributes.get(attribute);
		if (old_value == null && value == null)
		{
			try
			{
				config.resumeSaving();
			}
			catch (ShareException e)
			{
				Debug.printStackTrace(e);
			}
			return;
		}
		if (old_value != null && value != null && old_value.equals(value))
		{
			try
			{
				config.resumeSaving();
			}
			catch (ShareException e)
			{
				Debug.printStackTrace(e);
			}
			return;
		}
		attributes.put(attribute, value);
		try
		{
			config.saveConfig();
		}
		catch (ShareException e)
		{
			Debug.printStackTrace(e);
		}
		try
		{
			config.resumeSaving();
		}
		catch (ShareException e)
		{
			Debug.printStackTrace(e);
		}
		break MISSING_BLOCK_LABEL_181;
		Exception exception;
		exception;
		try
		{
			config.resumeSaving();
		}
		catch (ShareException e)
		{
			Debug.printStackTrace(e);
		}
		throw exception;
		for (int i = 0; i < change_listeners.size(); i++)
			try
			{
				((ShareResourceListener)change_listeners.get(i)).shareResourceChanged(this, new ShareResourceEvent() {

					final TorrentAttribute val$attribute;
					final ShareResourceImpl this$0;

					public int getType()
					{
						return 1;
					}

					public Object getData()
					{
						return attribute;
					}

			
			{
				this$0 = ShareResourceImpl.this;
				attribute = torrentattribute;
				super();
			}
				});
			}
			catch (Throwable e)
			{
				Debug.printStackTrace(e);
			}

		return;
	}

	public String getAttribute(TorrentAttribute attribute)
	{
		return (String)attributes.get(attribute);
	}

	public TorrentAttribute[] getAttributes()
	{
		TorrentAttribute res[] = new TorrentAttribute[attributes.size()];
		attributes.keySet().toArray(res);
		return res;
	}

	protected void inheritAttributes(ShareResourceImpl source)
	{
		TorrentAttribute attrs[] = source.getAttributes();
		for (int i = 0; i < attrs.length; i++)
			setAttribute(attrs[i], source.getAttribute(attrs[i]));

	}

	public void delete()
		throws ShareException, ShareResourceDeletionVetoException
	{
		if (getParent() != null)
		{
			throw new ShareResourceDeletionVetoException(MessageText.getString("plugin.sharing.remove.veto"));
		} else
		{
			delete(false);
			return;
		}
	}

	protected void delete(boolean force)
		throws ShareException, ShareResourceDeletionVetoException
	{
		if (!force)
			canBeDeleted();
		manager.delete(this);
	}

	public abstract boolean canBeDeleted()
		throws ShareResourceDeletionVetoException;

	protected abstract void deleteInternal();

	protected byte[] getFingerPrint(File file)
		throws ShareException
	{
		StringBuffer buffer;
		buffer = new StringBuffer();
		getFingerPrintSupport(buffer, file, TorrentUtils.getIgnoreSet());
		return hasher.calculateHash(buffer.toString().getBytes());
		ShareException e;
		e;
		throw e;
		e;
		throw new ShareException("ShareResource::getFingerPrint: fails", e);
	}

	protected void getFingerPrintSupport(StringBuffer buffer, File file, Set ignore_set)
		throws ShareException
	{
		try
		{
			if (file.isFile())
			{
				long mod = file.lastModified();
				long size = file.length();
				String file_name = file.getName();
				if (!ignore_set.contains(file_name.toLowerCase()))
					buffer.append(file_name).append(":").append(mod).append(":").append(size);
			} else
			if (file.isDirectory())
			{
				File dir_file_list[] = file.listFiles();
				List file_list = new ArrayList(Arrays.asList(dir_file_list));
				Collections.sort(file_list);
				for (int i = 0; i < file_list.size(); i++)
				{
					File f = (File)file_list.get(i);
					String file_name = f.getName();
					if (!file_name.equals(".") && !file_name.equals(".."))
					{
						StringBuffer sub_print = new StringBuffer();
						getFingerPrintSupport(sub_print, f, ignore_set);
						if (sub_print.length() > 0)
							buffer.append(":").append(sub_print);
					}
				}

			} else
			{
				throw new ShareException((new StringBuilder()).append("ShareResource::getFingerPrint: '").append(file.toString()).append("' doesn't exist").toString());
			}
		}
		catch (Throwable e)
		{
			if (e instanceof ShareException)
			{
				throw (ShareException)e;
			} else
			{
				Debug.printStackTrace(e);
				throw new ShareException("ShareResource::getFingerPrint: fails", e);
			}
		}
	}

	protected String getNewTorrentLocation()
		throws ShareException
	{
		return manager.getNewTorrentLocation();
	}

	protected void writeTorrent(ShareItemImpl item)
		throws ShareException
	{
		manager.writeTorrent(item);
	}

	protected void readTorrent(ShareItemImpl item)
		throws ShareException
	{
		manager.readTorrent(item);
	}

	protected void deleteTorrent(ShareItemImpl item)
	{
		manager.deleteTorrent(item);
	}

	public File getTorrentFile(ShareItemImpl item)
	{
		return manager.getTorrentFile(item);
	}

	protected abstract void checkConsistency()
		throws ShareException;

	public void addChangeListener(ShareResourceListener l)
	{
		change_listeners.add(l);
	}

	public void removeChangeListener(ShareResourceListener l)
	{
		change_listeners.remove(l);
	}

	public void addDeletionListener(ShareResourceWillBeDeletedListener l)
	{
		deletion_listeners.add(l);
	}

	public void removeDeletionListener(ShareResourceWillBeDeletedListener l)
	{
		deletion_listeners.remove(l);
	}

}

⌨️ 快捷键说明

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