Class Util


  • public abstract class Util
    extends io.token.util.Util
    Utility methods.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static io.token.proto.common.alias.AliasProtos.Alias TOKEN
      The token alias.
      • Fields inherited from class io.token.util.Util

        TOKEN_REALM
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static io.token.proto.common.security.SecurityProtos.Key getSigningKey​(io.token.proto.common.member.MemberProtos.Member member, io.token.proto.common.security.SecurityProtos.Signature signature)
      Get the key corresponding to a signature.
      static java.util.Map<java.lang.String,​java.lang.String> parseQueryString​(java.lang.String queryString)
      Returns map of query string parameters, given a query string.
      static <T> T retryWithExponentialBackoff​(long timeoutMs, long waitTimeMs, double backOffFactor, long maxWaitTimeMs, java.util.concurrent.Callable<T> function, java.util.function.Predicate<T> retryIf)
      Repetitively run a function until the result of the function is acceptable (defined by retryIf predicate) or the total wait time exceeds the requested amount (timeoutMs).
      static <T> T retryWithExponentialBackoffNoThrow​(long timeoutMs, long waitTimeMs, double backOffFactor, long maxWaitTimeMs, java.util.concurrent.Callable<T> function, java.util.function.Predicate<T> retryIf)
      Repetitively run a function until the result of the function is acceptable (defined by retryIf predicate) or the total wait time exceeds the requested amount (timeoutMs).
      static java.lang.String urlDecode​(java.lang.String string)
      URL decodes a string.
      static java.lang.String urlEncode​(java.lang.String string)
      URL encodes a string.
      static void verifySignature​(io.token.proto.common.member.MemberProtos.Member member, com.google.protobuf.Message payload, io.token.proto.common.security.SecurityProtos.Signature signature)
      Verify the signature of the payload.
      • Methods inherited from class io.token.util.Util

        generateNonce, getWebAppUrl, hashString, toAddAliasOperation, toAddAliasOperationMetadata, toAddKeyOperation, toObservable, toRecoveryAgentOperation
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • TOKEN

        public static final io.token.proto.common.alias.AliasProtos.Alias TOKEN
        The token alias.
    • Method Detail

      • parseQueryString

        public static java.util.Map<java.lang.String,​java.lang.String> parseQueryString​(java.lang.String queryString)
        Returns map of query string parameters, given a query string.
        Parameters:
        queryString - query string
        Returns:
        map of parameters in query string
      • urlEncode

        public static java.lang.String urlEncode​(java.lang.String string)
        URL encodes a string.
        Parameters:
        string - to encode
        Returns:
        encoded string
      • urlDecode

        public static java.lang.String urlDecode​(java.lang.String string)
        URL decodes a string.
        Parameters:
        string - to decode
        Returns:
        decoded string
      • verifySignature

        public static void verifySignature​(io.token.proto.common.member.MemberProtos.Member member,
                                           com.google.protobuf.Message payload,
                                           io.token.proto.common.security.SecurityProtos.Signature signature)
        Verify the signature of the payload.
        Parameters:
        member - member
        payload - payload
        signature - signature
      • getSigningKey

        public static io.token.proto.common.security.SecurityProtos.Key getSigningKey​(io.token.proto.common.member.MemberProtos.Member member,
                                                                                      io.token.proto.common.security.SecurityProtos.Signature signature)
        Get the key corresponding to a signature.
        Parameters:
        member - member
        signature - signature
        Returns:
        signing key if member owns it.
      • retryWithExponentialBackoff

        public static <T> T retryWithExponentialBackoff​(long timeoutMs,
                                                        long waitTimeMs,
                                                        double backOffFactor,
                                                        long maxWaitTimeMs,
                                                        java.util.concurrent.Callable<T> function,
                                                        java.util.function.Predicate<T> retryIf)
                                                 throws java.lang.Exception
        Repetitively run a function until the result of the function is acceptable (defined by retryIf predicate) or the total wait time exceeds the requested amount (timeoutMs). Returns the last result of the function, acceptable or not (in the case of timeout).
        Type Parameters:
        T - the type of the esult of the function
        Parameters:
        timeoutMs - a maximum total waiting time between retries
        waitTimeMs - initial wait time before retry
        backOffFactor - a factor by which the wait time is multiplied after each retry
        maxWaitTimeMs - max wait time between retries
        function - function that should be called
        retryIf - a boolean function that checks the result of the function and returns true if need to retry
        Returns:
        last result of the function
        Throws:
        java.lang.Exception - whatever checked exceptions function throws
        java.lang.InterruptedException - if any thread has interrupted the current thread
        java.lang.IllegalArgumentException - if any of the time arguments or the backOffFactor is negative
      • retryWithExponentialBackoffNoThrow

        public static <T> T retryWithExponentialBackoffNoThrow​(long timeoutMs,
                                                               long waitTimeMs,
                                                               double backOffFactor,
                                                               long maxWaitTimeMs,
                                                               java.util.concurrent.Callable<T> function,
                                                               java.util.function.Predicate<T> retryIf)
                                                        throws java.lang.InterruptedException
        Repetitively run a function until the result of the function is acceptable (defined by retryIf predicate) or the total wait time exceeds the requested amount (timeoutMs). Returns the last result of the function, acceptable or not (in the case of timeout).

        To be used for functions that do not throw checked exceptions.
        Type Parameters:
        T - the type of the esult of the function
        Parameters:
        timeoutMs - a maximum total waiting time between retries
        waitTimeMs - initial wait time before retry
        backOffFactor - a factor by which the wait time is multiplied after each retry
        maxWaitTimeMs - max wait time between retries
        function - function that should be called
        retryIf - a boolean function that checks the result of the function and returns true if need to retry
        Returns:
        last result of the function
        Throws:
        java.lang.InterruptedException - if any thread has interrupted the current thread
        java.lang.IllegalArgumentException - if any of the time arguments or the backOffFactor is negative