Example usage for com.google.common.primitives UnsignedInteger intValue

List of usage examples for com.google.common.primitives UnsignedInteger intValue

Introduction

In this page you can find the example usage for com.google.common.primitives UnsignedInteger intValue.

Prototype

@Override
public int intValue() 

Source Link

Document

Returns the value of this UnsignedInteger as an int .

Usage

From source file:org.opendaylight.protocol.bgp.rib.impl.RouterIds.java

public static PeerId createPeerId(@Nonnull final UnsignedInteger intAddress) {
    final String inet4Address = InetAddresses.fromInteger(intAddress.intValue()).getHostAddress();
    return new PeerId(BGP_PREFIX.concat(inet4Address));
}

From source file:org.apache.nifi.processors.evtx.parser.NumberUtil.java

/**
 * Throws an exception if the UnsignedInteger is greater than a given int, returning the int value otherwise
 *
 * @param unsignedInteger the number//from  ww w  .  j a  va2s . com
 * @param max             the maximum value
 * @param errorMessage    error message (can be Java format string)
 * @param args            args for error message format string
 * @return the value
 * @throws IOException if the value is greater than max
 */
public static int intValueMax(UnsignedInteger unsignedInteger, int max, String errorMessage, Object... args)
        throws IOException {
    if (unsignedInteger.compareTo(UnsignedInteger.valueOf(max)) > 0) {
        throw createException(errorMessage, args, "< " + max, unsignedInteger);
    }
    return unsignedInteger.intValue();
}

From source file:org.apache.nifi.processors.evtx.parser.bxml.value.BooleanTypeNode.java

public BooleanTypeNode(BinaryReader binaryReader, ChunkHeader chunkHeader, BxmlNode parent, int length)
        throws IOException {
    super(binaryReader, chunkHeader, parent, length);
    UnsignedInteger unsignedInteger = binaryReader.readDWord();
    value = unsignedInteger.intValue() > 0;
}

From source file:org.apache.nifi.processors.evtx.parser.bxml.value.FloatTypeNode.java

public FloatTypeNode(BinaryReader binaryReader, ChunkHeader chunkHeader, BxmlNode parent, int length)
        throws IOException {
    super(binaryReader, chunkHeader, parent, length);
    UnsignedInteger unsignedInteger = binaryReader.readDWord();
    value = Float.intBitsToFloat(unsignedInteger.intValue());
}

From source file:org.calrissian.mango.types.encoders.lexi.UnsignedIntegerEncoder.java

@Override
public String encode(UnsignedInteger value) {
    checkNotNull(value, "Null values are not allowed");
    return encodeUInt(value.intValue());
}

From source file:org.calrissian.mango.types.encoders.lexi.UnsignedIntegerReverseEncoder.java

@Override
public String encode(UnsignedInteger value) {
    checkNotNull(value, "Null values are not allowed");
    return encodeUInt(~value.intValue());
}

From source file:com.lyndir.masterpassword.impl.MPAlgorithmV0.java

@Override
public byte[] toBytes(final UnsignedInteger number) {
    return ByteBuffer.allocate(Integer.SIZE / Byte.SIZE).order(mpw_byteOrder()).putInt(number.intValue())
            .array();/*from w  w  w .  j a v a  2 s  .  com*/
}

From source file:se.sics.caracaldb.Key.java

public Key(UnsignedInteger num) {
    this(num.intValue());
}

From source file:com.spotify.crtauth.CrtAuthServer.java

/**
 * Given the response to a previous challenge, produce a token used by the client to authenticate.
 *
 * @param response The client's response to the initial challenge.
 * @return A token used to authenticate subsequent requests.
 * @throws InvalidInputException//from w ww  .  java 2 s.c  o m
 */
public String createToken(String response) throws InvalidInputException {
    final Response decodedResponse;
    final Challenge challenge;
    try {
        decodedResponse = CrtAuthCodec.deserializeResponse(decode(response));
        challenge = CrtAuthCodec.deserializeChallengeAuthenticated(decodedResponse.getPayload(), secret);
    } catch (DeserializationException e) {
        throw new InvalidInputException(e);
    }

    if (!challenge.getServerName().equals(serverName)) {
        throw new InvalidInputException("Got challenge with the wrong server_name encoded.");
    }
    PublicKey publicKey;
    try {
        publicKey = keyProvider.getKey(challenge.getUserName());
    } catch (KeyNotFoundException e) {
        // If the user requesting authentication doesn't have a public key,  we throw an
        // InvalidInputException. This normally shouldn't happen, since at this stage a challenge
        // should have already been sent, which in turn requires knowledge of the user's public key.
        throw new InvalidInputException(e);
    }
    boolean signatureVerified = false;
    try {
        Signature signature = Signature.getInstance(SIGNATURE_ALGORITHM);
        signature.initVerify(publicKey);
        signature.update(decodedResponse.getPayload());
        signatureVerified = signature.verify(decodedResponse.getSignature());
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    if (!signatureVerified) {
        throw new InvalidInputException("Client did not provide proof that it controls the secret " + "key.");
    }
    if (challenge.isExpired(timeSupplier)) {
        throw new InvalidInputException("The challenge is out of its validity period");
    }
    UnsignedInteger validFrom = timeSupplier.getTime().minus(CLOCK_FUDGE);
    UnsignedInteger validTo = timeSupplier.getTime().plus(tokenLifetimeInS);
    Token token = new Token(validFrom.intValue(), validTo.intValue(), challenge.getUserName());
    try {
        return encode(CrtAuthCodec.serialize(token, secret));
    } catch (SerializationException e) {
        throw new RuntimeException(e);
    }
}