首页 > 学院 > 开发设计 > 正文

欢迎使用CSDN-markdown编辑器

2019-11-14 13:08:06
字体:
来源:转载
供稿:网友

hadoop示例代码

序列化和反序列化 IntWritable writable = new IntWritable(10); 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);writable对象的比较 IntWritable int1 = new IntWritable(1); IntWritable int2 = new IntWritable(3); 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));
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表