Beispiel #1
0
 @Override
 public String toString() {
   return "MetaInfo[info_hash='"
       + I2PSnarkUtil.toHex(info_hash)
       + "', announce='"
       + announce
       + "', name='"
       + name
       + "', files="
       + files
       + ", #pieces='"
       + piece_hashes.length / 20
       + "', piece_length='"
       + piece_length
       + "', length='"
       + length
       + "']";
 }
Beispiel #2
0
 private byte[] calculateInfoHash() {
   Map<String, BEValue> info = createInfoMap();
   if (_log.shouldLog(Log.DEBUG)) {
     StringBuilder buf = new StringBuilder(128);
     buf.append("info: ");
     for (Map.Entry<String, BEValue> entry : info.entrySet()) {
       String key = entry.getKey();
       Object val = entry.getValue();
       buf.append(key).append('=');
       buf.append(val.toString());
     }
     _log.debug(buf.toString());
   }
   byte[] infoBytes = BEncoder.bencode(info);
   // _log.debug("info bencoded: [" + Base64.encode(infoBytes, true) + "]");
   MessageDigest digest = SHA1.getInstance();
   byte hash[] = digest.digest(infoBytes);
   if (_log.shouldLog(Log.DEBUG)) _log.debug("info hash: " + I2PSnarkUtil.toHex(hash));
   return hash;
 }
Beispiel #3
0
 /** @since 0.8.5 */
 public static void main(String[] args) {
   if (args.length <= 0) {
     System.err.println("Usage: MetaInfo files...");
     return;
   }
   for (int i = 0; i < args.length; i++) {
     InputStream in = null;
     try {
       in = new FileInputStream(args[i]);
       MetaInfo meta = new MetaInfo(in);
       System.out.println(args[i] + " InfoHash: " + I2PSnarkUtil.toHex(meta.getInfoHash()));
     } catch (IOException ioe) {
       System.err.println("Error in file " + args[i] + ": " + ioe);
     } finally {
       try {
         if (in != null) in.close();
       } catch (IOException ioe) {
       }
     }
   }
 }