@Test(expected = ParseException.class) public void testParse03() throws ParseException { IPv4Address.newIPv4Instance("127.0.0.299"); }
public static IPv4Address newIPv4Instance(String ipv4AddressString) throws ParseException { if (ipv4AddressString == null || ipv4AddressString.length() == 0) { return null; } int slashPos = ipv4AddressString.indexOf('/'); int colonPos = ipv4AddressString.indexOf(':'); if ((colonPos >= 0) && (colonPos < slashPos)) { throw new ParseException(INVALID_IP4ADDRESS_MSG + ipv4AddressString + "\": out of order components", colonPos); } int endAddress = (slashPos >= 0 ? slashPos : (colonPos >= 0 ? colonPos : ipv4AddressString.length() )); if (endAddress < 7) { throw new ParseException(INVALID_IP4ADDRESS_MSG + ipv4AddressString + "\": address too short", 0); } short[] addressBytes = getAddress(ipv4AddressString.substring(0, endAddress)); short[] maskBytes = null; if (slashPos >= 0) { int endMask = (colonPos >= 0 ? colonPos : ipv4AddressString.length()); maskBytes = getAddress(ipv4AddressString.substring(slashPos+1, endMask)); } PortRange portRange = null; if (colonPos >= 0) { if (ipv4AddressString.substring(colonPos+1).length() < 1) { throw new ParseException(INVALID_IP4ADDRESS_MSG + ipv4AddressString + "\": no portrange given after ':'", colonPos+1); } portRange = PortRange.newInstance(ipv4AddressString.substring(colonPos+1)); } return new IPv4Address(addressBytes, maskBytes, portRange); }
IPv4Address extends IPAddress { public static IPv4Address newIPv4Instance(String ipv4AddressString) throws ParseException { if (ipv4AddressString == null || ipv4AddressString.length() == 0) { return null; } int slashPos = ipv4AddressString.indexOf('/'); int colonPos = ipv4AddressString.indexOf(':'); if ((colonPos >= 0) && (colonPos < slashPos)) { throw new ParseException(INVALID_IP4ADDRESS_MSG + ipv4AddressString + "\": out of order components", colonPos); } int endAddress = (slashPos >= 0 ? slashPos : (colonPos >= 0 ? colonPos : ipv4AddressString.length() )); if (endAddress < 7) { throw new ParseException(INVALID_IP4ADDRESS_MSG + ipv4AddressString + "\": address too short", 0); } short[] addressBytes = getAddress(ipv4AddressString.substring(0, endAddress)); short[] maskBytes = null; if (slashPos >= 0) { int endMask = (colonPos >= 0 ? colonPos : ipv4AddressString.length()); maskBytes = getAddress(ipv4AddressString.substring(slashPos+1, endMask)); } PortRange portRange = null; if (colonPos >= 0) { if (ipv4AddressString.substring(colonPos+1).length() < 1) { throw new ParseException(INVALID_IP4ADDRESS_MSG + ipv4AddressString + "\": no portrange given after ':'", colonPos+1); } portRange = PortRange.newInstance(ipv4AddressString.substring(colonPos+1)); } return new IPv4Address(addressBytes, maskBytes, portRange); } }
IPv4Address extends IPAddress { public static IPv4Address newIPv4Instance(String ipv4AddressString) throws ParseException { if (ipv4AddressString == null || ipv4AddressString.length() == 0) { return null; } int slashPos = ipv4AddressString.indexOf('/'); int colonPos = ipv4AddressString.indexOf(':'); if ((colonPos >= 0) && (colonPos < slashPos)) { throw new ParseException(INVALID_IP4ADDRESS_MSG + ipv4AddressString + "\": out of order components", colonPos); } int endAddress = (slashPos >= 0 ? slashPos : (colonPos >= 0 ? colonPos : ipv4AddressString.length() )); if (endAddress < 7) { throw new ParseException(INVALID_IP4ADDRESS_MSG + ipv4AddressString + "\": address too short", 0); } short[] addressBytes = getAddress(ipv4AddressString.substring(0, endAddress)); short[] maskBytes = null; if (slashPos >= 0) { int endMask = (colonPos >= 0 ? colonPos : ipv4AddressString.length()); maskBytes = getAddress(ipv4AddressString.substring(slashPos+1, endMask)); } PortRange portRange = null; if (colonPos >= 0) { if (ipv4AddressString.substring(colonPos+1).length() < 1) { throw new ParseException(INVALID_IP4ADDRESS_MSG + ipv4AddressString + "\": no portrange given after ':'", colonPos+1); } portRange = PortRange.newInstance(ipv4AddressString.substring(colonPos+1)); } return new IPv4Address(addressBytes, maskBytes, portRange); } IPv4Address(short[] addressBytesIn, short[] addressMaskIn, PortRange portRangeIn); }
IPv4Address extends IPAddress { public static IPv4Address newIPv4Instance(String ipv4AddressString) throws ParseException { if (ipv4AddressString == null || ipv4AddressString.length() == 0) { return null; } int slashPos = ipv4AddressString.indexOf('/'); int colonPos = ipv4AddressString.indexOf(':'); if ((colonPos >= 0) && (colonPos < slashPos)) { throw new ParseException(INVALID_IP4ADDRESS_MSG + ipv4AddressString + "\": out of order components", colonPos); } int endAddress = (slashPos >= 0 ? slashPos : (colonPos >= 0 ? colonPos : ipv4AddressString.length() )); if (endAddress < 7) { throw new ParseException(INVALID_IP4ADDRESS_MSG + ipv4AddressString + "\": address too short", 0); } short[] addressBytes = getAddress(ipv4AddressString.substring(0, endAddress)); short[] maskBytes = null; if (slashPos >= 0) { int endMask = (colonPos >= 0 ? colonPos : ipv4AddressString.length()); maskBytes = getAddress(ipv4AddressString.substring(slashPos+1, endMask)); } PortRange portRange = null; if (colonPos >= 0) { if (ipv4AddressString.substring(colonPos+1).length() < 1) { throw new ParseException(INVALID_IP4ADDRESS_MSG + ipv4AddressString + "\": no portrange given after ':'", colonPos+1); } portRange = PortRange.newInstance(ipv4AddressString.substring(colonPos+1)); } return new IPv4Address(addressBytes, maskBytes, portRange); } IPv4Address(short[] addressBytesIn, short[] addressMaskIn, PortRange portRangeIn); static String formatAddress(short[] addressBytes); static IPv4Address newIPv4Instance(String ipv4AddressString); static boolean isIPv4Address(String ipv4AddressString); @Override String stringValue(); @Override String toString(); @Override boolean equals(Object obj); }
IPv4Address extends IPAddress { public static IPv4Address newIPv4Instance(String ipv4AddressString) throws ParseException { if (ipv4AddressString == null || ipv4AddressString.length() == 0) { return null; } int slashPos = ipv4AddressString.indexOf('/'); int colonPos = ipv4AddressString.indexOf(':'); if ((colonPos >= 0) && (colonPos < slashPos)) { throw new ParseException(INVALID_IP4ADDRESS_MSG + ipv4AddressString + "\": out of order components", colonPos); } int endAddress = (slashPos >= 0 ? slashPos : (colonPos >= 0 ? colonPos : ipv4AddressString.length() )); if (endAddress < 7) { throw new ParseException(INVALID_IP4ADDRESS_MSG + ipv4AddressString + "\": address too short", 0); } short[] addressBytes = getAddress(ipv4AddressString.substring(0, endAddress)); short[] maskBytes = null; if (slashPos >= 0) { int endMask = (colonPos >= 0 ? colonPos : ipv4AddressString.length()); maskBytes = getAddress(ipv4AddressString.substring(slashPos+1, endMask)); } PortRange portRange = null; if (colonPos >= 0) { if (ipv4AddressString.substring(colonPos+1).length() < 1) { throw new ParseException(INVALID_IP4ADDRESS_MSG + ipv4AddressString + "\": no portrange given after ':'", colonPos+1); } portRange = PortRange.newInstance(ipv4AddressString.substring(colonPos+1)); } return new IPv4Address(addressBytes, maskBytes, portRange); } IPv4Address(short[] addressBytesIn, short[] addressMaskIn, PortRange portRangeIn); static String formatAddress(short[] addressBytes); static IPv4Address newIPv4Instance(String ipv4AddressString); static boolean isIPv4Address(String ipv4AddressString); @Override String stringValue(); @Override String toString(); @Override boolean equals(Object obj);  }