public class Utils extends Object
| Modifier and Type | Class and Description |
|---|---|
static class |
Utils.HashAlgorithm
An enum of the hash algorithms supported by
computeHash(java.io.InputStream, com.akamai.netstorage.Utils.HashAlgorithm)
Currently supported hashes include MD5; SHA1; SHA256
The string representation matches the java MessageDigest.getInstance(String) canonical names. |
static class |
Utils.KeyedHashAlgorithm
An enum of the keyed-hash algorithms supported by
computeKeyedHash(byte[], String, com.akamai.netstorage.Utils.KeyedHashAlgorithm)
Currently supported hashes include HMAC-MD5; HMAC-SHA1; HMAC-SHA256
The string representation matches the java Mac.getInstance(String)} cononical names. |
| Constructor and Description |
|---|
Utils() |
| Modifier and Type | Method and Description |
|---|---|
static byte[] |
computeHash(InputStream srcStream,
Utils.HashAlgorithm hashAlgorithm)
Computes the hash of a given InputStream.
|
static byte[] |
computeKeyedHash(byte[] data,
String key,
Utils.KeyedHashAlgorithm hashType)
Computes the HMAC hash of a given byte[].
|
static String |
convertMapAsQueryParams(Map<String,String> data)
Convert Map<String, String> into a name=value query params string.
|
static Map<String,String> |
convertObjectAsMap(Object srcObj)
Convert a POJO object into a primitive name-value pair or Map<String, String>.
|
static String |
encodeBase64(byte[] value)
Base64-encode a byte array.
|
static String |
encodeHex(byte[] value)
Hex encoding wrapper for a byte array.
|
static Properties |
readIniSection(File srcFile,
String section)
Convenience method to read Properties in Ini format
|
static Properties |
readIniSection(InputStream inputStream,
String section)
Convenience method to read Properties in Ini format
|
static void |
readToEnd(InputStream stream)
Simple utility to read to the end of a stream when you don't particularly care for the contents of the stream.
|
public static byte[] computeHash(InputStream srcStream, Utils.HashAlgorithm hashAlgorithm) throws IOException
srcStream - a source stream. This will be wrapped in a BufferedInputStream
in case the source stream is not bufferedhashAlgorithm - the Algorithm to use to compute the hashIOException - If there is a problem with the InputStream during the compute of the hashpublic static byte[] computeKeyedHash(byte[] data,
String key,
Utils.KeyedHashAlgorithm hashType)
data - byte[] of content to hashkey - secret key to salt the hashhashType - determines which alogirthm to use. The recommendation is to use HMAC-SHA256public static String encodeHex(byte[] value)
value - a byte array to encode. The assumption is that the string to encode
is small enough to be held in memory without streaming the encodingpublic static String encodeBase64(byte[] value)
value - byte array to encode.public static Map<String,String> convertObjectAsMap(Object srcObj)
srcObj - source pojo objectpublic static String convertMapAsQueryParams(Map<String,String> data)
NB: This uses URLEncoding - not URI Encoding for escaping name and values. This shouldn't be an issue for most uses of this function for the Netstorage API, but could impact non-ascii usernames in the future.
data - a Key-Value mappublic static void readToEnd(InputStream stream) throws IOException
stream - the open InputStreamIOException - inputs tream read exceptionpublic static Properties readIniSection(File srcFile, String section) throws IOException
srcFile - File of the inputstreamsection - the ini [section] name to read the properties fromIOException - inputs tream read exceptionpublic static Properties readIniSection(InputStream inputStream, String section) throws IOException
inputStream - streamsection - the ini [section] name to read the properties fromIOException - inputs tream read exceptionCopyright © 2016. All rights reserved.