int test_type= 0;
if ( args.length != 1 ){
usage();
}
if ( args[0].equalsIgnoreCase( "encode" )){
test_type = TT_ENCODE;
}else if ( args[0].equalsIgnoreCase( "decode" )){
test_type = TT_DECODE;
}else if ( args[0].equalsIgnoreCase( "create" )){
test_type = TT_CREATE;
}else{
usage();
}
try{
if ( test_type == TT_ENCODE ){
/*
File f = new File("D:\\az2060-broken.torrent");
TOTorrent torrent = TOTorrentFactory.deserialiseFromBEncodedFile( f );
TOTorrentAnnounceURLSet set = torrent.getAnnounceURLGroup().createAnnounceURLSet(new URL[]{ new URL("http://localhost:6970/announce"), new URL("http://localhost:6969/announce")});
torrent.getAnnounceURLGroup().setAnnounceURLSets( new TOTorrentAnnounceURLSet[]{ set });
torrent.setAdditionalStringProperty( "Wibble", "wobble" );
torrent.print();
torrent.serialiseToBEncodedFile( new File("c:\\temp\\test2.torrent"));
*/
}else if ( test_type == TT_DECODE ){
File f = new File("c:\\temp\\az3008-broken.torrent" );
TOTorrent torrent = TOTorrentFactory.deserialiseFromBEncodedFile( f );
// System.out.println( "\turl group sets = " + torrent.getAnnounceURLGroup().getAnnounceURLSets().length);
torrent.print();
}else if ( test_type == TT_CREATE ){
TOTorrentProgressListener list = new TOTorrentProgressListener()
{
public void
reportProgress(
int p )
{
System.out.println( "" + p );
}
public void
reportCurrentTask(
String task_description )
{
System.out.println( "task = " + task_description );
}
};
boolean do_file = false;
boolean do_fixed = false;
TOTorrent t;
if ( do_fixed ){
if ( do_file ){
TOTorrentCreator c = TOTorrentFactory.createFromFileOrDirWithFixedPieceLength(
new File("c:\\temp\\test.wmf"),
new URL( "http://127.0.0.1:6969/announce" ),
1024*10 );
c.addListener( list );
t = c.create();
}else{
TOTorrentCreator c = TOTorrentFactory.createFromFileOrDirWithFixedPieceLength(
new File("c:\\temp\\scans"),
new URL("http://127.0.0.1:6969/announce" ),
1024*256 );
c.addListener( list );
t = c.create();
}
}else{
if ( do_file ){
TOTorrentCreator c = TOTorrentFactory.createFromFileOrDirWithComputedPieceLength(
new File("c:\\temp\\test.wmf"),
new URL( "http://127.0.0.1:6969/announce" ));
c.addListener( list );
t = c.create();
}else{
TOTorrentCreator c = TOTorrentFactory.createFromFileOrDirWithComputedPieceLength(
new File("c:\\temp\\qqq"),
new URL("http://127.0.0.1:6969/announce" ));
c.addListener( list );
t = c.create();
t.setCreationDate( 12345L );
t.setComment( "poo pee plop mcjock");
}
}
t.print();
t.serialiseToBEncodedFile( new File("c:\\temp\\test.torrent" ));
}
}catch( Throwable e ){
Debug.printStackTrace( e );
}