Ejemplo n.º 1
0
 /**
  * Creates a new MetaInfo from the given BDecoder. The BDecoder must have a complete dictionary
  * describing the torrent.
  */
 private MetaInfo(BDecoder be) throws IOException {
   // Note that evaluation order matters here...
   this(be.bdecodeMap().getMap());
   byte[] origInfohash = be.get_special_map_digest();
   // shouldn't ever happen
   if (!DataHelper.eq(origInfohash, info_hash))
     throw new InvalidBEncodingException("Infohash mismatch, please report");
 }
Ejemplo n.º 2
0
 /**
  * Efficiently returns the name and the 20 byte SHA1 hash of the info dictionary in a torrent file
  * Caller must close stream.
  *
  * @param infoHashOut 20-byte out parameter
  * @since 0.8.5
  */
 public static String getNameAndInfoHash(InputStream in, byte[] infoHashOut) throws IOException {
   BDecoder bd = new BDecoder(in);
   Map<String, BEValue> m = bd.bdecodeMap().getMap();
   BEValue ibev = m.get("info");
   if (ibev == null) throw new InvalidBEncodingException("Missing info map");
   Map<String, BEValue> i = ibev.getMap();
   BEValue rvbev = i.get("name");
   if (rvbev == null) throw new InvalidBEncodingException("Missing name");
   byte[] h = bd.get_special_map_digest();
   System.arraycopy(h, 0, infoHashOut, 0, 20);
   return rvbev.getString();
 }