@Test public void expandIPTest() { Assert.assertEquals(AclUtils.expandIP("::1", 8), "0000:0000:0000:0000:0000:0000:0000:0001"); Assert.assertEquals(AclUtils.expandIP("3::", 8), "0003:0000:0000:0000:0000:0000:0000:0000"); Assert.assertEquals(AclUtils.expandIP("2::2", 8), "0002:0000:0000:0000:0000:0000:0000:0002"); Assert.assertEquals(AclUtils.expandIP("4::aac4:92", 8), "0004:0000:0000:0000:0000:0000:AAC4:0092"); Assert.assertEquals(AclUtils.expandIP("ab23:56:901a::cc6:765:bb:9011", 8), "AB23:0056:901A:0000:0CC6:0765:00BB:9011"); Assert.assertEquals(AclUtils.expandIP("ab23:56:901a:1:cc6:765:bb:9011", 8), "AB23:0056:901A:0001:0CC6:0765:00BB:9011"); Assert.assertEquals(AclUtils.expandIP("5::7:6", 6), "0005:0000:0000:0000:0007:0006"); }
public static String expandIP(String netaddress, int part) { boolean compress = false; int compressIndex = -1; String[] strArray = StringUtils.split(netaddress, ":"); ArrayList<Integer> indexes = new ArrayList<>(); for (int i = 0; i < netaddress.length(); i++) { if (netaddress.charAt(i) == ':') { if (indexes.size() > 0 && i - indexes.get(indexes.size() - 1) == 1) { compressIndex = i; compress = true; } indexes.add(i); } } for (int i = 0; i < strArray.length; i++) { if (strArray[i].length() < 4) { strArray[i] = "0000".substring(0, 4 - strArray[i].length()) + strArray[i]; } } StringBuilder sb = new StringBuilder(); if (compress) { int pos = indexes.indexOf(compressIndex); int index = 0; if (!netaddress.startsWith(":")) { for (int i = 0; i < pos; i++) { sb.append(strArray[index]).append(":"); index += 1; } } int zeroNum = part - strArray.length; if (netaddress.endsWith(":")) { for (int i = 0; i < zeroNum; i++) { sb.append("0000"); if (i != zeroNum - 1) { sb.append(":"); } } } else { for (int i = 0; i < zeroNum; i++) { sb.append("0000").append(":"); } for (int i = index; i < strArray.length; i++) { sb.append(strArray[i]); if (i != strArray.length - 1) { sb.append(":"); } } } } else { for (int i = 0; i < strArray.length; i++) { sb.append(strArray[i]); if (i != strArray.length - 1) { sb.append(":"); } } } return sb.toString().toUpperCase(); }
AclUtils { public static String expandIP(String netaddress, int part) { boolean compress = false; int compressIndex = -1; String[] strArray = StringUtils.split(netaddress, ":"); ArrayList<Integer> indexes = new ArrayList<>(); for (int i = 0; i < netaddress.length(); i++) { if (netaddress.charAt(i) == ':') { if (indexes.size() > 0 && i - indexes.get(indexes.size() - 1) == 1) { compressIndex = i; compress = true; } indexes.add(i); } } for (int i = 0; i < strArray.length; i++) { if (strArray[i].length() < 4) { strArray[i] = "0000".substring(0, 4 - strArray[i].length()) + strArray[i]; } } StringBuilder sb = new StringBuilder(); if (compress) { int pos = indexes.indexOf(compressIndex); int index = 0; if (!netaddress.startsWith(":")) { for (int i = 0; i < pos; i++) { sb.append(strArray[index]).append(":"); index += 1; } } int zeroNum = part - strArray.length; if (netaddress.endsWith(":")) { for (int i = 0; i < zeroNum; i++) { sb.append("0000"); if (i != zeroNum - 1) { sb.append(":"); } } } else { for (int i = 0; i < zeroNum; i++) { sb.append("0000").append(":"); } for (int i = index; i < strArray.length; i++) { sb.append(strArray[i]); if (i != strArray.length - 1) { sb.append(":"); } } } } else { for (int i = 0; i < strArray.length; i++) { sb.append(strArray[i]); if (i != strArray.length - 1) { sb.append(":"); } } } return sb.toString().toUpperCase(); } }
AclUtils { public static String expandIP(String netaddress, int part) { boolean compress = false; int compressIndex = -1; String[] strArray = StringUtils.split(netaddress, ":"); ArrayList<Integer> indexes = new ArrayList<>(); for (int i = 0; i < netaddress.length(); i++) { if (netaddress.charAt(i) == ':') { if (indexes.size() > 0 && i - indexes.get(indexes.size() - 1) == 1) { compressIndex = i; compress = true; } indexes.add(i); } } for (int i = 0; i < strArray.length; i++) { if (strArray[i].length() < 4) { strArray[i] = "0000".substring(0, 4 - strArray[i].length()) + strArray[i]; } } StringBuilder sb = new StringBuilder(); if (compress) { int pos = indexes.indexOf(compressIndex); int index = 0; if (!netaddress.startsWith(":")) { for (int i = 0; i < pos; i++) { sb.append(strArray[index]).append(":"); index += 1; } } int zeroNum = part - strArray.length; if (netaddress.endsWith(":")) { for (int i = 0; i < zeroNum; i++) { sb.append("0000"); if (i != zeroNum - 1) { sb.append(":"); } } } else { for (int i = 0; i < zeroNum; i++) { sb.append("0000").append(":"); } for (int i = index; i < strArray.length; i++) { sb.append(strArray[i]); if (i != strArray.length - 1) { sb.append(":"); } } } } else { for (int i = 0; i < strArray.length; i++) { sb.append(strArray[i]); if (i != strArray.length - 1) { sb.append(":"); } } } return sb.toString().toUpperCase(); }  }
AclUtils { public static String expandIP(String netaddress, int part) { boolean compress = false; int compressIndex = -1; String[] strArray = StringUtils.split(netaddress, ":"); ArrayList<Integer> indexes = new ArrayList<>(); for (int i = 0; i < netaddress.length(); i++) { if (netaddress.charAt(i) == ':') { if (indexes.size() > 0 && i - indexes.get(indexes.size() - 1) == 1) { compressIndex = i; compress = true; } indexes.add(i); } } for (int i = 0; i < strArray.length; i++) { if (strArray[i].length() < 4) { strArray[i] = "0000".substring(0, 4 - strArray[i].length()) + strArray[i]; } } StringBuilder sb = new StringBuilder(); if (compress) { int pos = indexes.indexOf(compressIndex); int index = 0; if (!netaddress.startsWith(":")) { for (int i = 0; i < pos; i++) { sb.append(strArray[index]).append(":"); index += 1; } } int zeroNum = part - strArray.length; if (netaddress.endsWith(":")) { for (int i = 0; i < zeroNum; i++) { sb.append("0000"); if (i != zeroNum - 1) { sb.append(":"); } } } else { for (int i = 0; i < zeroNum; i++) { sb.append("0000").append(":"); } for (int i = index; i < strArray.length; i++) { sb.append(strArray[i]); if (i != strArray.length - 1) { sb.append(":"); } } } } else { for (int i = 0; i < strArray.length; i++) { sb.append(strArray[i]); if (i != strArray.length - 1) { sb.append(":"); } } } return sb.toString().toUpperCase(); }  static byte[] combineRequestContent(RemotingCommand request, SortedMap<String, String> fieldsMap); static byte[] combineBytes(byte[] b1, byte[] b2); static String calSignature(byte[] data, String secretKey); static void IPv6AddressCheck(String netaddress); static String v6ipProcess(String netaddress, String[] strArray, int index); static void verify(String netaddress, int index); static String[] getAddreeStrArray(String netaddress, String partialAddress); static boolean isScope(String netaddress, int index); static boolean isScope(String[] num, int index); static boolean isColon(String netaddress); static boolean isScope(String num); static boolean isScope(int num); static boolean isAsterisk(String asterisk); static boolean isComma(String colon); static boolean isMinus(String minus); static boolean isIPv6Scope(String[] num, int index); static boolean isIPv6Scope(int num); static String expandIP(String netaddress, int part); static T getYamlDataObject(String path, Class<T> clazz); static boolean writeDataObject(String path, Map<String, Object> dataMap); static RPCHook getAclRPCHook(String fileName); }
AclUtils { public static String expandIP(String netaddress, int part) { boolean compress = false; int compressIndex = -1; String[] strArray = StringUtils.split(netaddress, ":"); ArrayList<Integer> indexes = new ArrayList<>(); for (int i = 0; i < netaddress.length(); i++) { if (netaddress.charAt(i) == ':') { if (indexes.size() > 0 && i - indexes.get(indexes.size() - 1) == 1) { compressIndex = i; compress = true; } indexes.add(i); } } for (int i = 0; i < strArray.length; i++) { if (strArray[i].length() < 4) { strArray[i] = "0000".substring(0, 4 - strArray[i].length()) + strArray[i]; } } StringBuilder sb = new StringBuilder(); if (compress) { int pos = indexes.indexOf(compressIndex); int index = 0; if (!netaddress.startsWith(":")) { for (int i = 0; i < pos; i++) { sb.append(strArray[index]).append(":"); index += 1; } } int zeroNum = part - strArray.length; if (netaddress.endsWith(":")) { for (int i = 0; i < zeroNum; i++) { sb.append("0000"); if (i != zeroNum - 1) { sb.append(":"); } } } else { for (int i = 0; i < zeroNum; i++) { sb.append("0000").append(":"); } for (int i = index; i < strArray.length; i++) { sb.append(strArray[i]); if (i != strArray.length - 1) { sb.append(":"); } } } } else { for (int i = 0; i < strArray.length; i++) { sb.append(strArray[i]); if (i != strArray.length - 1) { sb.append(":"); } } } return sb.toString().toUpperCase(); }  static byte[] combineRequestContent(RemotingCommand request, SortedMap<String, String> fieldsMap); static byte[] combineBytes(byte[] b1, byte[] b2); static String calSignature(byte[] data, String secretKey); static void IPv6AddressCheck(String netaddress); static String v6ipProcess(String netaddress, String[] strArray, int index); static void verify(String netaddress, int index); static String[] getAddreeStrArray(String netaddress, String partialAddress); static boolean isScope(String netaddress, int index); static boolean isScope(String[] num, int index); static boolean isColon(String netaddress); static boolean isScope(String num); static boolean isScope(int num); static boolean isAsterisk(String asterisk); static boolean isComma(String colon); static boolean isMinus(String minus); static boolean isIPv6Scope(String[] num, int index); static boolean isIPv6Scope(int num); static String expandIP(String netaddress, int part); static T getYamlDataObject(String path, Class<T> clazz); static boolean writeDataObject(String path, Map<String, Object> dataMap); static RPCHook getAclRPCHook(String fileName);  }