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