private Torrent loadTorrent(String res) {
   ClassLoader cl = this.getClass().getClassLoader();
   InputStream is = cl.getResourceAsStream(res);
   if (is != null) {
     try {
       return plugin_interface.getTorrentManager().createFromBEncodedInputStream(is);
     } catch (Exception e) {
       Logger.info("System: The channel torrent is impossible to create!");
       return null;
     }
   }
   Logger.info("System: The channel torrent created is null");
   return null;
 }
 public Torrent getChannelTorrent(String channelName) {
   try {
     Map genericMap = genericTorrent.writeToMap();
     Map info = (Map) genericMap.get("info");
     info.put("name", channelName.getBytes());
     info.put("name.utf8", channelName.getBytes("UTF-8"));
     genericMap.put("info", info);
     byte[] channelTorrent = plugin_interface.getUtilities().getFormatters().bEncode(genericMap);
     Torrent result = plugin_interface.getTorrentManager().createFromBEncodedData(channelTorrent);
     result.setAnnounceURL(new URL("dht://chat.dht/announce"));
     return result;
   } catch (Exception e) {
     e.printStackTrace();
   }
   return null;
 }
Esempio n. 3
0
  protected void taTest() {
    try {

      final TorrentAttribute ta =
          plugin_interface.getTorrentManager().getAttribute(TorrentAttribute.TA_CATEGORY);

      ta.addTorrentAttributeListener(
          new TorrentAttributeListener() {
            public void event(TorrentAttributeEvent ev) {
              System.out.println("ev: " + ev.getType() + ", " + ev.getData());

              if (ev.getType() == TorrentAttributeEvent.ET_ATTRIBUTE_VALUE_ADDED) {

                if ("plop".equals(ev.getData())) {

                  ta.removeDefinedValue("plop");
                }
              }
            }
          });

      ta.addDefinedValue("wibble");

      plugin_interface
          .getDownloadManager()
          .addListener(
              new DownloadManagerListener() {
                public void downloadAdded(Download download) {
                  try {
                    download.setAttribute(ta, "wibble");

                  } catch (Throwable e) {

                    e.printStackTrace();
                  }
                }

                public void downloadRemoved(Download download) {}
              });

    } catch (Throwable e) {

      e.printStackTrace();
    }
  }