parent
ca70018b0c
commit
f01434f22e
|
@ -16,7 +16,10 @@ import java.nio.charset.StandardCharsets;
|
||||||
import java.sql.Timestamp;
|
import java.sql.Timestamp;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
@ -130,19 +133,33 @@ public class Helper {
|
||||||
* @return the string
|
* @return the string
|
||||||
*/
|
*/
|
||||||
public static String ipAddrToFullFormat(String ipAddr) {
|
public static String ipAddrToFullFormat(String ipAddr) {
|
||||||
String[] ipArrays = ipAddr.split("-");
|
List<String> formatString = new ArrayList<>();
|
||||||
|
|
||||||
for(int i = 0; i < ipArrays.length; i++) {
|
for (String v : ipAddr.split(DisposeConfigValue.SPLIT_CHAR)) {
|
||||||
IPAddressString addrString = new IPAddressString(ipArrays[i]);
|
if (v.contains("/")) {
|
||||||
|
String[] ret = v.split("/");
|
||||||
|
IPAddressString addrString = new IPAddressString(ret[0]);
|
||||||
IPAddress addr = addrString.getAddress();
|
IPAddress addr = addrString.getAddress();
|
||||||
ipArrays[i] = addr.toFullString().toUpperCase();
|
formatString.add(addr.toNormalizedString().toUpperCase() + "/" + ret[1]);
|
||||||
|
} else if (v.contains("-")) {
|
||||||
|
String[] ret = v.split("-");
|
||||||
|
|
||||||
|
for (int i = 0; i < ret.length; i++) {
|
||||||
|
IPAddressString addrString = new IPAddressString(ret[i]);
|
||||||
|
IPAddress addr = addrString.getAddress();
|
||||||
|
ret[i] = addr.toNormalizedString().toUpperCase();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(ipArrays.length == 1) {
|
formatString.add(ret[0] + "-" + ret[1]);
|
||||||
return ipArrays[0];
|
|
||||||
} else {
|
} else {
|
||||||
return ipArrays[0] + "-" + ipArrays[1];
|
IPAddressString addrString = new IPAddressString(v);
|
||||||
|
IPAddress addr = addrString.getAddress();
|
||||||
|
formatString.add(addr.toNormalizedString().toUpperCase());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return formatString.stream().map(Objects::toString).collect(Collectors.joining(","));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -220,7 +237,8 @@ public class Helper {
|
||||||
public static String inputStream2String(InputStream inputStream) {
|
public static String inputStream2String(InputStream inputStream) {
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
|
|
||||||
try (BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, StandardCharsets.UTF_8))) {
|
try (BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream,
|
||||||
|
StandardCharsets.UTF_8))) {
|
||||||
String line;
|
String line;
|
||||||
while ((line = reader.readLine()) != null) {
|
while ((line = reader.readLine()) != null) {
|
||||||
sb.append(line);
|
sb.append(line);
|
||||||
|
|
|
@ -523,20 +523,22 @@ public class demo {
|
||||||
/**
|
/**
|
||||||
* Ip segment.
|
* Ip segment.
|
||||||
*/
|
*/
|
||||||
public void ipSegment() {
|
@Test
|
||||||
String str = "192.168.1.1/23, 192.168.1.2-192.168.1.80, ::1-::255, 192.168.1, 01.012.012.01, " +
|
public void ipSegmentTest() {
|
||||||
"123.123.123-";
|
String str = "192.168.1.1/23, 192.168.1.2-192.168.1.80, ::1-::255, 01.012.012.01, ::1/24, ::02:23";
|
||||||
String fIpAddr = "";
|
String fIpAddr = "";
|
||||||
|
|
||||||
for (String s : str.split(DisposeConfigValue.SPLIT_CHAR)) {
|
for (String s : str.split(DisposeConfigValue.SPLIT_CHAR)) {
|
||||||
|
|
||||||
log.info("process string: {}", s);
|
// log.info("process string: {}", s);
|
||||||
|
//
|
||||||
|
// String normalString = s.replace(" ", "");
|
||||||
|
//
|
||||||
|
// if (!Pattern.matches(ConstValue.ipAddrSegmentReg(), normalString)) {
|
||||||
|
// log.error("Step1: {} not match", normalString);
|
||||||
|
// }
|
||||||
|
|
||||||
String normalString = s.replace(" ", "");
|
log.info("Format: {} --> {}", s, Helper.ipAddrToFullFormat(s));
|
||||||
|
|
||||||
if (!Pattern.matches(ConstValue.ipAddrSegmentReg(), normalString)) {
|
|
||||||
log.error("Step1: {} not match", normalString);
|
|
||||||
}
|
|
||||||
|
|
||||||
// if (normalString.indexOf("-") == normalString.lastIndexOf("-")) {
|
// if (normalString.indexOf("-") == normalString.lastIndexOf("-")) {
|
||||||
// if(normalString.contains("-")) {
|
// if(normalString.contains("-")) {
|
||||||
|
|
Loading…
Reference in New Issue