📄 maketorrent.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: MakeTorrent.java
package org.gudy.azureus2.ui.console;
import java.io.File;
import java.io.PrintStream;
import java.net.URL;
import java.util.*;
import org.gudy.azureus2.core3.torrent.*;
import org.gudy.azureus2.core3.util.TorrentUtils;
public class MakeTorrent
implements TOTorrentProgressListener
{
private boolean verbose;
private static final String validKeys[] = {
"comment", "announce-list", "target", "force_piece_size_pow2", "verbose"
};
public void reportCurrentTask(String task_description)
{
if (verbose)
System.out.println(task_description);
}
public void reportProgress(int percent_complete)
{
if (verbose)
System.out.print((new StringBuilder()).append("\r").append(percent_complete).append("% ").toString());
}
public MakeTorrent(String file, URL url, Map parameters)
{
File fSrc = new File(file);
String torrentName = (String)parameters.get("target");
if (torrentName == null)
torrentName = (new StringBuilder()).append(file).append(".torrent").toString();
File fDst = new File(torrentName);
if (parameters.get("verbose") != null)
verbose = true;
TOTorrent torrent = null;
String pieceSizeStr = (String)parameters.get("force_piece_size_pow2");
if (pieceSizeStr != null)
try
{
long pieceSize = 1L << Integer.parseInt(pieceSizeStr);
TOTorrentCreator creator = TOTorrentFactory.createFromFileOrDirWithFixedPieceLength(fSrc, url, pieceSize);
creator.addListener(this);
torrent = creator.create();
}
catch (Exception e)
{
e.printStackTrace();
return;
}
else
try
{
TOTorrentCreator creator = TOTorrentFactory.createFromFileOrDirWithComputedPieceLength(fSrc, url);
creator.addListener(this);
torrent = creator.create();
}
catch (Exception e)
{
e.printStackTrace();
return;
}
String comment = (String)parameters.get("comment");
if (comment != null)
torrent.setComment(comment);
String announceList = (String)parameters.get("announce-list");
if (announceList != null)
{
StringTokenizer st = new StringTokenizer(announceList, "|");
List list = new ArrayList();
List urls = new ArrayList();
String _url;
for (; st.hasMoreTokens(); urls.add(_url))
_url = st.nextToken();
list.add(urls);
TorrentUtils.listToAnnounceGroups(list, torrent);
}
try
{
torrent.serialiseToBEncodedFile(fDst);
}
catch (Exception e)
{
e.printStackTrace();
}
}
public static void main(String args[])
{
if (args.length < 2)
{
usage();
System.exit(0);
}
Map parameters = new HashMap();
for (int i = 2; i < args.length; i++)
{
boolean ok = parseParameter(args[i], parameters);
if (!ok)
System.exit(-1);
}
File f = new File(args[1]);
if (!f.exists())
{
System.out.println((new StringBuilder()).append(args[1]).append(" is not a valid file / directory").toString());
System.exit(-1);
}
URL url = null;
try
{
url = new URL(args[0]);
}
catch (Exception e)
{
System.out.println((new StringBuilder()).append(args[0]).append(" is not a valid url").toString());
System.exit(-1);
}
new MakeTorrent(args[1], url, parameters);
}
public static void usage()
{
System.out.println("Usage :");
System.out.println("MakeTorrent <trackerurl> <file|dir> [options]");
System.out.println("Options :");
System.out.println("--comment=<comment> Adds a comment to the torrent");
System.out.println("--force_piece_size_pow2=<pow2> Specifies the piece size to use");
System.out.println("--target=<target file> Specifies a target torrent file");
System.out.println("--verbose Verbose");
System.out.println("--announce-list=url1[|url2|...] Use a list of trackers");
}
public static boolean parseParameter(String parameter, Map parameters)
{
if (parameter == null)
return false;
if (parameter.equalsIgnoreCase("--v") || parameter.equalsIgnoreCase("--verbose"))
parameters.put("verbose", new Integer(1));
if (!parameter.startsWith("--"))
break MISSING_BLOCK_LABEL_233;
String key;
String value;
StringTokenizer st = new StringTokenizer(parameter.substring(2), "=");
key = st.nextToken();
value = "";
for (String sep = ""; st.hasMoreTokens(); sep = "=")
value = (new StringBuilder()).append(value).append(sep).append(st.nextElement()).toString();
boolean valid = false;
int i = 0;
do
{
if (i >= validKeys.length)
break;
if (validKeys[i].equalsIgnoreCase(key))
{
valid = true;
break;
}
i++;
} while (true);
if (valid)
break MISSING_BLOCK_LABEL_193;
System.out.println((new StringBuilder()).append("Invalid parameter : ").append(key).toString());
return false;
parameters.put(key, value);
return true;
Exception e;
e;
System.out.println((new StringBuilder()).append("Cannot parse ").append(parameter).toString());
return false;
System.out.println((new StringBuilder()).append("Cannot parse ").append(parameter).toString());
return false;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -