public byte[] encodeVariantLong(long read){
  long value=(read << 1) ^ (read >> 63);
  ByteArrayOutputStream bytes=new ByteArrayOutputStream();
  while (true) {
    if ((value & ~0x7FL) == 0) {
      bytes.write((int)value);
      break;
    }
 else {
      bytes.write(((int)value & 0x7F) | 0x80);
      value>>>=7;
    }
  }
  return bytes.toByteArray();
}

public byte [ ] encodeVariantLong ( long read ) { long value = ( read << 1 ) ^ ( read > > 63 ) ; ByteArrayOutputStream bytes = new ByteArrayOutputStream ( ) ; while ( true ) { if ( ( value & ~ 0x7FL ) == 0 ) { bytes . write ( ( int ) value ) ; break ; } else { bytes . write ( ( ( int ) value & 0x7F ) | 0x80 ) ; value >>>= 7 ; } } return bytes . toByteArray ( ) ; }
encode a long number as variable length encoded byte array 1 . get equivalent unsigned long 2 . encode 7 bits at a time starting from lsb , set the highest bit if there is a next byte needed
