Code example for DataInput

Methods: readByte

0
    setSize(origSize);
  } 
 
  @Override 
  public void readFields(DataInput in) throws IOException {
    super.readFields(in);
    setType(in.readByte());
    if (REDUCE_SPEC == getType()) {
      spec.readFields(in);
    } 
  } 
  @Override 
  public void write(DataOutput out) throws IOException {
    super.write(out);
    final byte t = getType();
    out.writeByte(t);
    if (REDUCE_SPEC == t) {
      spec.write(out);
    } 
  } 
  int fixedBytes() { 
    return super.fixedBytes() + 
      (REDUCE_SPEC == getType() ? spec.getSize() : 0) + META_BYTES;
  } 
  @Override 
  public int compareTo(GridmixRecord other) {
    final GridmixKey o = (GridmixKey) other;
    final byte t1 = getType();
    final byte t2 = o.getType();
    if (t1 != t2) {
      return t1 - t2;
    } 
    return super.compareTo(other);
  } 
 
  /** 
   * Note that while the spec is not explicitly included, changing the spec 
   * may change its size, which will affect equality. 
   */ 
  @Override 
  public boolean equals(Object other) {
    if (this == other) {
      return true; 
    } 
    if (other != null && other.getClass() == getClass()) {
      final GridmixKey o = ((GridmixKey)other);
      return getType() == o.getType() && super.equals(o);
    } 
    return false; 
  } 
 
  @Override 
  public int hashCode() { 
    return super.hashCode() ^ getType(); 
  } 
 
  public static class Spec implements Writable { 
    long rec_in;
    long rec_out;
    long bytes_out;
    public Spec() { } 
 
    public void set(Spec other) {
      rec_in = other.rec_in;
      bytes_out = other.bytes_out;
      rec_out = other.rec_out;
    } 
 
    public int getSize() { 
      return WritableUtils.getVIntSize(rec_in) +
             WritableUtils.getVIntSize(rec_out) +
             WritableUtils.getVIntSize(bytes_out);
    } 
 
    @Override 
    public void readFields(DataInput in) throws IOException {
      rec_in = WritableUtils.readVLong(in);
      rec_out = WritableUtils.readVLong(in);
      bytes_out = WritableUtils.readVLong(in);
    } 
 
    @Override 
    public void write(DataOutput out) throws IOException {
      WritableUtils.writeVLong(out, rec_in);