es.gob.fnmt.net.tool

## Class ToolBox

- java.lang.Object
- - es.gob.fnmt.net.tool.ToolBox

-     public class ToolBox
      extends java.lang.Object

  Class with miscellaneous functionality.

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static java.lang.String` | `DEFAULT_TRUSTED_KEYSTORE_TYPE`
    `static java.lang.String` | `DEFAUTL_TRUSTED_KEYSTORE_PROVIDER`

  - ### Method Summary

    All Methods Static Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `static void` | `checkHostAvailable(java.lang.String hostName, int timeOut)` Try to resolve the host in order to check if can be reached.
    `static java.security.KeyStore` | `getKeyStoreFromResource(int trustKeyStoreResource, android.content.Context context)` Build KeyStore object from resource.
    `static java.security.KeyStore` | `getKeyStoreFromResource(int trustKeyStoreResource, java.lang.String keyStorePassword, android.content.Context context)` Build KeyStore object from resource.
    `static java.security.KeyStore` | `getKeyStoreFromResource(int trustKeyStoreResource, java.lang.String keyStorePassword, java.lang.String keyStoreType, java.lang.String provider, android.content.Context context)` Build KeyStore object from resource.
    `static java.lang.String` | `getURLEncodedStringData(java.util.Map<java.lang.String,java.lang.String> params, java.nio.charset.Charset charset)` Get URL encoded string parameters.
    `static void` | `notNull(java.lang.Object... objects)` Check if any object in the list is null.
    `static byte[]` | `streamToByteArray(java.io.InputStream inputStream)` Read the input stream and return a byte array.
    `static java.lang.String` | `streamToString(java.io.InputStream inputStream)` Read the input stream and return a string encoded in 'UTF-8'.
    `static java.lang.String` | `streamToString(java.io.InputStream inputStream, java.nio.charset.Charset charset)` Read the input stream and return a string.
    `static void` | `writePostDataToStream(java.io.OutputStream outputStream, java.util.Map<java.lang.String,java.lang.String> params)` Write parameters in the output stream of the 'POST' request as 'UTF-8' URL encoded string.
    `static void` | `writePostDataToStream(java.io.OutputStream outputStream, java.util.Map<java.lang.String,java.lang.String> params, java.nio.charset.Charset charset)` Write parameters in the output stream of the 'POST' request.
    `static void` | `writePostDataToStream(java.io.OutputStream outputStream, java.lang.String urlEncodedparams)` Write parameters in the output stream of the 'POST' request.
    `static void` | `writePostDataToStream(java.io.OutputStream outputStream, java.lang.String urlEncodedparams, java.nio.charset.Charset charset)` Write parameters in the output stream of the 'POST' request.

    - ### Methods inherited from class java.lang.Object

      `equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### DEFAULT_TRUSTED_KEYSTORE_TYPE

          public static final java.lang.String DEFAULT_TRUSTED_KEYSTORE_TYPE

      See Also:
        Constant Field Values

    - #### DEFAUTL_TRUSTED_KEYSTORE_PROVIDER

          public static final java.lang.String DEFAUTL_TRUSTED_KEYSTORE_PROVIDER

      See Also:
        Constant Field Values

  - ### Method Detail

    - #### checkHostAvailable

          public static void checkHostAvailable(java.lang.String hostName,
                                                int timeOut)
                                         throws java.net.UnknownHostException

      Try to resolve the host in order to check if can be reached.
      Parameters:
        `hostName` - host to connect is DNS format such as "myhost.home.com".
        `timeOut` - max time in seconds waiting host response. If 0 then 10 sec is default value.
      Throws:
        `java.lang.IllegalArgumentException` - if `httpUrl` is `null`.
        `java.net.UnknownHostException`

    - #### getKeyStoreFromResource

          public static java.security.KeyStore getKeyStoreFromResource(int trustKeyStoreResource,
                                                                       android.content.Context context)
                                                                throws java.security.NoSuchProviderException,
                                                                       java.security.KeyStoreException,
                                                                       java.security.cert.CertificateException,
                                                                       java.security.NoSuchAlgorithmException,
                                                                       java.io.IOException

      Build KeyStore object from resource.
      Parameters:
        `trustKeyStoreResource` - identification of the resource to load.
        `context` - application context.
      Returns:
        KeyStore.
      Throws:
        `java.lang.IllegalArgumentException` - if `context` is `null`.
        `java.security.NoSuchProviderException`
        `java.security.KeyStoreException`
        `java.security.cert.CertificateException`
        `java.security.NoSuchAlgorithmException`
        `java.io.IOException`

    - #### getKeyStoreFromResource

          public static java.security.KeyStore getKeyStoreFromResource(int trustKeyStoreResource,
                                                                       java.lang.String keyStorePassword,
                                                                       android.content.Context context)
                                                                throws java.security.NoSuchProviderException,
                                                                       java.security.KeyStoreException,
                                                                       java.security.cert.CertificateException,
                                                                       java.security.NoSuchAlgorithmException,
                                                                       java.io.IOException

      Build KeyStore object from resource.
      Parameters:
        `trustKeyStoreResource` - identification of the resource to load.
        `keyStorePassword` - password that protects the keystore.
        `context` - application context.
      Returns:
        KeyStore instance.
      Throws:
        `java.lang.IllegalArgumentException` - if `context` is `null`.
        `java.security.NoSuchProviderException`
        `java.security.KeyStoreException`
        `java.security.cert.CertificateException`
        `java.security.NoSuchAlgorithmException`
        `java.io.IOException`

    - #### getKeyStoreFromResource

          public static java.security.KeyStore getKeyStoreFromResource(int trustKeyStoreResource,
                                                                       java.lang.String keyStorePassword,
                                                                       java.lang.String keyStoreType,
                                                                       java.lang.String provider,
                                                                       android.content.Context context)
                                                                throws java.security.NoSuchProviderException,
                                                                       java.security.KeyStoreException,
                                                                       java.security.cert.CertificateException,
                                                                       java.security.NoSuchAlgorithmException,
                                                                       java.io.IOException

      Build KeyStore object from resource.
      Parameters:
        `trustKeyStoreResource` - identification of the resource to load.
        `keyStorePassword` - password that protects the keystore.
        `keyStoreType` - type of the keystore to load ("JKS", "JCEKS", "BKS", "PKCS12", etc. More info at https://docs.oracle.com/javase/8/docs/technotes/guides/security/StandardNames.html#KeyStore).
        `provider` - provider use to load the keystore. Set null if default JCA Provider must be used.
        `context` - application context.
      Returns:
        KeyStore instance.
      Throws:
        `java.lang.IllegalArgumentException` - if `context` is `null`.
        `java.security.NoSuchProviderException`
        `java.security.KeyStoreException`
        `java.security.cert.CertificateException`
        `java.security.NoSuchAlgorithmException`
        `java.io.IOException`

    - #### getURLEncodedStringData

          public static java.lang.String getURLEncodedStringData(java.util.Map<java.lang.String,java.lang.String> params,
                                                                 java.nio.charset.Charset charset)
                                                          throws java.io.IOException

      Get URL encoded string parameters.
      Parameters:
        `params` -
        `charset` -
      Returns:
        The URL encoded string.
      Throws:
        `java.lang.IllegalArgumentException` - if `outputStream` or `urlEncodedparams` or `charset` is `null`.
        `java.io.IOException`

    - #### notNull

          public static void notNull(java.lang.Object... objects)

      Check if any object in the list is null.
      Parameters:
        `objects` - Object list to validate.
      Throws:
        `java.lang.IllegalArgumentException`

    - #### streamToByteArray

          public static byte[] streamToByteArray(java.io.InputStream inputStream)
                                          throws java.io.IOException

      Read the input stream and return a byte array.
      Parameters:
        `inputStream` - The stream to be read.
      Returns:
        The byte array built.
      Throws:
        `java.lang.IllegalArgumentException` - if `inputStream` is `null`.
        `java.io.IOException`

    - #### streamToString

          public static java.lang.String streamToString(java.io.InputStream inputStream)
                                                 throws java.io.IOException

      Read the input stream and return a string encoded in 'UTF-8'.
      Parameters:
        `inputStream` - The stream to be read.
      Returns:
        The string built.
      Throws:
        `java.lang.IllegalArgumentException` - if `inputStream` is `null`.
        `java.io.IOException`

    - #### streamToString

          public static java.lang.String streamToString(java.io.InputStream inputStream,
                                                        java.nio.charset.Charset charset)
                                                 throws java.io.IOException

      Read the input stream and return a string.
      Parameters:
        `inputStream` - The stream to be read.
        `charset` -
      Returns:
        The string built.
      Throws:
        `java.lang.IllegalArgumentException` - if `inputStream` or `charset` is `null`.
        `java.io.IOException`

    - #### writePostDataToStream

          public static void writePostDataToStream(java.io.OutputStream outputStream,
                                                   java.util.Map<java.lang.String,java.lang.String> params)
                                            throws java.io.IOException

      Write parameters in the output stream of the 'POST' request as 'UTF-8' URL encoded string.
      Parameters:
        `outputStream` - The stream to write in.
        `params` - The parameters to write.
      Throws:
        `java.lang.IllegalArgumentException` - if `outputStream` or `params` or `charset` is `null`.
        `java.io.UnsupportedEncodingException`
        `java.io.IOException`

    - #### writePostDataToStream

          public static void writePostDataToStream(java.io.OutputStream outputStream,
                                                   java.util.Map<java.lang.String,java.lang.String> params,
                                                   java.nio.charset.Charset charset)
                                            throws java.io.UnsupportedEncodingException,
                                                   java.io.IOException

      Write parameters in the output stream of the 'POST' request.
      Parameters:
        `outputStream` - The stream to write in.
        `params` - The parameters to write.
        `charset` - The encoded format of the string built.
      Throws:
        `java.lang.IllegalArgumentException` - if `outputStream` or `params` or `charset` is `null`.
        `java.io.UnsupportedEncodingException`
        `java.io.IOException`

    - #### writePostDataToStream

          public static void writePostDataToStream(java.io.OutputStream outputStream,
                                                   java.lang.String urlEncodedparams)
                                            throws java.io.IOException

      Write parameters in the output stream of the 'POST' request.
      Parameters:
        `outputStream` - The stream to write in.
        `urlEncodedparams` - The URL encoded string with the parameters to send.
      Throws:
        `java.lang.IllegalArgumentException` - if `outputStream` or `params` or `charset` is `null`.
        `java.io.UnsupportedEncodingException`
        `java.io.IOException`

    - #### writePostDataToStream

          public static void writePostDataToStream(java.io.OutputStream outputStream,
                                                   java.lang.String urlEncodedparams,
                                                   java.nio.charset.Charset charset)
                                            throws java.io.UnsupportedEncodingException,
                                                   java.io.IOException

      Write parameters in the output stream of the 'POST' request.
      Parameters:
        `outputStream` - The stream to write in.
        `urlEncodedparams` - The URL encoded string with the parameters to send.
        `charset` -
      Throws:
        `java.lang.IllegalArgumentException` - if `outputStream` or `urlEncodedparams` or `charset` is `null`.
        `java.io.UnsupportedEncodingException`
        `java.io.IOException`