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.ExceptioncheckGrpcUrl(java.lang.String url)Check if the strings Grpc url is validstatic java.lang.StringcombinePaths(java.lang.String first, java.lang.String... other)Combine two or more pathsstatic voiddeleteFileOrDirectory(java.io.File file)Delete a file or directorystatic java.lang.StringgenerateDirectoryHash(java.lang.String rootDir, java.lang.String chaincodeDir, java.lang.String hash)Generate hash of a chaincode directorystatic byte[]generateNonce()static java.lang.StringgenerateParameterHash(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.TimestampgenerateTimestamp()Create a newTimestampinstance based on the current timestatic java.lang.StringgenerateUUID()Generate a v4 UUIDstatic byte[]hash(byte[] input, org.bouncycastle.crypto.Digest digest)Generate hash of the given input using the given Digest.static booleanisNullOrEmpty(java.lang.String url)Check if a string is null or empty.static java.lang.StringlogString(java.lang.String string)Makes logging strings which can be long or with unprintable characters be logged and trimmed.static java.util.PropertiesparseGrpcUrl(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.StringtoHexString(byte[] bytes)static java.lang.StringtoHexString(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.IOExceptionGenerate 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.IOExceptionCompress 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, ornullif 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.IOExceptionRead 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 newTimestampinstance based on the current time- Returns:
- timestamp
-
deleteFileOrDirectory
public static void deleteFileOrDirectory(java.io.File file) throws java.io.IOExceptionDelete a file or directory- Parameters:
file-Filerepresenting 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.IOExceptionRead 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:
trueif 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)
-
-