public class LibraryUtils
extends java.lang.Object
| Constructor and Description |
|---|
LibraryUtils() |
| Modifier and Type | Method and Description |
|---|---|
static void |
checkArgumentNotNull(java.lang.Object argument,
java.lang.String message)
Check that an object is not
null; throw an exception if it
is. |
static void |
checkCondition(boolean condition,
java.lang.String message)
Check a conditional value or expression, if
true, throw an
exception. |
static void |
endToProcess(ProgressReporter progressReporter,
boolean processSuccess,
ProgressStatus progressStatus,
java.lang.Object reportObject)
A wrapper function of reporting the result of the processing.
|
static java.lang.String |
extractAccountIdFromObjectKey(java.lang.String objectKey)
Extract the account ID from an S3 object key.
|
static java.text.SimpleDateFormat |
getUtcSdf()
Get a timestamp in
SimpleDateFormat.
|
static void |
handleException(ExceptionHandler exceptionHandler,
ProgressStatus progressStatus,
java.lang.Exception e,
java.lang.String message)
A wrapper function of handling exceptions that have a known root cause, such as
AmazonServiceException. |
static void |
handleException(ExceptionHandler exceptionHandler,
ProgressStatus progressStatus,
java.lang.String message)
A wrapper function of handling uncaught exceptions.
|
static void |
setMessageAccountId(Message sqsMessage,
java.lang.String s3ObjectKey)
Add the account ID attribute to the
sqsMessage if it does not exist. |
static java.lang.String[] |
toBucketNameObjectKey(java.lang.String s3ObjectHttpUrl)
Split an HTTP representation of an Amazon S3 URL to bucket name and object key.
|
static byte[] |
toByteArray(java.io.InputStream inputStream)
Convert an
InputSteam to a byte array.
|
public static void checkArgumentNotNull(java.lang.Object argument,
java.lang.String message)
null; throw an exception if it
is.argument - the Object to check.message - a description string that will be sent with the exception.java.lang.IllegalStateException - if the passed-in object is null.public static void checkCondition(boolean condition,
java.lang.String message)
true, throw an
exception.condition - a boolean value or an expression to check.message - a description string that will be sent with the exception.java.lang.IllegalStateException - if the condition expression is true.public static byte[] toByteArray(java.io.InputStream inputStream)
throws java.io.IOException
inputStream - the InputStream to convert.java.io.IOException - if the InputStream could not be converted.public static java.lang.String[] toBucketNameObjectKey(java.lang.String s3ObjectHttpUrl)
For example:
input: s3ObjectHttpUrl = http://s3-us-west-2.amazonaws.com/mybucket/myobjectpath1/myobjectpath2/myobject.extension
output: {"mybucket", "myobjectpath1/myobjectpath2/myobject.extension"}
s3ObjectHttpUrl - the URL of the S3 object to split.public static java.lang.String extractAccountIdFromObjectKey(java.lang.String objectKey)
For example:
input: https://s3-us-west-2.amazonaws.com/mybucket/AWSLogs/123456789012/CloudTrail/us-east-1/2014/02/14/123456789012_CloudTrail_us-east-1_20140214T2230Z_K0UsfksWvF8TBJZy.json.gz output: 1234567890
objectKey - The object key to query.public static void setMessageAccountId(Message sqsMessage,
java.lang.String s3ObjectKey)
sqsMessage if it does not exist.sqsMessage - The SQS message.s3ObjectKey - The S3 object key.public static void handleException(ExceptionHandler exceptionHandler, ProgressStatus progressStatus, java.lang.Exception e, java.lang.String message)
AmazonServiceException.exceptionHandler - the ExceptionHandler to handle exceptions.progressStatus - the current progress status ProgressStatus.e - the exception needs to be handled.message - the exception message.public static void handleException(ExceptionHandler exceptionHandler, ProgressStatus progressStatus, java.lang.String message)
exceptionHandler - the ExceptionHandler to handle exceptions.progressStatus - the current progress status ProgressStatus.message - the exception message.public static void endToProcess(ProgressReporter progressReporter, boolean processSuccess, ProgressStatus progressStatus, java.lang.Object reportObject)
progressReporter - the ProgressReporter to report the end of process.processSuccess - the result of process.progressStatus - the current progress status ProgressStatus.reportObject - the object to send, usually the object returned by ProgressReporter.reportStart(ProgressStatus).public static java.text.SimpleDateFormat getUtcSdf()