Github user cestella commented on a diff in the pull request:

    https://github.com/apache/incubator-metron/pull/119#discussion_r63102275
  
    --- Diff: 
metron-platform/metron-pcap/src/main/java/org/apache/metron/pcap/mr/PcapJob.java
 ---
    @@ -33,36 +33,39 @@
     import org.apache.hadoop.mapreduce.lib.input.SequenceFileInputFormat;
     import org.apache.hadoop.mapreduce.lib.output.SequenceFileOutputFormat;
     import org.apache.log4j.Logger;
    -import org.apache.metron.common.Constants;
     import org.apache.metron.pcap.PcapHelper;
    +import org.apache.metron.pcap.filter.PcapFilter;
    +import org.apache.metron.pcap.filter.PcapFilterConfigurator;
    +import org.apache.metron.pcap.filter.PcapFilters;
     
    -import javax.annotation.Nullable;
     import java.io.IOException;
     import java.text.DateFormat;
     import java.text.SimpleDateFormat;
     import java.util.*;
    +import java.util.stream.Collectors;
     
     public class PcapJob {
       private static final Logger LOG = Logger.getLogger(PcapJob.class);
    -
       public static class PcapMapper extends Mapper<LongWritable, 
BytesWritable, LongWritable, BytesWritable> {
         public static final String START_TS_CONF = "start_ts";
         public static final String END_TS_CONF = "end_ts";
         PcapFilter filter;
         long start;
         long end;
    +
         @Override
         protected void setup(Context context) throws IOException, 
InterruptedException {
           super.setup(context);
    -      filter = new PcapFilter(context.getConfiguration());
    +      filter = 
PcapFilters.valueOf(context.getConfiguration().get(PcapFilterConfigurator.PCAP_FILTER_NAME_CONF)).create();
    +      filter.configure(context.getConfiguration());
           start = 
Long.parseUnsignedLong(context.getConfiguration().get(START_TS_CONF));
           end = 
Long.parseUnsignedLong(context.getConfiguration().get(END_TS_CONF));
         }
     
         @Override
         protected void map(LongWritable key, BytesWritable value, Context 
context) throws IOException, InterruptedException {
           if(Long.compareUnsigned(key.get() ,start) >= 0 && 
Long.compareUnsigned(key.get(), end) <= 0) {
    -        boolean send = 
Iterables.size(Iterables.filter(PcapHelper.toPacketInfo(value.copyBytes()), 
filter)) > 0;
    +        boolean send = 
PcapHelper.toPacketInfo(value.copyBytes()).stream().filter(filter).collect(Collectors.toList()).size()
 > 0;
    --- End diff --
    
    It's also clearer of intent (not empty as opposed to size > 0)


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

Reply via email to