@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) { // It is assumed that the passed BytesWritable value is always a *single* PacketInfo object. // Passing more than 1 // object will result in the whole set being passed through if any pass the filter. We // cannot serialize PacketInfo // objects back to byte arrays, otherwise we could support more than one packet. // Note: short-circuit findAny() func on stream boolean send = filteredPacketInfo(value).findAny().isPresent(); if (send) { context.write(key, value); } } }
public Iterable<String> getPaths(FileSystem fs, Path basePath, long begin, long end) throws IOException { List<String> ret = new ArrayList<>(); Iterator<Path> files = listFiles(fs, basePath).iterator(); /* The trick here is that we need a trailing left endpoint, because we only capture the start of the timeseries kept in the file. */ boolean isFirst = true; Path leftEndpoint = files.hasNext() ? files.next() : null; if (leftEndpoint == null) { return ret; } { Long ts = PcapHelper.getTimestamp(leftEndpoint.getName()); if (ts != null && Long.compareUnsigned(ts, begin) >= 0 && Long.compareUnsigned(ts, end) <= 0) { ret.add(leftEndpoint.toString()); isFirst = false; } } while (files.hasNext()) { Path p = files.next(); Long ts = PcapHelper.getTimestamp(p.getName()); if (ts != null && Long.compareUnsigned(ts, begin) >= 0 && Long.compareUnsigned(ts, end) <= 0) { if (isFirst && leftEndpoint != null) { ret.add(leftEndpoint.toString()); } if (isFirst) { isFirst = false; } ret.add(p.toString()); } else { leftEndpoint = p; } } if (LOG.isDebugEnabled()) { LOG.debug("Including files " + Joiner.on(",").join(ret)); } return ret; }