// , TorrentProcessor tp = new TorrentProcessor(); // tp.setCreationDate(System.currentTimeMillis()); // tp.setCreator("jBittorrentAPI 1.0"); // tp.setComment("test"); // URL , - . , . tp.setAnnounceURL(null); // tp.setPieceLength(100); // tp.setEncoding("UTF-8"); // , - tp.setName(torrentSavedTo); // , File checkData = new File(torrentSavedTo); if(checkData.isDirectory()) { // File - tp.addFiles(checkData.listFiles()); } else { // , tp.addFile(checkData); } // , tp.setPieceLength() tp.generatePieceHashes(); // - byte[] generateTorrent = tp.generateTorrent(); File generateTorrentFile = new File(torrentName); try { generateTorrentFile.createNewFile(); } catch(IOException ex) { Logger.getLogger(DownloadTorrent.class.getName()).log(Level.SEVERE, null, ex); } try { DataOutputStream dos = new DataOutputStream(new FileOutputStream(generateTorrentFile)); try { dos.write(generateTorrent); dos.flush(); dos.close(); } catch(IOException ex) { Logger.getLogger(DownloadTorrent.class.getName()).log(Level.SEVERE, null, ex); } } catch(FileNotFoundException ex) { Logger.getLogger(DownloadTorrent.class.getName()).log(Level.SEVERE, null, ex); }
TorrentProcessor.setTorrentData()
, but they are almost the same. // - TorrentProcessor tp = new TorrentProcessor(); TorrentFile tf = tp.getTorrentFile(tp.parseTorrent(torrentPath)); DownloadManager dm = new DownloadManager(tf, Utils.generateID()); // dm.startListening(6882, 6889); dm.startTrackerUpdate(); while(true) { // , if(dm.isComplete()) { break; } try { Thread.sleep(1000); } catch(InterruptedException ex) { Logger.getLogger(DownloadTorrent.class.getName()).log(Level.SEVERE, null, ex); } } // dm.stopTrackerUpdate(); dm.closeTempFiles(); // , ( , TorrentProcessor.setName()) String torrentSavedTo = tp.getTorrentFile(tp.parseTorrent(torrentPath)).saveAs;
// - TorrentProcessor tp = new TorrentProcessor(); TorrentFile tf = tp.getTorrentFile(tp.parseTorrent(torrentPath)); DownloadManager dm = new DownloadManager(tf, Utils.generateID()); // dm.startListening(6882, 6889); dm.startTrackerUpdate(); dm.blockUntilCompletion(); // dm.stopTrackerUpdate(); dm.closeTempFiles(); // , ( , TorrentProcessor.setName()) String torrentSavedTo = tp.getTorrentFile(tp.parseTorrent(torrentPath)).saveAs;
DownloadManager.blockUntilCompletion()
method is called here, which implements the work with peers.this.piece_hash_values_as_hex.get(i)
this very exception works because the size of the ArrayList
is zero here.TorrentProcessor.addFile()
everything is fine. But when adding multiple files using TorrentProcessor.addFiles()
(List array, File, or multiple TorrentProcessor.addFile()
call), the following happens:run:
Contact Tracker. URL source = ***
{interval=3300, complete=6, peers=[B@1c184f4, min interval=60, incomplete=6}
Peer List updated from tracker with 22 peers
Piece completed by 109.62.187.159:35691 : 0 (Total dl = 100.0% )
Task completed
Sharing... Press Ctrl+C to stop client
Sharing... Press Ctrl+C to stop client
java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
Sharing... Press Ctrl+C to stop client
at java.util.LinkedList.entry(LinkedList.java:365)
at java.util.LinkedList.remove(LinkedList.java:357)
at jBittorrentAPI.DownloadManager.optimisticUnchoke(DownloadManager.java:617)
at jBittorrentAPI.DownloadManager.unchokePeers(DownloadManager.java:608)
at jBittorrentAPI.DownloadManager.blockUntilCompletion(DownloadManager.java:171)
at torrentstealer.DownloadTorrent.run(DownloadTorrent.java:32)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
at java.util.concurrent.FutureTask.run(FutureTask.java:138)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:662)
Sharing... Press Ctrl+C to stop client
Sharing... Press Ctrl+C to stop client
Source: https://habr.com/ru/post/117116/
All Articles