All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.acgist.snail.utils.PeerUtils Maven / Gradle / Ivy

package com.acgist.snail.utils;

import java.nio.ByteBuffer;
import java.util.HashMap;
import java.util.Map;

/**
 * 

Peer工具

* * @author acgist * @since 1.0.0 */ public class PeerUtils { /** * 读取IP和端口信息 */ public static final Map read(byte[] bytes) { if(bytes == null) { return null; } final ByteBuffer buffer = ByteBuffer.wrap(bytes); return read(buffer, bytes.length); } /** * 读取IP和端口信息 */ public static final Map read(ByteBuffer buffer, int size) { if(buffer == null) { return null; } final Map data = new HashMap<>(); while (buffer.position() < size) { final String ip = NetUtils.decodeIntToIp(buffer.getInt()); final int port = NetUtils.decodePort(buffer.getShort()); data.put(ip, port); } return data; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy