Search in sources :

Example 61 with Matcher

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);
}
Also used : Matcher(java.util.regex.Matcher) GdbParseException(org.eclipse.che.plugin.gdb.server.exception.GdbParseException)

Example 62 with Matcher

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);
}
Also used : Breakpoint(org.eclipse.che.api.debug.shared.model.Breakpoint) BreakpointImpl(org.eclipse.che.api.debug.shared.model.impl.BreakpointImpl) Matcher(java.util.regex.Matcher) ArrayList(java.util.ArrayList) LocationImpl(org.eclipse.che.api.debug.shared.model.impl.LocationImpl) Location(org.eclipse.che.api.debug.shared.model.Location)

Example 63 with Matcher

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;
}
Also used : Matcher(java.util.regex.Matcher)

Example 64 with Matcher

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;
}
Also used : Matcher(java.util.regex.Matcher)

Example 65 with Matcher

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;
}
Also used : Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher)

Aggregations

Matcher (java.util.regex.Matcher)12473 Pattern (java.util.regex.Pattern)5010 ArrayList (java.util.ArrayList)1516 IOException (java.io.IOException)904 HashMap (java.util.HashMap)565 File (java.io.File)487 Test (org.junit.Test)442 BufferedReader (java.io.BufferedReader)428 Map (java.util.Map)363 List (java.util.List)287 InputStreamReader (java.io.InputStreamReader)266 HashSet (java.util.HashSet)236 MalformedURLException (java.net.MalformedURLException)163 URL (java.net.URL)155 Date (java.util.Date)152 InputStream (java.io.InputStream)147 Field (java.lang.reflect.Field)130 PatternSyntaxException (java.util.regex.PatternSyntaxException)128 ParseException (java.text.ParseException)127 LinkedHashMap (java.util.LinkedHashMap)120