com.acgist.snail.protocol.torrent.bean.TorrentInfo Maven / Gradle / Ivy
package com.acgist.snail.protocol.torrent.bean;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import com.acgist.snail.system.bencode.BEncodeDecoder;
import com.acgist.snail.utils.StringUtils;
/**
* 文件列表信息:单文件时files为空
*
* @author acgist
* @since 1.0.0
*/
public class TorrentInfo {
/**
* 每个Piece的HASH字节数
*/
public static final int PIECE_HASH_LENGTH = 20;
private String name; // 名称
private String nameUtf8; // 名称:utf8
private Long length; // 大小
private byte[] ed2k; // ed2k
private byte[] filehash; // 文件hash
private byte[] pieces; // 特征信息:每个piece的hash值占用20个字节
private Long pieceLength; // 每个块大小
private String publisher; // 发布者
private String publisherUtf8; // 发布者UTF8
private String publisherUrl; // 发布者URL
private String publisherUrlUtf8; // 发布者URL UTF8
private List files; // 多文件时存在
protected TorrentInfo() {
}
public static final TorrentInfo valueOf(Map map) {
if(map == null) {
return null;
}
final TorrentInfo info = new TorrentInfo();
info.setName(BEncodeDecoder.getString(map, "name"));
info.setNameUtf8(BEncodeDecoder.getString(map, "name.utf-8"));
info.setLength(BEncodeDecoder.getLong(map, "length"));
info.setEd2k(BEncodeDecoder.getBytes(map, "ed2k"));
info.setFilehash(BEncodeDecoder.getBytes(map, "filehash"));
info.setPieces(BEncodeDecoder.getBytes(map, "pieces"));
info.setPieceLength(BEncodeDecoder.getLong(map, "piece length"));
info.setPublisher(BEncodeDecoder.getString(map, "publisher"));
info.setPublisherUtf8(BEncodeDecoder.getString(map, "publisher.utf-8"));
info.setPublisherUrl(BEncodeDecoder.getString(map, "publisher-url"));
info.setPublisherUrlUtf8(BEncodeDecoder.getString(map, "publisher-url.utf-8"));
final List