hadoop示例代碼
IntWritable writable = new IntWritable();
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
DataOutputStream dataOutputStream = new DataOutputStream(byteArrayOutputStream);
writable.write(dataOutputStream);
dataOutputStream.close();
byte[] bytes = byteArrayOutputStream.toByteArray();
System.out.println(StringUtils.byteToHexString(bytes));
//解序列化
ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(bytes);
DataInputStream input = new DataInputStream(byteArrayInputStream);
IntWritable intWritable = new IntWritable();
intWritable.readFields(input);
input.close();
System.out.println(intWritable);
IntWritable int1 = new IntWritable();
IntWritable int2 = new IntWritable();
RawComparator<IntWritable> comparator = WritableComparator.get(IntWritable.class);
System.out.println(comparator.compare(int1,int2));
//也可以直接比較位元組流,不需要反序列化,問題是怎麼定位這個位元組流呢
System.out.println(comparator.compare(byte[] b1, int s1, int l1, byte[] b2, int s2, int l2));