Example usage for com.google.common.primitives UnsignedLongs parseUnsignedLong

List of usage examples for com.google.common.primitives UnsignedLongs parseUnsignedLong

Introduction

In this page you can find the example usage for com.google.common.primitives UnsignedLongs parseUnsignedLong.

Prototype

public static long parseUnsignedLong(String s, int radix) 

Source Link

Document

Returns the unsigned long value represented by a string with the given radix.

Usage

From source file:org.onlab.util.Tools.java

/**
 * Converts a string from hex to long.//from   w  w  w .jav a 2 s .  c o m
 *
 * @param string hex number in string form; sans 0x
 * @return long value
 */
public static long fromHex(String string) {
    return UnsignedLongs.parseUnsignedLong(string, 16);
}

From source file:io.opencensus.contrib.http.util.CloudTraceFormat.java

@Override
public <C /*>>> extends @NonNull Object*/> SpanContext extract(C carrier, Getter<C> getter)
        throws SpanContextParseException {
    checkNotNull(carrier, "carrier");
    checkNotNull(getter, "getter");
    try {/*w  w w  .j  a  v a 2  s . c o  m*/
        String headerStr = getter.get(carrier, HEADER_NAME);
        if (headerStr == null || headerStr.length() < MIN_HEADER_SIZE) {
            throw new SpanContextParseException("Missing or too short header: " + HEADER_NAME);
        }
        checkArgument(headerStr.charAt(TRACE_ID_SIZE) == SPAN_ID_DELIMITER, "Invalid TRACE_ID size");

        TraceId traceId = TraceId.fromLowerBase16(headerStr.subSequence(0, TRACE_ID_SIZE));
        int traceOptionsPos = headerStr.indexOf(TRACE_OPTION_DELIMITER, TRACE_ID_SIZE);
        CharSequence spanIdStr = headerStr.subSequence(SPAN_ID_START_POS,
                traceOptionsPos < 0 ? headerStr.length() : traceOptionsPos);
        SpanId spanId = longToSpanId(UnsignedLongs.parseUnsignedLong(spanIdStr.toString(), 10));
        TraceOptions traceOptions = OPTIONS_NOT_SAMPLED;
        if (traceOptionsPos > 0) {
            String traceOptionsStr = headerStr.substring(traceOptionsPos + TRACE_OPTION_DELIMITER_SIZE);
            if ((UnsignedInts.parseUnsignedInt(traceOptionsStr, 10) & CLOUD_TRACE_IS_SAMPLED) != 0) {
                traceOptions = OPTIONS_SAMPLED;
            }
        }
        return SpanContext.create(traceId, spanId, traceOptions, TRACESTATE_DEFAULT);
    } catch (IllegalArgumentException e) {
        throw new SpanContextParseException("Invalid input", e);
    }
}