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

📄 downloadmanagerstateimpl.java

📁 java 文件下载器。可自定义
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
// 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:   DownloadManagerStateImpl.java

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

import com.aelitis.azureus.core.AzureusCore;
import com.aelitis.azureus.core.AzureusCoreFactory;
import com.aelitis.azureus.core.util.*;
import java.io.*;
import java.net.URL;
import java.util.*;
import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream;
import org.gudy.azureus2.core3.category.Category;
import org.gudy.azureus2.core3.category.CategoryManager;
import org.gudy.azureus2.core3.config.COConfigurationManager;
import org.gudy.azureus2.core3.config.ParameterListener;
import org.gudy.azureus2.core3.disk.DiskManagerFactory;
import org.gudy.azureus2.core3.disk.DiskManagerFileInfo;
import org.gudy.azureus2.core3.download.*;
import org.gudy.azureus2.core3.global.GlobalManager;
import org.gudy.azureus2.core3.logging.*;
import org.gudy.azureus2.core3.peer.PEPeerSource;
import org.gudy.azureus2.core3.torrent.*;
import org.gudy.azureus2.core3.tracker.client.TRTrackerAnnouncer;
import org.gudy.azureus2.core3.util.*;

// Referenced classes of package org.gudy.azureus2.core3.download.impl:
//			DownloadManagerDefaultPaths, DownloadManagerImpl

public class DownloadManagerStateImpl
	implements DownloadManagerState, ParameterListener
{
	protected static class CachedStateWrapper extends LogRelation
		implements org.gudy.azureus2.core3.util.TorrentUtils.ExtendedTorrent
	{
		protected class cacheGroup
			implements TOTorrentAnnounceURLGroup
		{
			protected class cacheSet
				implements TOTorrentAnnounceURLSet
			{

				private URL urls[];
				private TOTorrentAnnounceURLSet delegateSet;
				final cacheGroup this$1;

				public URL[] getAnnounceURLs()
				{
					if (announce_group == null && fixup() && delegateSet != null)
						return delegateSet.getAnnounceURLs();
					else
						return urls;
				}

				public void setAnnounceURLs(URL toSet[])
				{
					if (fixup() && delegateSet != null)
						delegateSet.setAnnounceURLs(toSet);
					else
						urls = toSet;
				}



				public cacheSet(URL urls[])
				{
					this$1 = cacheGroup.this;
					super();
					this.urls = urls;
				}
			}


			private TOTorrentAnnounceURLSet sets[];
			final CachedStateWrapper this$0;

			public TOTorrentAnnounceURLSet[] getAnnounceURLSets()
			{
				if (announce_group == null && fixup())
					return delegate.getAnnounceURLGroup().getAnnounceURLSets();
				else
					return sets;
			}

			void fixGroup()
			{
				TOTorrentAnnounceURLSet realSets[] = delegate.getAnnounceURLGroup().getAnnounceURLSets();
				if (realSets.length != sets.length)
				{
					Debug.out("Cached announce group state does not match real state");
				} else
				{
					for (int i = 0; i < realSets.length; i++)
						if (sets[i] instanceof cacheSet)
							((cacheSet)sets[i]).delegateSet = realSets[i];

					sets = null;
				}
			}

			public void setAnnounceURLSets(TOTorrentAnnounceURLSet toSet[])
			{
				if (fixup())
				{
					TOTorrentAnnounceURLSet modToSet[] = new TOTorrentAnnounceURLSet[toSet.length];
					for (int i = 0; i < toSet.length; i++)
					{
						TOTorrentAnnounceURLSet set = toSet[i];
						if (set instanceof cacheSet)
							modToSet[i] = ((cacheSet)set).delegateSet;
						if (modToSet[i] == null)
							modToSet[i] = set;
					}

					delegate.getAnnounceURLGroup().setAnnounceURLSets(modToSet);
				}
			}

			public TOTorrentAnnounceURLSet createAnnounceURLSet(URL urls[])
			{
				if (fixup())
					return delegate.getAnnounceURLGroup().createAnnounceURLSet(urls);
				else
					return null;
			}

			protected cacheGroup(List group)
				throws Exception
			{
				this$0 = CachedStateWrapper.this;
				super();
				sets = new TOTorrentAnnounceURLSet[group.size()];
				for (int i = 0; i < sets.length; i++)
				{
					List set = (List)group.get(i);
					URL urls[] = new URL[set.size()];
					for (int j = 0; j < urls.length; j++)
						urls[j] = StringInterner.internURL(new URL(new String((byte[])(byte[])set.get(j), "UTF-8")));

					sets[i] = new cacheSet(urls);
				}

			}
		}


		private DownloadManagerImpl download_manager;
		private String torrent_file;
		private HashWrapper torrent_hash_wrapper;
		private Map cache;
		private Map cache_attributes;
		private Map cache_azp;
		private volatile org.gudy.azureus2.core3.util.TorrentUtils.ExtendedTorrent delegate;
		private TOTorrentException fixup_failure;
		private boolean discard_pieces;
		private boolean logged_failure;
		private Boolean simple_torrent;
		private long size;
		private URL announce_url;
		private cacheGroup announce_group;
		private volatile boolean discard_fluff;

		protected static Map export(DownloadManagerState dms)
			throws TOTorrentException
		{
			Map cache = new HashMap();
			TOTorrent state = dms.getTorrent();
			cache.put("hash", state.getHash());
			cache.put("name", state.getName());
			cache.put("comment", state.getComment());
			cache.put("createdby", state.getCreatedBy());
			cache.put("size", new Long(state.getSize()));
			cache.put("encoding", state.getAdditionalStringProperty("encoding"));
			cache.put("torrent filename", state.getAdditionalStringProperty("torrent filename"));
			cache.put("attributes", state.getAdditionalMapProperty("attributes"));
			cache.put("azp", state.getAdditionalMapProperty("azureus_properties"));
			try
			{
				cache.put("au", state.getAnnounceURL().toExternalForm());
				cache.put("ag", exportGroup(state.getAnnounceURLGroup()));
			}
			catch (Throwable e) { }
			boolean discard_pieces = dms.isResumeDataComplete();
			TOTorrent t = dms.getTorrent();
			if (t instanceof CachedStateWrapper)
			{
				CachedStateWrapper csw = (CachedStateWrapper)t;
				if (!discard_pieces)
					discard_pieces = csw.peekPieces() == null;
				Boolean simple_torrent = csw.simple_torrent;
				if (simple_torrent != null)
					cache.put("simple", new Long(simple_torrent.booleanValue() ? 1L : 0L));
			}
			cache.put("dp", new Long(discard_pieces ? 1L : 0L));
			return cache;
		}

		protected static List exportGroup(TOTorrentAnnounceURLGroup group)
		{
			TOTorrentAnnounceURLSet sets[] = group.getAnnounceURLSets();
			List result = new ArrayList();
			for (int i = 0; i < sets.length; i++)
			{
				TOTorrentAnnounceURLSet set = sets[i];
				URL urls[] = set.getAnnounceURLs();
				if (urls.length <= 0)
					continue;
				List s = new ArrayList(urls.length);
				for (int j = 0; j < urls.length; j++)
					s.add(urls[j].toExternalForm());

				result.add(s);
			}

			return result;
		}

		protected cacheGroup importGroup(List l)
			throws Exception
		{
			return new cacheGroup(l);
		}

		protected void clearCache()
		{
			cache = null;
		}

		protected boolean fixup()
		{
			if (delegate == null)
				synchronized (this)
				{
					if (delegate == null)
					{
						if (fixup_failure != null)
							throw fixup_failure;
						delegate = loadRealState();
						if (discard_fluff)
							delegate.setDiscardFluff(discard_fluff);
						if (cache != null)
							Debug.out("Cache miss forced fixup");
						cache = null;
						if (cache_attributes != null)
						{
							delegate.setAdditionalMapProperty("attributes", cache_attributes);
							cache_attributes = null;
						}
						if (cache_azp != null)
						{
							delegate.setAdditionalMapProperty("azureus_properties", cache_azp);
							cache_azp = null;
						}
						announce_url = null;
						if (announce_group != null)
						{
							announce_group.fixGroup();
							announce_group = null;
						}
					}
				}
			return true;
			TOTorrentException e;
			e;
			fixup_failure = e;
			if (download_manager != null)
				download_manager.setTorrentInvalid(Debug.getNestedExceptionMessage(e));
			else
			if (!logged_failure)
			{
				logged_failure = true;
				Debug.out((new StringBuilder()).append("Torrent can't be loaded: ").append(Debug.getNestedExceptionMessage(e)).toString());
			}
			return false;
		}

		protected org.gudy.azureus2.core3.util.TorrentUtils.ExtendedTorrent loadRealState()
			throws TOTorrentException
		{
			File saved_file;
			if (!DownloadManagerStateImpl.SUPPRESS_FIXUP_ERRORS && Constants.isCVSVersion() && !Thread.currentThread().isDaemon())
				Debug.out("Premature fixup?");
			saved_file = DownloadManagerStateImpl.getStateFile(torrent_hash_wrapper.getBytes());
			if (!saved_file.exists())
				break MISSING_BLOCK_LABEL_79;
			return TorrentUtils.readDelegateFromFile(saved_file, discard_pieces);
			Throwable e;
			e;
			Debug.out((new StringBuilder()).append("Failed to load download state for ").append(saved_file).toString());
			TOTorrent original_torrent;
			original_torrent = TorrentUtils.readFromFile(new File(torrent_file), true);
			torrent_hash_wrapper = original_torrent.getHashWrapper();
			saved_file = DownloadManagerStateImpl.getStateFile(torrent_hash_wrapper.getBytes());
			if (!saved_file.exists())
				break MISSING_BLOCK_LABEL_155;
			return TorrentUtils.readDelegateFromFile(saved_file, discard_pieces);
			Throwable e;
			e;
			Debug.out((new StringBuilder()).append("Failed to load download state for ").append(saved_file).toString());
			TorrentUtils.copyToFile(original_torrent, saved_file);
			return TorrentUtils.readDelegateFromFile(saved_file, discard_pieces);
		}

		public byte[] getName()
		{
			Map c = cache;
			if (c != null)
			{
				byte name[] = (byte[])(byte[])c.get("name");
				if (name != null)
					return name;
			}
			if (fixup())
				return delegate.getName();
			else
				return (new StringBuilder()).append("Error - ").append(Debug.getNestedExceptionMessage(fixup_failure)).toString().getBytes();
		}

		public boolean isSimpleTorrent()
		{
			if (simple_torrent != null)
				return simple_torrent.booleanValue();
			if (fixup())
			{
				boolean st = delegate.isSimpleTorrent();
				simple_torrent = new Boolean(st);
				return st;
			} else
			{
				return false;
			}
		}

		public byte[] getComment()
		{
			Map c = cache;
			if (c != null)
				return (byte[])(byte[])c.get("comment");
			if (fixup())
				return delegate.getComment();
			else
				return null;
		}

		public void setComment(String comment)
		{
			if (fixup())
				delegate.setComment(comment);
		}

		public long getCreationDate()
		{
			if (fixup())
				return delegate.getCreationDate();
			else
				return 0L;
		}

		public void setCreationDate(long date)
		{
			if (fixup())
				delegate.setCreationDate(date);
		}

		public byte[] getCreatedBy()
		{
			Map c = cache;
			if (c != null)
				return (byte[])(byte[])c.get("createdby");
			if (fixup())
				return delegate.getCreatedBy();
			else
				return null;
		}

		public boolean isCreated()
		{
			if (fixup())
				return delegate.isCreated();
			else
				return false;
		}

		public URL getAnnounceURL()
		{
			if (announce_url != null)
				return announce_url;
			if (fixup())
				return delegate.getAnnounceURL();
			else
				return null;
		}

		public boolean setAnnounceURL(URL url)
		{
			if (fixup())
			{
				return delegate.setAnnounceURL(url);
			} else
			{
				announce_url = url;
				return false;
			}
		}

		public TOTorrentAnnounceURLGroup getAnnounceURLGroup()
		{
			if (announce_group != null)
				return announce_group;
			if (fixup())
				return delegate.getAnnounceURLGroup();
			else
				return null;
		}

		public byte[][] getPieces()
			throws TOTorrentException
		{
			if (fixup())
				return delegate.getPieces();
			else
				throw fixup_failure;
		}

		public void setPieces(byte pieces[][])
			throws TOTorrentException
		{
			if (fixup())
			{
				delegate.setPieces(pieces);
				return;
			} else
			{
				throw fixup_failure;
			}
		}

		public byte[][] peekPieces()
			throws TOTorrentException
		{
			if (fixup())
				return delegate.peekPieces();
			else
				throw fixup_failure;
		}

		public void setDiscardFluff(boolean discard)
		{
			discard_fluff = discard;
			if (delegate != null)
				delegate.setDiscardFluff(discard_fluff);
		}

		public long getPieceLength()
		{
			if (fixup())
				return delegate.getPieceLength();
			else
				return 0L;
		}

		public int getNumberOfPieces()
		{
			if (fixup())
				return delegate.getNumberOfPieces();
			else
				return 0;
		}

		public long getSize()
		{
			if (size > 0L)
				return size;
			if (fixup())
			{
				size = delegate.getSize();
				return size;
			} else
			{
				return 0L;
			}
		}

		public TOTorrentFile[] getFiles()
		{
			if (fixup())
				return delegate.getFiles();
			else
				return new TOTorrentFile[0];
		}

		public byte[] getHash()
			throws TOTorrentException
		{
			return torrent_hash_wrapper.getBytes();
		}

		public HashWrapper getHashWrapper()
			throws TOTorrentException
		{
			return torrent_hash_wrapper;
		}

		public void setHashOverride(byte hash[])
			throws TOTorrentException
		{
			throw new TOTorrentException("Not supported", 8);
		}

		public boolean hasSameHashAs(TOTorrent other)
		{
			byte other_hash[] = other.getHash();
			return Arrays.equals(getHash(), other_hash);
			TOTorrentException e;
			e;
			Debug.printStackTrace(e);
			return false;
		}

		public boolean getPrivate()
		{
			if (fixup())
				return delegate.getPrivate();
			else
				return false;
		}

		public void setPrivate(boolean _private)
			throws TOTorrentException
		{

⌨️ 快捷键说明

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