标签:
import java.io.DataInput; import java.io.DataOutput; import java.io.IOException; /** * Created by user on 16/3/17. */ public interface Writable { void write(DataOutput out) throws IOException; void readFields(DataInput in) throws IOException; }
IntWritable writable = new IntWritable(163);
public static byte[] serialize(Writable writable) throws IOException { ByteArrayOutputStream out = new ByteArrayOutputStream(); DataOutputStream dataOut = new DataOutputStream(out); writable.write(dataOut); dataOut.close(); return out.toByteArray(); }
public static byte[] deserialize(Writable writable,byte[] bytes) throws IOException{ ByteArrayInputStream in = new ByteArrayInputStream(bytes); DataInputStream dataIn = new DataInputStream(in); writable.readFields(dataIn); dataIn.close(); return bytes; }
public interface WritableComparable<T> extends Writable,Comparable<T> {} public interface RawComparator<T> extends Comparable<T> { public int compare(byte[] b1,int s1, int l1, byte[] b2, int s2, int l2); }
标签:
原文地址:http://www.cnblogs.com/dalu610/p/5286770.html