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

📄 totorrentdeserialiseimpl.java

📁 java 文件下载器。可自定义
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
						}

						if (!announce_url_found && announce_url != null && announce_url.length() > 0)
							try
							{
								Vector urls = new Vector();
								urls.add(new URL(StringInterner.intern(announce_url)));
								URL url_array[] = new URL[urls.size()];
								urls.copyInto(url_array);
								addTorrentAnnounceURLSet(url_array);
							}
							catch (Exception e)
							{
								Debug.printStackTrace(e);
							}
					}
				} else
				if (key.equalsIgnoreCase("comment"))
					setComment((byte[])(byte[])meta_data.get("comment"));
				else
				if (key.equalsIgnoreCase("created by"))
					setCreatedBy((byte[])(byte[])meta_data.get("created by"));
				else
				if (key.equalsIgnoreCase("creation date"))
					try
					{
						Long creation_date = (Long)meta_data.get("creation date");
						if (creation_date != null)
							setCreationDate(creation_date.longValue());
					}
					catch (Exception e)
					{
						System.out.println("creation_date extraction fails, ignoring");
					}
				else
				if (!key.equalsIgnoreCase("info"))
				{
					Object prop = meta_data.get(key);
					if (prop instanceof byte[])
						setAdditionalByteArrayProperty(key, (byte[])(byte[])prop);
					else
					if (prop instanceof Long)
						setAdditionalLongProperty(key, (Long)prop);
					else
					if (prop instanceof List)
						setAdditionalListProperty(key, (List)prop);
					else
						setAdditionalMapProperty(key, (Map)prop);
				}
			} while (true);
			if (bad_announce)
				if (got_announce_list)
				{
					TOTorrentAnnounceURLSet sets[] = getAnnounceURLGroup().getAnnounceURLSets();
					if (sets.length > 0)
						setAnnounceURL(sets[0].getAnnounceURLs()[0]);
					else
						throw new TOTorrentException((new StringBuilder()).append("ANNOUNCE_URL malformed ('").append(announce_url).append("' and no usable announce list)").toString(), 6);
				} else
				{
					throw new TOTorrentException((new StringBuilder()).append("ANNOUNCE_URL malformed ('").append(announce_url).append("'").toString(), 6);
				}
			if (!got_announce_list && !got_announce)
				setAnnounceURL(TorrentUtils.getDecentralisedEmptyURL());
			Map info = (Map)meta_data.get("info");
			if (info == null)
				throw new TOTorrentException("Decode fails, 'info' element not found'", 6);
			setName((byte[])(byte[])info.get("name"));
			long piece_length = ((Long)info.get("piece length")).longValue();
			if (piece_length <= 0L)
				throw new TOTorrentException("Decode fails, piece-length is invalid", 6);
			setPieceLength(piece_length);
			setHashFromInfo(info);
			Long simple_file_length = (Long)info.get("length");
			long total_length = 0L;
			if (simple_file_length != null)
			{
				setSimpleTorrent(true);
				total_length = simple_file_length.longValue();
				setFiles(new TOTorrentFileImpl[] {
					new TOTorrentFileImpl(this, 0L, total_length, new byte[][] {
						getName()
					})
				});
			} else
			{
				setSimpleTorrent(false);
				List meta_files = (List)info.get("files");
				TOTorrentFileImpl files[] = new TOTorrentFileImpl[meta_files.size()];
label0:
				for (int i = 0; i < files.length; i++)
				{
					Map file_map = (Map)meta_files.get(i);
					long len = ((Long)file_map.get("length")).longValue();
					List paths = (List)file_map.get("path");
					byte path_comps[][] = new byte[paths.size()][];
					for (int j = 0; j < paths.size(); j++)
						path_comps[j] = (byte[])(byte[])paths.get(j);

					TOTorrentFileImpl file = files[i] = new TOTorrentFileImpl(this, total_length, len, path_comps);
					total_length += len;
					Iterator file_it = file_map.keySet().iterator();
					do
					{
						if (!file_it.hasNext())
							continue label0;
						String key = (String)file_it.next();
						if (!key.equals("length") && !key.equals("path"))
							file.setAdditionalProperty(key, file_map.get(key));
					} while (true);
				}

				setFiles(files);
			}
			byte flat_pieces[] = (byte[])(byte[])info.get("pieces");
			int pieces_required = (int)((total_length + (piece_length - 1L)) / piece_length);
			int pieces_supplied = flat_pieces.length / 20;
			if (pieces_supplied < pieces_required)
				throw new TOTorrentException("Decode fails, insufficient pieces supplied", 6);
			if (pieces_supplied > pieces_required)
				Debug.out((new StringBuilder()).append("Torrent '").append(new String(getName())).append("' has too many pieces (required=").append(pieces_required).append(",supplied=").append(pieces_supplied).append(") - ignoring excess").toString());
			byte pieces[][] = new byte[pieces_supplied][20];
			for (int i = 0; i < pieces.length; i++)
				System.arraycopy(flat_pieces, i * 20, pieces[i], 0, 20);

			setPieces(pieces);
			Iterator info_it = info.keySet().iterator();
			do
			{
				if (!info_it.hasNext())
					break;
				String key = (String)info_it.next();
				if (!key.equals("name") && !key.equals("length") && !key.equals("files") && !key.equals("piece length") && !key.equals("pieces"))
					addAdditionalInfoProperty(key, info.get(key));
			} while (true);
			try
			{
				byte ho[] = (byte[])(byte[])info.get("hash-override");
				if (ho != null)
					setHashOverride(ho);
			}
			catch (Throwable e)
			{
				Debug.printStackTrace(e);
			}
		}
		catch (Throwable e)
		{
			if (e instanceof TOTorrentException)
				throw (TOTorrentException)e;
			else
				throw new TOTorrentException((new StringBuilder()).append("Torrent decode fails '").append(Debug.getNestedExceptionMessageAndStack(e)).append("'").toString(), 6, e);
		}
	}

	public void printMap()
	{
		try
		{
			print("", "root", serialiseToMap());
		}
		catch (TOTorrentException e)
		{
			Debug.printStackTrace(e);
		}
	}

	protected void print(String indent, String name, Map map)
	{
		System.out.println((new StringBuilder()).append(indent).append(name).append("{map}").toString());
		for (Iterator it = map.keySet().iterator(); it.hasNext();)
		{
			String key = (String)it.next();
			Object value = map.get(key);
			if (value instanceof Map)
				print((new StringBuilder()).append(indent).append("  ").toString(), key, (Map)value);
			else
			if (value instanceof List)
				print((new StringBuilder()).append(indent).append("  ").toString(), key, (List)value);
			else
			if (value instanceof Long)
				print((new StringBuilder()).append(indent).append("  ").toString(), key, (Long)value);
			else
				print((new StringBuilder()).append(indent).append("  ").toString(), key, (byte[])(byte[])value);
		}

	}

	protected void print(String indent, String name, List list)
	{
		System.out.println((new StringBuilder()).append(indent).append(name).append("{list}").toString());
		Iterator it = list.iterator();
		for (int index = 0; it.hasNext(); index++)
		{
			Object value = it.next();
			if (value instanceof Map)
			{
				print((new StringBuilder()).append(indent).append("  ").toString(), (new StringBuilder()).append("[").append(index).append("]").toString(), (Map)value);
				continue;
			}
			if (value instanceof List)
			{
				print((new StringBuilder()).append(indent).append("  ").toString(), (new StringBuilder()).append("[").append(index).append("]").toString(), (List)value);
				continue;
			}
			if (value instanceof Long)
				print((new StringBuilder()).append(indent).append("  ").toString(), (new StringBuilder()).append("[").append(index).append("]").toString(), (Long)value);
			else
				print((new StringBuilder()).append(indent).append("  ").toString(), (new StringBuilder()).append("[").append(index).append("]").toString(), (byte[])(byte[])value);
		}

	}

	protected void print(String indent, String name, Long value)
	{
		System.out.println((new StringBuilder()).append(indent).append(name).append("{long} = ").append(value.longValue()).toString());
	}

	protected void print(String indent, String name, byte value[])
	{
		String x = new String(value);
		boolean print = true;
		int i = 0;
		do
		{
			if (i >= x.length())
				break;
			char c = x.charAt(i);
			if (c >= '\200')
			{
				print = false;
				break;
			}
			i++;
		} while (true);
		if (print)
			System.out.println((new StringBuilder()).append(indent).append(name).append("{byte[]} = ").append(x).toString());
		else
			System.out.println((new StringBuilder()).append(indent).append(name).append("{byte[], length ").append(value.length).append("}").toString());
	}
}

⌨️ 快捷键说明

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