@Test public void testBytes2IpString() throws IPStringConversionException { IPv6 ip = new IPv6(ipv4Mixed_bytes); assertTrue("Expected Bytes2IpString to work", ipv4Mixed_uncompressed.equals(ip.getString())); }
public static String bytes2IpString(byte[] in) throws IPStringConversionException { int i; int hi; int lo; StringBuilder sb = new StringBuilder(); String hex; if (in.length != 16) { String msg = "Error IPv6 requires byte array of length 16"; throw new IPStringConversionException(msg); } for (i = 0; i < 14; i += 2) { hi = BitConverters.ubyte2int(in[i]) << 8; lo = BitConverters.ubyte2int(in[i + 1]); hex = String.format("%s:", BitConverters.int16bit2hex(hi | lo)); sb.append(hex); } hi = BitConverters.ubyte2int(in[14]) << 8; lo = BitConverters.ubyte2int(in[15]); sb.append(String.format("%s", BitConverters.int16bit2hex(hi | lo))); return sb.toString(); }
IPv6 implements Comparable<IPv6> { public static String bytes2IpString(byte[] in) throws IPStringConversionException { int i; int hi; int lo; StringBuilder sb = new StringBuilder(); String hex; if (in.length != 16) { String msg = "Error IPv6 requires byte array of length 16"; throw new IPStringConversionException(msg); } for (i = 0; i < 14; i += 2) { hi = BitConverters.ubyte2int(in[i]) << 8; lo = BitConverters.ubyte2int(in[i + 1]); hex = String.format("%s:", BitConverters.int16bit2hex(hi | lo)); sb.append(hex); } hi = BitConverters.ubyte2int(in[14]) << 8; lo = BitConverters.ubyte2int(in[15]); sb.append(String.format("%s", BitConverters.int16bit2hex(hi | lo))); return sb.toString(); } }
IPv6 implements Comparable<IPv6> { public static String bytes2IpString(byte[] in) throws IPStringConversionException { int i; int hi; int lo; StringBuilder sb = new StringBuilder(); String hex; if (in.length != 16) { String msg = "Error IPv6 requires byte array of length 16"; throw new IPStringConversionException(msg); } for (i = 0; i < 14; i += 2) { hi = BitConverters.ubyte2int(in[i]) << 8; lo = BitConverters.ubyte2int(in[i + 1]); hex = String.format("%s:", BitConverters.int16bit2hex(hi | lo)); sb.append(hex); } hi = BitConverters.ubyte2int(in[14]) << 8; lo = BitConverters.ubyte2int(in[15]); sb.append(String.format("%s", BitConverters.int16bit2hex(hi | lo))); return sb.toString(); } IPv6(BigInteger in);  IPv6();  IPv6(String ip);  IPv6(byte[] in); }
IPv6 implements Comparable<IPv6> { public static String bytes2IpString(byte[] in) throws IPStringConversionException { int i; int hi; int lo; StringBuilder sb = new StringBuilder(); String hex; if (in.length != 16) { String msg = "Error IPv6 requires byte array of length 16"; throw new IPStringConversionException(msg); } for (i = 0; i < 14; i += 2) { hi = BitConverters.ubyte2int(in[i]) << 8; lo = BitConverters.ubyte2int(in[i + 1]); hex = String.format("%s:", BitConverters.int16bit2hex(hi | lo)); sb.append(hex); } hi = BitConverters.ubyte2int(in[14]) << 8; lo = BitConverters.ubyte2int(in[15]); sb.append(String.format("%s", BitConverters.int16bit2hex(hi | lo))); return sb.toString(); } IPv6(BigInteger in);  IPv6();  IPv6(String ip);  IPv6(byte[] in); static String expand(String ipStr, int nwords); String expand(); BigInteger toBigInteger(); static IPv6 bigInteger2IPv6(BigInteger in); static byte[] IpString2bytes(String ipStr); static String bytes2IpString(byte[] in); void setIp(byte[] in); String getString(); byte[] getBytes(); void setIp(String ip); void insertInteger(int in, int startBit); void insertBigInteger(BigInteger in, int startBit, int size); void setAccountPartition(int accountId); void setVipOctets(int lo); int getVipOctets(); void setClusterPartition(IPv6Cidr clusterCidr); @Override String toString(); @Override boolean equals(Object obj); @Override int hashCode(); @Override int compareTo(IPv6 that); }
IPv6 implements Comparable<IPv6> { public static String bytes2IpString(byte[] in) throws IPStringConversionException { int i; int hi; int lo; StringBuilder sb = new StringBuilder(); String hex; if (in.length != 16) { String msg = "Error IPv6 requires byte array of length 16"; throw new IPStringConversionException(msg); } for (i = 0; i < 14; i += 2) { hi = BitConverters.ubyte2int(in[i]) << 8; lo = BitConverters.ubyte2int(in[i + 1]); hex = String.format("%s:", BitConverters.int16bit2hex(hi | lo)); sb.append(hex); } hi = BitConverters.ubyte2int(in[14]) << 8; lo = BitConverters.ubyte2int(in[15]); sb.append(String.format("%s", BitConverters.int16bit2hex(hi | lo))); return sb.toString(); } IPv6(BigInteger in);  IPv6();  IPv6(String ip);  IPv6(byte[] in); static String expand(String ipStr, int nwords); String expand(); BigInteger toBigInteger(); static IPv6 bigInteger2IPv6(BigInteger in); static byte[] IpString2bytes(String ipStr); static String bytes2IpString(byte[] in); void setIp(byte[] in); String getString(); byte[] getBytes(); void setIp(String ip); void insertInteger(int in, int startBit); void insertBigInteger(BigInteger in, int startBit, int size); void setAccountPartition(int accountId); void setVipOctets(int lo); int getVipOctets(); void setClusterPartition(IPv6Cidr clusterCidr); @Override String toString(); @Override boolean equals(Object obj); @Override int hashCode(); @Override int compareTo(IPv6 that);  }