当前位置: 首页>>代码示例>>Java>>正文


Java InvalidBEncodingException类代码示例

本文整理汇总了Java中com.turn.ttorrent.bcodec.InvalidBEncodingException的典型用法代码示例。如果您正苦于以下问题:Java InvalidBEncodingException类的具体用法?Java InvalidBEncodingException怎么用?Java InvalidBEncodingException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


InvalidBEncodingException类属于com.turn.ttorrent.bcodec包,在下文中一共展示了InvalidBEncodingException类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: MockedTorrent

import com.turn.ttorrent.bcodec.InvalidBEncodingException; //导入依赖的package包/类
/**
 * Create a new torrent from meta-info binary data.
 * <p>
 * Parses the meta-info data (which should be B-encoded as described in the
 * BitTorrent specification) and create a Torrent object from it.
 *
 * @param torrent The meta-info byte data.
 * @param seeder  Whether we'll be seeding for this torrent or not.
 * @throws IOException When the info dictionary can't be read or
 *                     encoded and hashed back to create the torrent's SHA-1 hash.
 */
private MockedTorrent(final byte[] torrent, final boolean seeder) throws IOException, NoSuchAlgorithmException {
    super(torrent, seeder);

    try {
        // Torrent validity tests
        final int pieceLength = this.decoded_info.get("piece length").getInt();
        final ByteBuffer piecesHashes = ByteBuffer.wrap(this.decoded_info.get("pieces").getBytes());

        if (piecesHashes.capacity() / Torrent.PIECE_HASH_SIZE * (long) pieceLength < this.getSize()) {
            throw new IllegalArgumentException("Torrent size does not match the number of pieces and the piece size!");
        }
    } catch (final InvalidBEncodingException ex) {
        throw new IllegalArgumentException("Error reading torrent meta-info fields!", ex);
    }

}
 
开发者ID:anthonyraymond,项目名称:joal,代码行数:28,代码来源:MockedTorrent.java

示例2: printValue

import com.turn.ttorrent.bcodec.InvalidBEncodingException; //导入依赖的package包/类
public static String printValue(BEValue value) throws InvalidBEncodingException {
  if (value.getValue() instanceof byte[]) {
    return "\"" + value.getString("UTF-8") + "\"";
  } else if (value.getValue() instanceof Integer) {
    return "" + value.getInt();
  } else if (value.getValue() instanceof Long) {
    return "" + value.getLong();
  } else if (value.getValue() instanceof Number) {
    return "" + value.getNumber();
  } else if (value.getValue() instanceof Map) {
    return printMap(value.getMap());
  } else if (value.getValue() instanceof List) {
    return printList(value.getList());
  }
  return "{}";
}
 
开发者ID:cjmalloy,项目名称:torrent-fs,代码行数:17,代码来源:BencodeUtil.java

示例3: parse

import com.turn.ttorrent.bcodec.InvalidBEncodingException; //导入依赖的package包/类
public static HTTPTrackerErrorMessage parse(ByteBuffer data)
	throws IOException, MessageValidationException {
	BEValue decoded = BDecoder.bdecode(data);
	if (decoded == null) {
		throw new MessageValidationException(
			"Could not decode tracker message (not B-encoded?)!");
	}

	Map<String, BEValue> params = decoded.getMap();

	try {
		return new HTTPTrackerErrorMessage(
			data,
			params.get("failure reason")
				.getString(Torrent.BYTE_ENCODING));
	} catch (InvalidBEncodingException ibee) {
		throw new MessageValidationException("Invalid tracker error " +
			"message!", ibee);
	}
}
 
开发者ID:DurandA,项目名称:bitworker,代码行数:21,代码来源:HTTPTrackerErrorMessage.java

示例4: toPeerList

import com.turn.ttorrent.bcodec.InvalidBEncodingException; //导入依赖的package包/类
/**
 * Build a peer list as a list of {@link Peer}s from the
 * announce response's binary compact peer list.
 *
 * @param data The bytes representing the compact peer list from the
 * announce response.
 * @return A {@link List} of {@link Peer}s representing the
 * peers' addresses. Peer IDs are lost, but they are not crucial.
 */
private static List<Peer> toPeerList(byte[] data)
	throws InvalidBEncodingException, UnknownHostException {
	if (data.length % 6 != 0) {
		throw new InvalidBEncodingException("Invalid peers " +
			"binary information string!");
	}

	List<Peer> result = new LinkedList<Peer>();
	ByteBuffer peers = ByteBuffer.wrap(data);

	for (int i=0; i < data.length / 6 ; i++) {
		byte[] ipBytes = new byte[4];
		peers.get(ipBytes);
		InetAddress ip = InetAddress.getByAddress(ipBytes);
		int port =
			(0xFF & (int)peers.get()) << 8 |
			(0xFF & (int)peers.get());
		result.add(new Peer(new InetSocketAddress(ip, port)));
	}

	return result;
}
 
开发者ID:DurandA,项目名称:bitworker,代码行数:32,代码来源:HTTPAnnounceResponseMessage.java

示例5: printList

import com.turn.ttorrent.bcodec.InvalidBEncodingException; //导入依赖的package包/类
public static String printList(List<BEValue> value) throws InvalidBEncodingException {
  String s = "[";
  boolean started = false;
  for (BEValue v : value) {
    if (started) s += ",";
    started = true;
    s += printValue(v);
  }
  return s + "]";
}
 
开发者ID:cjmalloy,项目名称:torrent-fs,代码行数:11,代码来源:BencodeUtil.java

示例6: printMap

import com.turn.ttorrent.bcodec.InvalidBEncodingException; //导入依赖的package包/类
public static String printMap(Map<String, BEValue> value) throws InvalidBEncodingException {
  String s = "{";
  boolean started = false;
  for (String k : value.keySet()) {
    if (started) s += ",";
    started = true;
    s += "\"" + k + "\": ";
    if (k.equals("pieces")) {
      s += "\"snip\"";
    } else {
      s += printValue(value.get(k));
    }
  }
  return s + "}";
}
 
开发者ID:cjmalloy,项目名称:torrent-fs,代码行数:16,代码来源:BencodeUtil.java

示例7: SharedTorrent

import com.turn.ttorrent.bcodec.InvalidBEncodingException; //导入依赖的package包/类
/**
 * Create a new shared torrent from meta-info binary data.
 *
 * @param torrent The meta-info byte data.
 * @param parent The parent directory or location the torrent files.
 * @param seeder Whether we're a seeder for this torrent or not (disables
 * validation).
 * @throws FileNotFoundException If the torrent file location or
 * destination directory does not exist and can't be created.
 * @throws IOException If the torrent file cannot be read or decoded.
 */
public SharedTorrent(byte[] torrent, File parent, boolean seeder)
	throws FileNotFoundException, IOException {
	super(torrent, seeder);

	if (parent == null || !parent.isDirectory()) {
		throw new IllegalArgumentException("Invalid parent directory!");
	}

	 parentPath = parent.getCanonicalPath();

	try {
		this.pieceLength = this.decoded_info.get("piece length").getInt();
		/*this.piecesHashes = ByteBuffer.wrap(this.decoded_info.get("pieces")
				.getBytes());

		if (this.piecesHashes.capacity() / Torrent.PIECE_HASH_SIZE *
				(long)this.pieceLength < this.getSize()) {
			throw new IllegalArgumentException("Torrent size does not " +
					"match the number of pieces and the piece size!");
		}*/
	} catch (InvalidBEncodingException ibee) {
		throw new IllegalArgumentException(
				"Error reading torrent meta-info fields!");
	}

	List<FileStorage> files = new LinkedList<FileStorage>();
	long offset = 0L;
	
	for (Torrent.TorrentFile file : this.files) {
		
		for (int i = 0; i < (file.size/this.pieceLength); i++) {
			File actual = new File(parent+"/"+ file.file.getPath()+"."+i);
			if (!actual.getCanonicalPath().startsWith(parentPath)) {
			throw new SecurityException("Torrent file path attempted " +
				"to break directory jail!");
		}
			
				actual.getParentFile().mkdirs();
				files.add(new FileStorage(actual, offset, 0));
		}
	
		//offset += file.size;
	}
	this.bucket = new FileCollectionStorage(files, this.getSize());

	this.random = new Random(System.currentTimeMillis());
	this.stop = false;

	this.uploaded = 0;
	this.downloaded = 0;
	this.left = this.getSize();

	this.initialized = false;
	this.pieces = new Piece[0];
	this.rarest = Collections.synchronizedSortedSet(new TreeSet<Piece>());
	this.completedPieces = new BitSet();
	this.requestedPieces = new BitSet();
}
 
开发者ID:DurandA,项目名称:bitworker,代码行数:70,代码来源:SharedTorrent.java


注:本文中的com.turn.ttorrent.bcodec.InvalidBEncodingException类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。