Changeset b35762b


Ignore:
Timestamp:
Mar 27, 2019 1:24:55 PM (17 months ago)
Author:
zab2 <zab2@…>
Branches:
master
Children:
c777109
Parents:
3f6fc7c
Message:

factory to rule them all

Location:
apps/i2ptunnel/java/src/net/i2p/i2ptunnel/access
Files:
1 added
1 edited

Legend:

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

    r3f6fc7c rb35762b  
    11package net.i2p.i2ptunnel.access;
    2 
    3 import java.io.File;
    4 import java.io.FileReader;
    5 import java.io.BufferedReader;
    6 import java.io.IOException;
    72
    83import java.util.List;
    94import java.util.ArrayList;
    105
     6import java.io.File;
     7
    118class DefinitionParser {
    129
    13     static FilterDefinition parse(File f) throws IOException, InvalidDefinitionException {
     10    static FilterDefinition parse(String []definition) throws InvalidDefinitionException {
    1411       
    1512        DefinitionBuilder builder = new DefinitionBuilder();
    1613
    17         BufferedReader reader = new BufferedReader(new FileReader(f));
    18         try {
    19             String line;
    20             while((line = reader.readLine()) != null) {
    21                 line = line.trim();
    22                 if (line.isEmpty())
    23                     continue;
    24                 if (line.startsWith("#"))
    25                     continue;
    26 
    27                 String [] split = line.split(" \t");
    28                 split[0] = split[0].toLowerCase();
    29                 if ("default".equals(split[0]))
    30                     builder.setDefaultThreshold(parseThreshold(line.substring(7).trim()));
    31                 else if ("recorder".equals(split[0]))
    32                     builder.addRecorder(parseRecorder(line.substring(8).trim()));
    33                 else
    34                     builder.addElement(parseElement(line));
    35             }
    36         } finally {
    37             if (reader != null) try { reader.close(); } catch (IOException ignored) {}
     14        for (String line : definition) {
     15            String [] split = line.split(" \t");
     16            split[0] = split[0].toLowerCase();
     17            if ("default".equals(split[0]))
     18                builder.setDefaultThreshold(parseThreshold(line.substring(7).trim()));
     19            else if ("recorder".equals(split[0]))
     20                builder.addRecorder(parseRecorder(line.substring(8).trim()));
     21            else
     22                builder.addElement(parseElement(line));
    3823        }
    3924
Note: See TracChangeset for help on using the changeset viewer.