public class ToolBox
extends java.lang.Object
| Modifier and Type | Field and Description |
|---|---|
static java.lang.String |
DEFAULT_TRUSTED_KEYSTORE_TYPE |
static java.lang.String |
DEFAUTL_TRUSTED_KEYSTORE_PROVIDER |
| 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.
|
public static final java.lang.String DEFAULT_TRUSTED_KEYSTORE_TYPE
public static final java.lang.String DEFAUTL_TRUSTED_KEYSTORE_PROVIDER
public static void checkHostAvailable(java.lang.String hostName,
int timeOut)
throws java.net.UnknownHostException
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.java.lang.IllegalArgumentException - if httpUrl is null.java.net.UnknownHostExceptionpublic 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
trustKeyStoreResource - identification of the resource to load.context - application context.java.lang.IllegalArgumentException - if context is null.java.security.NoSuchProviderExceptionjava.security.KeyStoreExceptionjava.security.cert.CertificateExceptionjava.security.NoSuchAlgorithmExceptionjava.io.IOExceptionpublic 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
trustKeyStoreResource - identification of the resource to load.keyStorePassword - password that protects the keystore.context - application context.java.lang.IllegalArgumentException - if context is null.java.security.NoSuchProviderExceptionjava.security.KeyStoreExceptionjava.security.cert.CertificateExceptionjava.security.NoSuchAlgorithmExceptionjava.io.IOExceptionpublic 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
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.java.lang.IllegalArgumentException - if context is null.java.security.NoSuchProviderExceptionjava.security.KeyStoreExceptionjava.security.cert.CertificateExceptionjava.security.NoSuchAlgorithmExceptionjava.io.IOExceptionpublic static java.lang.String getURLEncodedStringData(java.util.Map<java.lang.String,java.lang.String> params,
java.nio.charset.Charset charset)
throws java.io.IOException
params - charset - java.lang.IllegalArgumentException - if outputStream or urlEncodedparams or charset is null.java.io.IOExceptionpublic static void notNull(java.lang.Object... objects)
objects - Object list to validate.java.lang.IllegalArgumentExceptionpublic static byte[] streamToByteArray(java.io.InputStream inputStream)
throws java.io.IOException
inputStream - The stream to be read.java.lang.IllegalArgumentException - if inputStream is null.java.io.IOExceptionpublic static java.lang.String streamToString(java.io.InputStream inputStream)
throws java.io.IOException
inputStream - The stream to be read.java.lang.IllegalArgumentException - if inputStream is null.java.io.IOExceptionpublic static java.lang.String streamToString(java.io.InputStream inputStream,
java.nio.charset.Charset charset)
throws java.io.IOException
inputStream - The stream to be read.charset - java.lang.IllegalArgumentException - if inputStream or charset is null.java.io.IOExceptionpublic static void writePostDataToStream(java.io.OutputStream outputStream,
java.util.Map<java.lang.String,java.lang.String> params)
throws java.io.IOException
outputStream - The stream to write in.params - The parameters to write.java.lang.IllegalArgumentException - if outputStream or params or charset is null.java.io.UnsupportedEncodingExceptionjava.io.IOExceptionpublic 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
outputStream - The stream to write in.params - The parameters to write.charset - The encoded format of the string built.java.lang.IllegalArgumentException - if outputStream or params or charset is null.java.io.UnsupportedEncodingExceptionjava.io.IOExceptionpublic static void writePostDataToStream(java.io.OutputStream outputStream,
java.lang.String urlEncodedparams)
throws java.io.IOException
outputStream - The stream to write in.urlEncodedparams - The URL encoded string with the parameters to send.java.lang.IllegalArgumentException - if outputStream or params or charset is null.java.io.UnsupportedEncodingExceptionjava.io.IOExceptionpublic static void writePostDataToStream(java.io.OutputStream outputStream,
java.lang.String urlEncodedparams,
java.nio.charset.Charset charset)
throws java.io.UnsupportedEncodingException,
java.io.IOException
outputStream - The stream to write in.urlEncodedparams - The URL encoded string with the parameters to send.charset - java.lang.IllegalArgumentException - if outputStream or urlEncodedparams or charset is null.java.io.UnsupportedEncodingExceptionjava.io.IOException