List of usage examples for com.google.common.primitives UnsignedLong fromLongBits
public static UnsignedLong fromLongBits(long bits)
From source file:com.facebook.buck.macho.NlistUtils.java
/** * Reads Nlist entry for the given architecture from the buffer at the current position. * @param buffer ByteBuffer with data, must be positioned properly. * @param is64Bit Indicator if architecture is 32 or 64 bits. * @return Nlist entry/*from w w w.j av a2 s . co m*/ */ public static Nlist createFromBuffer(ByteBuffer buffer, boolean is64Bit) { return Nlist.of(buffer.position(), UnsignedInteger.fromIntBits(buffer.getInt()), UnsignedInteger.fromIntBits(buffer.get() & 0xFF), UnsignedInteger.fromIntBits(buffer.get() & 0xFF), UnsignedInteger.fromIntBits(buffer.getShort() & 0xFFFF), UnsignedLong.fromLongBits(is64Bit ? buffer.getLong() : buffer.getInt() & 0xFFFFFFFFL)); }
From source file:org.opennms.newts.api.ValueType.java
public static ValueType<?> compose(Number number, MetricType type) { switch (type) { case ABSOLUTE: return new Absolute(UnsignedLong.fromLongBits(number.longValue())); case COUNTER: return new Counter(UnsignedLong.fromLongBits(number.longValue())); case DERIVE://www. j av a 2 s . c o m return new Derive(UnsignedLong.fromLongBits(number.longValue())); case GAUGE: return new Gauge(number.doubleValue()); default: throw new IllegalArgumentException(String.format("Unknown metric type: %s", type)); } }
From source file:com.facebook.buck.macho.SectionUtils.java
/** * Creates a section for the given architecture by reading the provided byte buffer from its * current position.//from ww w. j a va2 s . co m * @param buffer Buffer with data, must be positioned properly. * @param is64Bit Indicator if architecture is 64 or 32 bit. * @return Section object */ public static Section createFromBuffer(ByteBuffer buffer, boolean is64Bit, NulTerminatedCharsetDecoder decoder) throws CharacterCodingException { int offset = buffer.position(); String sectname = decoder.decodeString(buffer); buffer.position(offset + Section.LENGTH_OF_STRING_FIELDS_IN_BYTES); String segname = decoder.decodeString(buffer); buffer.position(offset + Section.LENGTH_OF_STRING_FIELDS_IN_BYTES * 2); return Section.of(offset, sectname, segname, UnsignedLong.fromLongBits(is64Bit ? buffer.getLong() : buffer.getInt() & 0xFFFFFFFFL), UnsignedLong.fromLongBits(is64Bit ? buffer.getLong() : buffer.getInt() & 0xFFFFFFFFL), UnsignedInteger.fromIntBits(buffer.getInt()), UnsignedInteger.fromIntBits(buffer.getInt()), UnsignedInteger.fromIntBits(buffer.getInt()), UnsignedInteger.fromIntBits(buffer.getInt()), UnsignedInteger.fromIntBits(buffer.getInt()), UnsignedInteger.fromIntBits(buffer.getInt()), UnsignedInteger.fromIntBits(buffer.getInt()), is64Bit ? Optional.of(UnsignedInteger.fromIntBits(buffer.getInt())) : Optional.empty()); }
From source file:org.opennms.newts.api.Counter.java
public Counter(long value) { this(UnsignedLong.fromLongBits(value)); }
From source file:com.google.cloud.trace.service.AppEngineSpanContextHandle.java
private static SpanContext getSpanContext(CloudTraceContext cloudTraceContext) { if (cloudTraceContext == null) { return new SpanContext(TraceId.invalid(), SpanId.invalid(), new TraceOptions()); }/*from w w w.j av a 2 s .co m*/ try { // Extract the trace ID from the binary protobuf CloudTraceContext#traceId. TraceIdProto traceIdProto = TraceIdProto.parseFrom(cloudTraceContext.getTraceId()); BigInteger traceIdHi = UnsignedLong.fromLongBits(traceIdProto.getHi()).bigIntegerValue(); BigInteger traceIdLo = UnsignedLong.fromLongBits(traceIdProto.getLo()).bigIntegerValue(); BigInteger traceId = traceIdHi.shiftLeft(64).or(traceIdLo); return new SpanContext(new TraceId(traceId), new SpanId(cloudTraceContext.getSpanId()), new TraceOptions((int) cloudTraceContext.getTraceMask())); } catch (InvalidProtocolBufferException e) { throw Throwables.propagate(e); } }
From source file:c1c.v8fs.Attributes.java
private byte[] codeDateTime(Date dateTime) { Calendar cal = Calendar.getInstance(); cal.setTime(dateTime);/*w ww .j av a 2 s .c o m*/ BigInteger divCn = new BigInteger("10"); long val = cal.getTimeInMillis(); byte[] res = UnsignedLong.fromLongBits(val).bigIntegerValue().multiply(divCn).toByteArray(); //ArrayUtils.reverse(res); cal.add(cal.YEAR, 1969); return res; }
From source file:org.onos.yangtools.util.SynchronizedDurationStatsTracker.java
@Override public synchronized double getAverageDuration() { return durationCount == 0 ? 0 : UnsignedLong.fromLongBits(durationSum).doubleValue() / durationCount; }
From source file:com.dianping.puma.parser.mysql.event.IntVarEvent.java
@Override public void doParse(ByteBuffer buf, PumaContext context) throws IOException { type = buf.get();/*www.j av a2 s . c o m*/ value = UnsignedLong.fromLongBits(PacketUtils.readLong(buf, 8)); }
From source file:org.opennms.newts.api.ValueType.java
public static ValueType<?> compose(ByteBuffer data) { ByteBuffer buffer = data.duplicate(); MetricType type = MetricType.fromCode(buffer.get()); switch (type) { case ABSOLUTE: return new Absolute(UnsignedLong.fromLongBits(buffer.getLong())); case COUNTER: return new Counter(UnsignedLong.fromLongBits(buffer.getLong())); case DERIVE:// w w w. j av a2 s . co m return new Derive(UnsignedLong.fromLongBits(buffer.getLong())); case GAUGE: return new Gauge(buffer.getDouble()); default: throw new IllegalArgumentException(String.format("Unknown metric type: %s", type)); } }
From source file:org.opendaylight.controller.cluster.datastore.utils.UnsignedLongRangeSet.java
public void add(final long longBits) { add(UnsignedLong.fromLongBits(longBits)); }