Example usage for org.apache.hadoop.io WritableComparator compare

List of usage examples for org.apache.hadoop.io WritableComparator compare

Introduction

In this page you can find the example usage for org.apache.hadoop.io WritableComparator compare.

Prototype

@Override
public int compare(byte[] b1, int s1, int l1, byte[] b2, int s2, int l2) 

Source Link

Document

Optimization hook.

Usage

From source file:tl.lin.data.WritableComparatorTestHarness.java

License:Apache License

@SuppressWarnings("rawtypes")
public static int compare(WritableComparator comparator, WritableComparable obj1, WritableComparable obj2) {

    byte[] bytes1 = null, bytes2 = null;

    try {//from  w  w w. ja va2  s.co  m
        ByteArrayOutputStream bytesOut1 = new ByteArrayOutputStream();
        DataOutputStream dataOut1 = new DataOutputStream(bytesOut1);
        obj1.write(dataOut1);
        bytes1 = bytesOut1.toByteArray();

        ByteArrayOutputStream bytesOut2 = new ByteArrayOutputStream();
        DataOutputStream dataOut2 = new DataOutputStream(bytesOut2);
        obj2.write(dataOut2);
        bytes2 = bytesOut2.toByteArray();

    } catch (IOException e) {
        e.printStackTrace();
    }

    return comparator.compare(bytes1, 0, bytes1.length, bytes2, 0, bytes2.length);
}