code: public static int decode(byte[] src, int srcOffset, byte[][] valueRef)
          throws CorruptEncodingException
      {
          try {
              final int originalOffset = srcOffset;
  
              int b = src[srcOffset++] & 0xff;
              if (b >= 0xf8) {
                  valueRef[0] = null;
                  return 1;
              }
  
              int valueLength;
              if (b <= 0x7f) {
                  valueLength = b;
              } else if (b <= 0xbf) {
                  valueLength = ((b & 0x3f) << 8) | (src[srcOffset++] & 0xff);
              } else if (b <= 0xdf) {
                  valueLength = ((b & 0x1f) << 16) | ((src[srcOffset++] & 0xff) << 8) |
                      (src[srcOffset++] & 0xff);
              } else if (b <= 0xef) {
                  valueLength = ((b & 0x0f) << 24) | ((src[srcOffset++] & 0xff) << 16) |
                      ((src[srcOffset++] & 0xff) << 8) | (src[srcOffset++] & 0xff);
              } else {
                  valueLength = ((src[srcOffset++] & 0xff) << 24) |
                      ((src[srcOffset++] & 0xff) << 16) |
                      ((src[srcOffset++] & 0xff) << 8) | (src[srcOffset++] & 0xff);
              }
  
              if (valueLength == 0) {
                  valueRef[0] = EMPTY_BYTE_ARRAY;
              } else {
                  byte[] value = new byte[valueLength];
                  System.arraycopy(src, srcOffset, value, 0, valueLength);
                  valueRef[0]= value;
              }
  
              return srcOffset - originalOffset + valueLength;
          } catch (IndexOutOfBoundsException e) {
              throw new CorruptEncodingException(null, e);
          }
      }
docs: Decodes the given byte array.
  
  @param src source of encoded data
  @param srcOffset offset into encoded data
  @param valueRef decoded byte array is stored in element 0, which may be null
  @return amount of bytes read from source
  @throws CorruptEncodingException if source data is corrupt