Skip to content

Commit

Permalink
Simple CreateTorrent test with progress.
Browse files Browse the repository at this point in the history
  • Loading branch information
aldenml committed Feb 27, 2015
1 parent a60fa51 commit 0d0cd8a
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/com/frostwire/jlibtorrent/Session.java
Original file line number Diff line number Diff line change
Expand Up @@ -754,6 +754,10 @@ public SessionStats getStats() {
return new SessionStats(lastStatsValues, lastDHTNodes);
}

public void setPieceHashes(String id, create_torrent t, String p, error_code ec) {
s.set_piece_hashes_with_progress(id, t, p, ec);
}

@Override
protected void finalize() throws Throwable {
this.running = false;
Expand Down
57 changes: 57 additions & 0 deletions src/com/frostwire/jlibtorrent/demo/CreateTorrentTest2.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package com.frostwire.jlibtorrent.demo;

import com.frostwire.jlibtorrent.AlertListener;
import com.frostwire.jlibtorrent.Session;
import com.frostwire.jlibtorrent.alerts.Alert;
import com.frostwire.jlibtorrent.alerts.SetPieceHashesAlert;
import com.frostwire.jlibtorrent.swig.*;

/**
* @author gubatron
* @author aldenml
*/
public final class CreateTorrentTest2 {

public static void main(String[] args) throws Throwable {
final Session s = new Session();

s.addListener(new AlertListener() {
@Override
public int[] types() {
return null;
}

@Override
public void alert(Alert<?> alert) {

if (alert instanceof SetPieceHashesAlert) {
System.out.println(alert);
}
}
});

file_storage fs = new file_storage();

// recursively adds files in directories
libtorrent.add_files(fs, "/Users/aldenml/Downloads/Kellee");

create_torrent t = new create_torrent(fs);
t.add_tracker("http://my.tracker.com/announce");
t.set_creator("libtorrent example");

error_code ec = new error_code();
// reads the files and calculates the hashes
s.setPieceHashes("test", t, "/Users/aldenml/Downloads", ec);

if (ec.value() != 0) {
System.out.println(ec.message());
}

entry e = t.generate();

System.out.println(e.to_string());

System.out.println("Press ENTER to exit");
System.in.read();
}
}

0 comments on commit 0d0cd8a

Please sign in to comment.