public abstract class CodingUtils extends Object
Some coding utilities for generating hashes, encoding and decoding.
| Modifier and Type | Method and Description |
|---|---|
static byte[] |
digestSilently(MessageDigest md,
byte[] bytes)
Calculates a hash value.
|
static byte[] |
digestSilently(MessageDigest md,
byte[] bytes,
InputStreamListener listener)
Calculates a hash value.
|
static byte[] |
digestSilently(MessageDigest md,
InputStream inputStream,
boolean closeInputStream)
Calculates a hash value.
|
static byte[] |
digestSilently(MessageDigest md,
InputStream inputStream,
boolean closeInputStream,
InputStreamListener listener)
Calculates a hash value.
|
static MessageDigest |
getMessageDigestSilently(String algorithm)
Returns a MessageDigest object that implements the specified digest
algorithm.
|
static MessageDigest |
getMessageDigestSilently(String algorithm,
Provider provider)
Returns a MessageDigest object that implements the specified digest
algorithm.
|
static MessageDigest |
getMessageDigestSilently(String algorithm,
String provider)
Returns a MessageDigest object that implements the specified digest
algorithm.
|
static byte[] |
toBytesSilently(String text,
Charset charset)
Encodes the specified string into a sequence of bytes using the named
charset, storing the result into a new byte array.
|
static byte[] |
toBytesSilently(String text,
String charsetName)
Encodes the specified string into a sequence of bytes using the named
charset, storing the result into a new byte array.
|
static String |
toHex(byte[] bytes)
Returns a string with the hex values of the specified byte array.
|
static String |
toHex(byte[] bytes,
boolean upperCase)
Returns a string with the hex values of the specified byte array.
|
static String |
toStringSilently(byte[] bytes,
Charset charset)
Constructs a new String by decoding the specified array of bytes using
the specified charset.
|
static String |
toStringSilently(byte[] bytes,
String charsetName)
Constructs a new String by decoding the specified array of bytes using
the specified charset.
|
public static MessageDigest getMessageDigestSilently(String algorithm)
algorithm - the name of the algorithm requestedCodingException - if a MessageDigestSpi implementation for the specified
algorithm is not availablepublic static MessageDigest getMessageDigestSilently(String algorithm, String provider)
algorithm - the name of the algorithm requestedprovider - the provider (may be null)CodingException - if a MessageDigestSpi implementation for the specified
algorithm is not available from the specified Provider objectpublic static MessageDigest getMessageDigestSilently(String algorithm, Provider provider)
algorithm - the name of the algorithm requestedprovider - the provider (may be null)CodingException - if a MessageDigestSpi implementation for the specified
algorithm is not available from the specified Provider objectpublic static byte[] digestSilently(MessageDigest md, byte[] bytes)
md - the MessageDigestbytes - a byte arrayIllegalArgumentException - if message digest or bytes are nullCodingException - if calculation of the hash failspublic static byte[] digestSilently(MessageDigest md, byte[] bytes, InputStreamListener listener)
md - the MessageDigestbytes - a byte arraylistener - an input stream listener (may be null)IllegalArgumentException - if message digest or bytes is nullCodingException - if calculation of the hash failspublic static byte[] digestSilently(MessageDigest md, InputStream inputStream, boolean closeInputStream)
md - the MessageDigestinputStream - an input streamcloseInputStream - if true the input stream will be closed, otherwise it
will stay openIllegalArgumentException - if message digest or input stream is nullCodingException - if calculation of the hash failspublic static byte[] digestSilently(MessageDigest md, InputStream inputStream, boolean closeInputStream, InputStreamListener listener)
md - the MessageDigestinputStream - an input streamcloseInputStream - if true the input stream will be closed, otherwise it
will stay openlistener - an input stream listener (may be null)IllegalArgumentException - if message digest or input stream is nullCodingException - if calculation of the hash failspublic static String toHex(byte[] bytes)
bytes - a byte array (may be nullnull if the the byte array is nullpublic static String toHex(byte[] bytes, boolean upperCase)
bytes - a byte array (may be nullupperCase - should the result by upper case?null if the the byte array is nullpublic static byte[] toBytesSilently(String text, String charsetName)
text - the stringcharsetName - the charset namenull if the string is
nullCodingException - if the named charset is not supportedpublic static byte[] toBytesSilently(String text, Charset charset)
text - the stringcharset - the charsetnull if the string is
nullpublic static String toStringSilently(byte[] bytes, String charsetName)
bytes - the bytescharsetName - the name of the charsetnull if the bytes are nullCodingException - if the named charset is not supportedCopyright © 2017 bremersee.org. All rights reserved.