TextMapCodec implements Codec<TextMap> { static JaegerSpanContext contextFromString(String value) throws MalformedTracerStateStringException, EmptyTracerStateStringException { if (value == null || value.equals("")) { throw new EmptyTracerStateStringException(); } String[] parts = value.split(":"); if (parts.length != 4) { throw new MalformedTracerStateStringException(value); } String traceId = parts[0]; if (traceId.length() > 32 || traceId.length() < 1) { throw new TraceIdOutOfBoundException("Trace id [" + traceId + "] length is not withing 1 and 32"); } return new JaegerSpanContext( high(traceId), new BigInteger(traceId, 16).longValue(), new BigInteger(parts[1], 16).longValue(), new BigInteger(parts[2], 16).longValue(), new BigInteger(parts[3], 16).byteValue()); } TextMapCodec(boolean urlEncoding); private  TextMapCodec(Builder builder); static String contextAsString(JaegerSpanContext context); @Override void inject(JaegerSpanContext spanContext, TextMap carrier); @Override JaegerSpanContext extract(TextMap carrier); @Override String toString(); static Builder builder();  }
@Test(expected = MalformedTracerStateStringException.class) public void testContextFromStringMalformedException() throws Exception { TextMapCodec.contextFromString("ff:ff:ff"); }
@Test(expected = EmptyTracerStateStringException.class) public void testContextFromStringEmptyException() throws Exception { TextMapCodec.contextFromString(""); }
@Test(expected = TraceIdOutOfBoundException.class) public void testContextFromStringTraceIdOutOfBoundExceptionTooBig() { TextMapCodec.contextFromString("123456789012345678901234567890123:ff:ff:ff"); }
@Test(expected = TraceIdOutOfBoundException.class) public void testContextFromStringTraceIdOutOfBoundExceptionToSmall() { TextMapCodec.contextFromString(":ff:ff:ff"); }
@Test public void testContextFromString() throws Exception { JaegerSpanContext context = TextMapCodec.contextFromString("ff:dd:cc:4"); assertEquals(context.getTraceIdLow(), 255L); assertEquals(context.getTraceIdHigh(), 0L); assertEquals(context.getSpanId(), 221L); assertEquals(context.getParentId(), 204L); assertEquals(context.getFlags(), 4); }
@Test public void testContextFromStringWith128BitTraceId() { JaegerSpanContext context = TextMapCodec.contextFromString("100000000000000ff:dd:cc:4"); assertEquals(context.getTraceIdLow(), 255L); assertEquals(context.getTraceIdHigh(), 1L); assertEquals(context.getSpanId(), 221L); assertEquals(context.getParentId(), 204L); assertEquals(context.getFlags(), 4); }