Package net.snowflake.ingest.utils
Class Utils
- java.lang.Object
-
- net.snowflake.ingest.utils.Utils
-
public class Utils extends Object
Contains Ingest related utility functions
-
-
Constructor Summary
Constructors Constructor Description Utils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
assertNotNull(String name, Object value)
Assert when the value is nullstatic void
assertStringNotNullOrEmpty(String name, String value)
Assert when the String is null or Emptystatic String
constructAccountUrl(String scheme, String host, int port)
Construct account url from input schema, host and portstatic KeyPair
createKeyPairFromPrivateKey(PrivateKey privateKey)
Generate key pair object from private keystatic Properties
createProperties(Properties inputProp)
Create a Properties for snowflake connectionstatic com.codahale.metrics.Timer.Context
createTimerContext(com.codahale.metrics.Timer timer)
Create a new timer context if input is not nullstatic String
getStackTrace(Throwable e)
Return the stack trace for a given exceptionstatic boolean
isNullOrEmpty(String string)
Utility function to check whether a string is null or emptystatic PrivateKey
parseEncryptedPrivateKey(String key, String passphrase)
Parse an encrypted private keystatic PrivateKey
parsePrivateKey(String key)
Parse an unencrypted private keystatic void
showMemory()
Util function to show memory usage info and debug memory issue in the SDKstatic byte[]
toByteArray(int value)
Convert int value to a byte arraystatic byte[]
toByteArray(long value)
Convert long value to a byte array
-
-
-
Method Detail
-
assertStringNotNullOrEmpty
public static void assertStringNotNullOrEmpty(String name, String value) throws SFException
Assert when the String is null or Empty- Parameters:
name
-value
-- Throws:
SFException
-
assertNotNull
public static void assertNotNull(String name, Object value) throws SFException
Assert when the value is null- Parameters:
name
-value
-- Throws:
SFException
-
createProperties
public static Properties createProperties(Properties inputProp)
Create a Properties for snowflake connection- Parameters:
inputProp
- input property map- Returns:
- a Properties instance
-
constructAccountUrl
public static String constructAccountUrl(String scheme, String host, int port)
Construct account url from input schema, host and port
-
parsePrivateKey
public static PrivateKey parsePrivateKey(String key)
Parse an unencrypted private key- Parameters:
key
- unencrypted private key- Returns:
- the unencrypted private key
-
parseEncryptedPrivateKey
public static PrivateKey parseEncryptedPrivateKey(String key, String passphrase)
Parse an encrypted private key- Parameters:
key
- encrypted private keypassphrase
- private key phrase- Returns:
- the decrypted private key
-
createKeyPairFromPrivateKey
public static KeyPair createKeyPairFromPrivateKey(PrivateKey privateKey) throws NoSuchAlgorithmException, InvalidKeySpecException
Generate key pair object from private key- Parameters:
privateKey
- private key- Returns:
- a key pair object
- Throws:
NoSuchAlgorithmException
- if can't create key factory by using RSA algorithmInvalidKeySpecException
- if private key or public key is invalid
-
createTimerContext
public static com.codahale.metrics.Timer.Context createTimerContext(com.codahale.metrics.Timer timer)
Create a new timer context if input is not null
-
toByteArray
public static byte[] toByteArray(long value)
Convert long value to a byte array
-
toByteArray
public static byte[] toByteArray(int value)
Convert int value to a byte array
-
isNullOrEmpty
public static boolean isNullOrEmpty(String string)
Utility function to check whether a string is null or empty
-
showMemory
public static void showMemory()
Util function to show memory usage info and debug memory issue in the SDK
-
-