@Test public void testToBytes() throws Exception { assertArrayEquals(new byte[]{32, 127, 0, 0, 1}, IpPrefixConv.toBytes(ipPrefix1)); assertArrayEquals(new byte[]{16, 0, 0}, IpPrefixConv.toBytes(ipPrefix2)); assertArrayEquals(new byte[]{-128, 32, 1, 13, -72, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, IpPrefixConv.toBytes(ipPrefix3)); assertArrayEquals(new byte[]{32, 32, 1, 0, -40}, IpPrefixConv.toBytes(ipPrefix4)); assertNotNull(IpPrefixConv.toBytes(new ArrayList<IpPrefix>())); assertArrayEquals( new byte[]{32, 127, 0, 0, 1, 16, 0, 0, -128, 32, 1, 13, -72, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 32, 32, 1, 0, -40}, IpPrefixConv.toBytes(ipPrefixes)); }
public static byte[] toBytes(IpPrefix prefix) { String _prefix = prefix.stringValue(); if (_prefix.startsWith("/")) { _prefix = _prefix.substring(1); } int i = _prefix.lastIndexOf('/'); if (i != -1) { _prefix = _prefix.substring(0, i); } int length = getPrefixLength(prefix); byte[] bprefix = trimPrefix(InetAddresses.forString(_prefix).getAddress(), getBytesLength(length)); if (Configuration.SET_COMPOSITION_ATTRIBUTE_COMPACT_NO_RESERVED_FIELDS) { return ArraysUtil.combine(new byte[] {ArraysUtil.int2bytes(length)[3]}, bprefix); } return ArraysUtil.combine(new byte[] {ArraysUtil.int2bytes(length)[3], 0x00, 0x00, 0x00}, bprefix); }
IpPrefixConv { public static byte[] toBytes(IpPrefix prefix) { String _prefix = prefix.stringValue(); if (_prefix.startsWith("/")) { _prefix = _prefix.substring(1); } int i = _prefix.lastIndexOf('/'); if (i != -1) { _prefix = _prefix.substring(0, i); } int length = getPrefixLength(prefix); byte[] bprefix = trimPrefix(InetAddresses.forString(_prefix).getAddress(), getBytesLength(length)); if (Configuration.SET_COMPOSITION_ATTRIBUTE_COMPACT_NO_RESERVED_FIELDS) { return ArraysUtil.combine(new byte[] {ArraysUtil.int2bytes(length)[3]}, bprefix); } return ArraysUtil.combine(new byte[] {ArraysUtil.int2bytes(length)[3], 0x00, 0x00, 0x00}, bprefix); } }
IpPrefixConv { public static byte[] toBytes(IpPrefix prefix) { String _prefix = prefix.stringValue(); if (_prefix.startsWith("/")) { _prefix = _prefix.substring(1); } int i = _prefix.lastIndexOf('/'); if (i != -1) { _prefix = _prefix.substring(0, i); } int length = getPrefixLength(prefix); byte[] bprefix = trimPrefix(InetAddresses.forString(_prefix).getAddress(), getBytesLength(length)); if (Configuration.SET_COMPOSITION_ATTRIBUTE_COMPACT_NO_RESERVED_FIELDS) { return ArraysUtil.combine(new byte[] {ArraysUtil.int2bytes(length)[3]}, bprefix); } return ArraysUtil.combine(new byte[] {ArraysUtil.int2bytes(length)[3], 0x00, 0x00, 0x00}, bprefix); } private  IpPrefixConv(); }
IpPrefixConv { public static byte[] toBytes(IpPrefix prefix) { String _prefix = prefix.stringValue(); if (_prefix.startsWith("/")) { _prefix = _prefix.substring(1); } int i = _prefix.lastIndexOf('/'); if (i != -1) { _prefix = _prefix.substring(0, i); } int length = getPrefixLength(prefix); byte[] bprefix = trimPrefix(InetAddresses.forString(_prefix).getAddress(), getBytesLength(length)); if (Configuration.SET_COMPOSITION_ATTRIBUTE_COMPACT_NO_RESERVED_FIELDS) { return ArraysUtil.combine(new byte[] {ArraysUtil.int2bytes(length)[3]}, bprefix); } return ArraysUtil.combine(new byte[] {ArraysUtil.int2bytes(length)[3], 0x00, 0x00, 0x00}, bprefix); } private  IpPrefixConv(); static IpPrefix createPrefix(String ipPrefix); static List<IpPrefix> decodeIpv4(byte[] array, boolean compact); static List<IpPrefix> decodeIpv6(byte[] array, boolean compact); static boolean equalTo(IpPrefix prefix1, IpPrefix prefix2); static int getBytesLength(int prefixLength); static int getPrefixLength(IpPrefix ipPrefix); static InetSocketAddress parseInetPrefix(String ipPrefix); static byte[] toBytes(IpPrefix prefix); static byte[] toBytes(List<IpPrefix> prefixes); static String toString(IpPrefix prefix); static String toString(List<IpPrefix> prefixes); static byte[] trimPrefix(byte[] prefix, int blength); }
IpPrefixConv { public static byte[] toBytes(IpPrefix prefix) { String _prefix = prefix.stringValue(); if (_prefix.startsWith("/")) { _prefix = _prefix.substring(1); } int i = _prefix.lastIndexOf('/'); if (i != -1) { _prefix = _prefix.substring(0, i); } int length = getPrefixLength(prefix); byte[] bprefix = trimPrefix(InetAddresses.forString(_prefix).getAddress(), getBytesLength(length)); if (Configuration.SET_COMPOSITION_ATTRIBUTE_COMPACT_NO_RESERVED_FIELDS) { return ArraysUtil.combine(new byte[] {ArraysUtil.int2bytes(length)[3]}, bprefix); } return ArraysUtil.combine(new byte[] {ArraysUtil.int2bytes(length)[3], 0x00, 0x00, 0x00}, bprefix); } private  IpPrefixConv(); static IpPrefix createPrefix(String ipPrefix); static List<IpPrefix> decodeIpv4(byte[] array, boolean compact); static List<IpPrefix> decodeIpv6(byte[] array, boolean compact); static boolean equalTo(IpPrefix prefix1, IpPrefix prefix2); static int getBytesLength(int prefixLength); static int getPrefixLength(IpPrefix ipPrefix); static InetSocketAddress parseInetPrefix(String ipPrefix); static byte[] toBytes(IpPrefix prefix); static byte[] toBytes(List<IpPrefix> prefixes); static String toString(IpPrefix prefix); static String toString(List<IpPrefix> prefixes); static byte[] trimPrefix(byte[] prefix, int blength);  }