Pretty-prints a {@code long} into a fixed-width hexadecimal number.
@return A string of the form {@code 0x0123456789ABCDEF}.
761467
public static String hex(long v) {
        final byte[] buf = new byte[2 + 16];
        buf[0] = '0';
        buf[1] = 'x';
        int i = 2 + 16;
        do {
            buf[--i] = HEX[(int) v & 0x0F];
            v >>>= 4;
        } while (v != 0);
        for (/**/; i > 1; i--) {
            buf[i] = '0';
        }
        return new String(buf);
    }
255030
@Override
  public long readLong() throws IOException {
    byte[] longBytes = new byte[8];
    int i = in.read(longBytes);
    if (i < 8) {
      throw new EOFException();
    }
    longBytes[0] = (byte) (longBytes[0] ^ 0x80);

    long value = 0;
    for (int j = 0; j < longBytes.length; ++j) {
      value = (value << 8) + (longBytes[j] & 0xff);
    }
    return value;
  }
645532
public static String writeLong(Long value) {
		if (value==null) return null;
		
		return Long.toString(value);			
	}
160042
public String toHexString() {
        final int l = mValue.length;
        final char[] out = new char[l*2+2];
        out[0] = '0';
        out[1] = 'x';
        for( int i=0,j=2; i<l; i++ ){
            out[j++] = HEX_DIGITS[(0xF0 & mValue[i]) >>> 4];
            out[j++] = HEX_DIGITS[0x0F & mValue[i]];
        }
        String s = new String(out);
        return s;
    }
859076
private long toLong(byte[] data)
    {
        if (data == null || data.length != 8)
            return 0x0;
        // ----------
        return (long) (
        // (Below) convert to longs before shift because digits
        // are lost with ints beyond the 32-bit limit
        (long) (0xff & data[0]) << 56 | (long) (0xff & data[1]) << 48 | (long) (0xff & data[2]) << 40
                | (long) (0xff & data[3]) << 32 | (long) (0xff & data[4]) << 24 | (long) (0xff & data[5]) << 16
                | (long) (0xff & data[6]) << 8 | (long) (0xff & data[7]) << 0);
    }
969698
public static String formatNumber(long number) {
        String stringRepresentation = Long.toString(number);
        StringBuilder sb = new StringBuilder();
        int bound = stringRepresentation.length() - 1;
        String delimiter = ",";
        int counter = 0;
        for (int i = bound; i >= 0; i--) {
            char c = stringRepresentation.charAt(i);
            if (i != bound && counter % 3 == 0) {
                sb.append(delimiter);
            }
            sb.append(c);
            counter++;
        }
        return sb.reverse().toString();
    }
433763
private static String formatISO6709Long(final PointLocation pointLocation)
  {
    final Latitude latitude = pointLocation.getLatitude();
    final Longitude longitude = pointLocation.getLongitude();
    String string = formatLatitudeLong(latitude) +
                    formatLongitudeLong(longitude);
    final double altitude = pointLocation.getAltitude();
    string = string + formatAltitudeWithSign(altitude);
    final String crs = pointLocation.getCoordinateReferenceSystemIdentifier();
    string = string + formatCoordinateReferenceSystemIdentifier(crs);
    return string + "/";
  }
724703
public static long toLong(byte[] b) {
        return ((((long) b[7]) & 0xFF)
                + ((((long) b[6]) & 0xFF) << 8)
                + ((((long) b[5]) & 0xFF) << 16)
                + ((((long) b[4]) & 0xFF) << 24)
                + ((((long) b[3]) & 0xFF) << 32)
                + ((((long) b[2]) & 0xFF) << 40)
                + ((((long) b[1]) & 0xFF) << 48)
                + ((((long) b[0]) & 0xFF) << 56));
    }
468901
private static String unsignedToString(final long value) {
    if (value >= 0) {
      return Long.toString(value);
    } else {
      // Pull off the most-significant bit so that BigInteger doesn't think
      // the number is negative, then set it again using setBit().
      return BigInteger.valueOf(value & 0x7FFFFFFFFFFFFFFFL)
                       .setBit(63).toString();
    }
  }
1208949
public static int longToInt(long inLong) {

        if (inLong < Integer.MIN_VALUE) {
            return Integer.MIN_VALUE;
        }

        if (inLong > Integer.MAX_VALUE) {
            return Integer.MAX_VALUE;
        }

        return (int) inLong;
    }
469147
public static long toLongValue(String str) throws PageException {
	BigInteger bi = null;
	try {
	    bi = new BigInteger(str);

	}
	catch (Throwable t) {
	    ExceptionUtil.rethrowIfNecessary(t);
	}
	if (bi != null) {
	    if (bi.bitLength() < 64) return bi.longValue();
	    throw new ApplicationException("number [" + str + "] cannot be casted to a long value, number is to long (" + (bi.bitLength() + 1) + " bit)");
	}
	return (long) toDoubleValue(str);
    }
732865
@Override
  public long length() {
    //The length of a character string is the number of UTF-16 units (not the number of characters)
    long len = 0;
    int pos = offset;

    //set ASCII (<= 127 chars)
    for (; len < length && data[pos] >= 0; ) {
      len++;
      pos++;
    }

    //multi-bytes UTF-8
    while (pos < offset + length) {
      byte firstByte = data[pos++];
      if (firstByte < 0) {
        if (firstByte >> 5 != -2 || (firstByte & 30) == 0) {
          if (firstByte >> 4 == -2) {
            if (pos + 1 < offset + length) {
              pos += 2;
              len++;
            } else {
              throw new UncheckedIOException("invalid UTF8", new CharacterCodingException());
            }
          } else if (firstByte >> 3 != -2) {
            throw new UncheckedIOException("invalid UTF8", new CharacterCodingException());
          } else if (pos + 2 < offset + length) {
            pos += 3;
            len += 2;
          } else {
            //bad truncated UTF8
            pos += offset + length;
            len += 1;
          }
        } else {
          pos++;
          len++;
        }
      } else {
        len++;
      }
    }
    return len;
  }
1055841
public static long longFromBase64(String value) {
        int pos = 0;
        long longVal = base64Values[value.charAt(pos++)];
        int len = value.length();
        while (pos < len) {
            longVal <<= 6;
            longVal |= base64Values[value.charAt(pos++)];
        }
        return longVal;
    }
446846
public long getLong() {
		long v = 0;
		v |= ((getByte() & 0xFFL) << 56);
		v |= ((getByte() & 0xFFL) << 48);
		v |= ((getByte() & 0xFFL) << 40);
		v |= ((getByte() & 0xFFL) << 32);
		v |= ((getByte() & 0xFFL) << 24);
		v |= ((getByte() & 0xFFL) << 16);
		v |= ((getByte() & 0xFFL) << 8);
		v |= (getByte() & 0xFFL);
		return v;
	}
436167
public String getLongString()
    {
        String value = Wire.getLongString(needle, needle.position());
        forward(value.length() + 4);
        return value;
    }
585034
public static long toLongValue(Object o) throws PageException {
	if (o instanceof Boolean) return ((((Boolean) o).booleanValue()) ? 1L : 0L);
	else if (o instanceof Number) return (((Number) o).longValue());
	else if (o instanceof CharSequence) {
	    String str = o.toString();
	    try {
		return Long.parseLong(str);
	    }
	    catch (NumberFormatException nfe) {
		return (long) toDoubleValue(str);
	    }
	}
	else if (o instanceof Character) return (((Character) o).charValue());
	else if (o instanceof Castable) return (long) ((Castable) o).castToDoubleValue();
	else if (o instanceof ObjectWrap) return toLongValue(((ObjectWrap) o).getEmbededObject());

	throw new CasterException(o, "long");
    }
1260467
public long getVLong() {
		// org.apache.lucene.util.packed.BlockPackedReaderIterator
		long value = 0;
		for (int i = 0; i <= 64; i += 7) {
			final byte b = getByte();
			value |= ((b & 0x7FL) << i);
			if (b >= 0)
				return value;
		}
		return value;
	}