Changeset 3f6fc7c


Ignore:
Timestamp:
Mar 27, 2019 1:05:31 PM (17 months ago)
Author:
zab2 <zab2@…>
Branches:
master
Children:
b35762b
Parents:
670016e
Message:

wip on parser of filter definitions

File:
1 edited

Legend:

Unmodified
Added
Removed
  • apps/i2ptunnel/java/src/net/i2p/i2ptunnel/access/DefinitionParser.java

    r670016e r3f6fc7c  
    6565
    6666    private static Recorder parseRecorder(String line) throws InvalidDefinitionException {
     67        String thresholdString = extractThreshold(line);
     68
     69        Threshold threshold = parseThreshold(thresholdString);
     70
     71        String line2 = line.substring(thresholdString.length()).trim();
     72        if (line2.length() == 0)
     73            throw new InvalidDefinitionException("Invalid definition "+ line);
     74        File file = new File(line2);
     75        return new Recorder(file, threshold);
     76    }
     77
     78    private static String extractThreshold(String line) {
    6779        StringBuilder thresholdBuilder = new StringBuilder();
    6880        int i = 0;
     
    7284                break;
    7385            i++;
    74             thresholdBuilder.append(c); 
     86            thresholdBuilder.append(c);
    7587        }
    76 
    77         Threshold threshold = parseThreshold(thresholdBuilder.toString());
    78 
    79         line = line.substring(i);
    80         File file = new File(line);
    81         return new Recorder(file, threshold);
     88        return thresholdBuilder.toString();
    8289    }
    8390
    84     private static FilterDefinitionElement parseElement(String line) {
    85         // TODO: implement
    86         return null;
     91    private static FilterDefinitionElement parseElement(String line) throws InvalidDefinitionException {
     92        String thresholdString = extractThreshold(line);
     93        Threshold threshold = parseThreshold(thresholdString);
     94        String line2 = line.substring(thresholdString.length()).trim();
     95        String[] split = line2.split(" \t");
     96        if (split.length < 2)
     97            throw new InvalidDefinitionException("invalid definition "+line);
     98        if ("explicit".equalsIgnoreCase(split[0]))
     99            return new ExplicitFilterDefinitionElement(split[1], threshold);
     100        if ("file".equalsIgnoreCase(split[0])) {
     101            String line3 = line2.substring(4).trim();
     102            File file = new File(line3);
     103            return new FileFilterDefinitionElement(file, threshold);
     104        }
     105        throw new InvalidDefinitionException("invalid definition "+line);
    87106    }
    88107
Note: See TracChangeset for help on using the changeset viewer.