Class Utils
- java.lang.Object
-
- org.hyperledger.fabric.sdk.helper.Utils
-
public final class Utils extends java.lang.Object
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.lang.Exception
checkGrpcUrl(java.lang.String url)
Check if the strings Grpc url is validstatic java.lang.String
combinePaths(java.lang.String first, java.lang.String... other)
Combine two or more pathsstatic void
deleteFileOrDirectory(java.io.File file)
Delete a file or directorystatic java.lang.String
generateDirectoryHash(java.lang.String rootDir, java.lang.String chaincodeDir, java.lang.String hash)
Generate hash of a chaincode directorystatic byte[]
generateNonce()
static java.lang.String
generateParameterHash(java.lang.String path, java.lang.String func, java.util.List<java.lang.String> args)
Generate parameter hash for the given chaincode path,func and argsstatic byte[]
generateTarGz(java.io.File sourceDirectory, java.lang.String pathPrefix, java.io.File chaincodeMetaInf)
Compress the contents of given directory using Tar and Gzip to an in-memory byte array.static com.google.protobuf.Timestamp
generateTimestamp()
Create a newTimestamp
instance based on the current timestatic java.lang.String
generateUUID()
Generate a v4 UUIDstatic byte[]
hash(byte[] input, org.bouncycastle.crypto.Digest digest)
Generate hash of the given input using the given Digest.static boolean
isNullOrEmpty(java.lang.String url)
Check if a string is null or empty.static java.lang.String
logString(java.lang.String string)
Makes logging strings which can be long or with unprintable characters be logged and trimmed.static java.util.Properties
parseGrpcUrl(java.lang.String url)
static byte[]
readFile(java.io.File input)
Read the contents a file.static byte[]
readFileFromClasspath(java.lang.String fileName)
Read a file from classpathstatic java.lang.String
toHexString(byte[] bytes)
static java.lang.String
toHexString(com.google.protobuf.ByteString byteString)
-
-
-
Method Detail
-
generateParameterHash
public static java.lang.String generateParameterHash(java.lang.String path, java.lang.String func, java.util.List<java.lang.String> args)
Generate parameter hash for the given chaincode path,func and args- Parameters:
path
- Chaincode pathfunc
- Chaincode function nameargs
- List of arguments- Returns:
- hash of path, func and args
-
generateDirectoryHash
public static java.lang.String generateDirectoryHash(java.lang.String rootDir, java.lang.String chaincodeDir, java.lang.String hash) throws java.io.IOException
Generate hash of a chaincode directory- Parameters:
rootDir
- Root directorychaincodeDir
- Channel code directoryhash
- Previous hash (if any)- Returns:
- hash of the directory
- Throws:
java.io.IOException
-
generateTarGz
public static byte[] generateTarGz(java.io.File sourceDirectory, java.lang.String pathPrefix, java.io.File chaincodeMetaInf) throws java.io.IOException
Compress the contents of given directory using Tar and Gzip to an in-memory byte array.- Parameters:
sourceDirectory
- the source directory.pathPrefix
- a path to be prepended to every file name in the .tar.gz output, ornull
if no prefix is required.chaincodeMetaInf
-- Returns:
- the compressed directory contents.
- Throws:
java.io.IOException
-
readFile
public static byte[] readFile(java.io.File input) throws java.io.IOException
Read the contents a file.- Parameters:
input
- source file to read.- Returns:
- contents of the file.
- Throws:
java.io.IOException
-
generateUUID
public static java.lang.String generateUUID()
Generate a v4 UUID- Returns:
- String representation of
UUID
-
generateTimestamp
public static com.google.protobuf.Timestamp generateTimestamp()
Create a newTimestamp
instance based on the current time- Returns:
- timestamp
-
deleteFileOrDirectory
public static void deleteFileOrDirectory(java.io.File file) throws java.io.IOException
Delete a file or directory- Parameters:
file
-File
representing file or directory- Throws:
java.io.IOException
-
hash
public static byte[] hash(byte[] input, org.bouncycastle.crypto.Digest digest)
Generate hash of the given input using the given Digest.- Parameters:
input
- input data.digest
- the digest to use for hashing- Returns:
- hashed data.
-
combinePaths
public static java.lang.String combinePaths(java.lang.String first, java.lang.String... other)
Combine two or more paths- Parameters:
first
- parent directory pathother
- children- Returns:
- combined path
-
readFileFromClasspath
public static byte[] readFileFromClasspath(java.lang.String fileName) throws java.io.IOException
Read a file from classpath- Parameters:
fileName
-- Returns:
- byte[] data
- Throws:
java.io.IOException
-
parseGrpcUrl
public static java.util.Properties parseGrpcUrl(java.lang.String url)
-
checkGrpcUrl
public static java.lang.Exception checkGrpcUrl(java.lang.String url)
Check if the strings Grpc url is valid- Parameters:
url
-- Returns:
- Return the exception that indicates the error or null if ok.
-
isNullOrEmpty
public static boolean isNullOrEmpty(java.lang.String url)
Check if a string is null or empty.- Parameters:
url
- the string to test.- Returns:
true
if the string is null or empty; otherwisefalse
.
-
logString
public static java.lang.String logString(java.lang.String string)
Makes logging strings which can be long or with unprintable characters be logged and trimmed.- Parameters:
string
- Unsafe string too long- Returns:
- returns a string which does not have unprintable characters and trimmed in length.
-
generateNonce
public static byte[] generateNonce()
-
toHexString
public static java.lang.String toHexString(com.google.protobuf.ByteString byteString)
-
toHexString
public static java.lang.String toHexString(byte[] bytes)
-
-