Code example for DataInput

Methods: readByte, readInt, readUnsignedByte, readUnsignedShort

0
   * @return the decoded long integer. 
   * @throws IOException 
   */ 
   
  public static long readVLong(DataInput in) throws IOException {
    int firstByte = in.readByte();
    if (firstByte >= -32) {
      return firstByte;
    } 
     
    switch ((firstByte + 128) / 8) {
      case 11: 
      case 10: 
      case 9: 
      case 8: 
      case 7: 
        return ((firstByte + 52) << 8) | in.readUnsignedByte();
      case 6: 
      case 5: 
      case 4: 
      case 3: 
        return ((firstByte + 88) << 16) | in.readUnsignedShort();
      case 2: 
      case 1: 
        return ((firstByte + 112) << 24) | (in.readUnsignedShort() << 8) | in.readUnsignedByte();
      case 0: 
        int len = firstByte + 129;
        switch (len) {
          case 4: 
            return in.readInt();
          case 5: 
            return ((long) in.readInt()) << 8 | in.readUnsignedByte();
          case 6: 
            return ((long) in.readInt()) << 16 | in.readUnsignedShort();
          case 7: 
            return ((long) in.readInt()) << 24 | (in.readUnsignedShort() << 8) | in.readUnsignedByte();
          case 8: 
            return in.readLong();
          default: 
            throw new IOException("Corrupted VLong encoding");
        }