use of java.util.regex.Matcher in project che by eclipse.
the class GdbDirectory method parse.
/**
* Factory method.
*/
public static GdbDirectory parse(GdbOutput gdbOutput) throws GdbParseException {
String output = gdbOutput.getOutput();
Matcher matcher = GDB_DIRECTORY.matcher(output);
if (matcher.find()) {
String directory = matcher.group(1);
return new GdbDirectory(directory);
}
throw new GdbParseException(GdbDirectory.class, output);
}
use of java.util.regex.Matcher in project che by eclipse.
the class GdbInfoBreak method parse.
/**
* Factory method.
*/
public static GdbInfoBreak parse(GdbOutput gdbOutput) throws GdbParseException {
String output = gdbOutput.getOutput();
List<Breakpoint> breakpoints = new ArrayList<>();
for (String line : output.split("\n")) {
Matcher matcher = GDB_INFO_B.matcher(line);
if (matcher.find()) {
String file = matcher.group(2);
String lineNumber = matcher.group(3);
Location location = new LocationImpl(file, Integer.parseInt(lineNumber));
breakpoints.add(new BreakpointImpl(location));
}
}
return new GdbInfoBreak(breakpoints);
}
use of java.util.regex.Matcher in project jetty.project by eclipse.
the class DoSFilter method subnetMatch.
protected boolean subnetMatch(String subnetAddress, String address) {
Matcher cidrMatcher = CIDR_PATTERN.matcher(subnetAddress);
if (!cidrMatcher.matches())
return false;
String subnet = cidrMatcher.group(1);
int prefix;
try {
prefix = Integer.parseInt(cidrMatcher.group(2));
} catch (NumberFormatException x) {
LOG.info("Ignoring malformed CIDR address {}", subnetAddress);
return false;
}
byte[] subnetBytes = addressToBytes(subnet);
if (subnetBytes == null) {
LOG.info("Ignoring malformed CIDR address {}", subnetAddress);
return false;
}
byte[] addressBytes = addressToBytes(address);
if (addressBytes == null) {
LOG.info("Ignoring malformed remote address {}", address);
return false;
}
// Comparing IPv4 with IPv6 ?
int length = subnetBytes.length;
if (length != addressBytes.length)
return false;
byte[] mask = prefixToBytes(prefix, length);
for (int i = 0; i < length; ++i) {
if ((subnetBytes[i] & mask[i]) != (addressBytes[i] & mask[i]))
return false;
}
return true;
}
use of java.util.regex.Matcher in project jetty.project by eclipse.
the class DoSFilter method addressToBytes.
private byte[] addressToBytes(String address) {
Matcher ipv4Matcher = IPv4_PATTERN.matcher(address);
if (ipv4Matcher.matches()) {
byte[] result = new byte[4];
for (int i = 0; i < result.length; ++i) result[i] = Integer.valueOf(ipv4Matcher.group(i + 1)).byteValue();
return result;
} else {
Matcher ipv6Matcher = IPv6_PATTERN.matcher(address);
if (ipv6Matcher.matches()) {
byte[] result = new byte[16];
for (int i = 0; i < result.length; i += 2) {
int word = Integer.valueOf(ipv6Matcher.group(i / 2 + 1), 16);
result[i] = (byte) ((word & 0xFF00) >>> 8);
result[i + 1] = (byte) (word & 0xFF);
}
return result;
}
}
return null;
}
use of java.util.regex.Matcher in project jetty.project by eclipse.
the class DefaultServletTest method getHeaderValue.
private String getHeaderValue(String header, String response) {
Pattern pattern = Pattern.compile("[\\r\\n]" + header + "\\s*:\\s*(.*?)\\s*[\\r\\n]");
Matcher matcher = pattern.matcher(response);
if (matcher.find())
return matcher.group(1);
return null;
}
Aggregations