forked from KNEMC/KLALB
KLALB完全大重写,代码规范了,可以当作网络库使用
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
package org.kne.cloud.network.klalb;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.net.Inet6Address;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.UUID;
|
||||
|
||||
public class KLALBUtils {
|
||||
public static Inet6Address uuidToIP(UUID uuid) {
|
||||
ByteArrayOutputStream bos=new ByteArrayOutputStream(8);
|
||||
DataOutputStream dos=new DataOutputStream(bos);
|
||||
try {
|
||||
dos.writeLong(uuid.getMostSignificantBits());
|
||||
dos.writeLong(uuid.getLeastSignificantBits());
|
||||
dos.close();} catch (IOException e) {
|
||||
// TODO 自动生成的 catch 块
|
||||
e.printStackTrace();
|
||||
}
|
||||
try {
|
||||
return (Inet6Address) Inet6Address.getByAddress(bos.toByteArray());
|
||||
} catch (UnknownHostException e) {
|
||||
// TODO 自动生成的 catch 块
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public static void main(String[] args) {
|
||||
System.out.println(uuidToIP(new UUID(-1,-1)));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user