Example usage for java.lang Long divideUnsigned

List of usage examples for java.lang Long divideUnsigned

Introduction

In this page you can find the example usage for java.lang Long divideUnsigned.

Prototype

public static long divideUnsigned(long dividend, long divisor) 

Source Link

Document

Returns the unsigned quotient of dividing the first argument by the second where each argument and the result is interpreted as an unsigned value.

Usage

From source file:org.apache.metron.pcap.mr.PcapJob.java

public <T> SequenceFileIterable query(Path basePath, Path baseOutputPath, long beginNS, long endNS,
        int numReducers, T fields, Configuration conf, FileSystem fs, PcapFilterConfigurator<T> filterImpl)
        throws IOException, ClassNotFoundException, InterruptedException {
    String fileName = Joiner.on("_").join(beginNS, endNS, filterImpl.queryToString(fields),
            UUID.randomUUID().toString());
    if (LOG.isDebugEnabled()) {
        DateFormat format = SimpleDateFormat.getDateTimeInstance(SimpleDateFormat.LONG, SimpleDateFormat.LONG);
        String from = format.format(new Date(Long.divideUnsigned(beginNS, 1000000)));
        String to = format.format(new Date(Long.divideUnsigned(endNS, 1000000)));
        LOG.debug("Executing query {} on timerange from {} to {}", filterImpl.queryToString(fields), from, to);
    }/* w  w w . ja v  a2s  .c o  m*/
    Path outputPath = new Path(baseOutputPath, fileName);
    Job job = createJob(basePath, outputPath, beginNS, endNS, numReducers, fields, conf, fs, filterImpl);
    if (job == null) {
        LOG.info("No files to process with specified date range.");
        return new SequenceFileIterable(new ArrayList<>(), conf);
    }
    boolean completed = job.waitForCompletion(true);
    if (completed) {
        return readResults(outputPath, conf, fs);
    } else {
        throw new RuntimeException(
                "Unable to complete query due to errors.  Please check logs for full errors.");
    }
}

From source file:org.apache.metron.pcap.mr.PcapJob.java

public static long findWidth(long start, long end, int numReducers) {
    return Long.divideUnsigned(end - start, numReducers) + 1;
}

From source file:org.apache.metron.utils.PcapInspector.java

public static void main(String... argv) throws IOException {
    Configuration conf = new Configuration();
    String[] otherArgs = new GenericOptionsParser(conf, argv).getRemainingArgs();
    CommandLine cli = InspectorOptions.parse(new PosixParser(), otherArgs);
    Path inputPath = new Path(InspectorOptions.INPUT.get(cli));
    int n = -1;/*  w w w.j a v a  2s. c o m*/
    if (InspectorOptions.NUM.has(cli)) {
        n = Integer.parseInt(InspectorOptions.NUM.get(cli));
    }
    SequenceFile.Reader reader = new SequenceFile.Reader(new Configuration(),
            SequenceFile.Reader.file(inputPath));
    LongWritable key = new LongWritable();
    BytesWritable value = new BytesWritable();

    for (int i = 0; (n < 0 || i < n) && reader.next(key, value); ++i) {
        long millis = Long.divideUnsigned(key.get(), 1000000);
        String ts = DATE_FORMAT.format(new Date(millis));
        for (PacketInfo pi : PcapHelper.toPacketInfo(value.copyBytes())) {
            EnumMap<Constants.Fields, Object> result = PcapHelper.packetToFields(pi);
            List<String> fieldResults = new ArrayList<String>() {
                {
                    add("TS: " + ts);
                }
            };
            for (Constants.Fields field : Constants.Fields.values()) {
                if (result.containsKey(field)) {
                    fieldResults.add(field.getName() + ": " + result.get(field));
                }
            }
            System.out.println(Joiner.on(",").join(fieldResults));
        }
    }
}