Core foundational library for AWS SDK for Java 1.x providing authentication, HTTP transport, regions, protocols, and shared utilities for all AWS service clients
—
The AWS Java SDK Core provides comprehensive utility classes for common operations including string manipulation, I/O operations, encoding/decoding, hashing, JSON processing, and validation.
// String manipulation utilities
class StringUtils {
// Null/empty checks
public static boolean isNullOrEmpty(String value);
public static boolean hasValue(String str);
public static String trim(String value);
public static String defaultString(String str);
public static String defaultString(String str, String defaultStr);
// String operations
public static String join(String delimiter, String... strings);
public static String join(String delimiter, Collection<String> strings);
public static String[] split(String toSplit, char splitChar);
public static String lowerCase(String str);
public static String upperCase(String str);
// Replacement operations
public static String replace(String originalString, String partToMatch, String replacement);
public static String replaceAll(String originalString, String partToMatch, String replacement);
// Comparison operations
public static boolean equals(String str1, String str2);
public static boolean equalsIgnoreCase(String str1, String str2);
// Encoding/decoding
public static String urlEncode(String url, boolean keepPathSlash);
public static String urlDecode(String url);
public static byte[] utf8(String str);
public static String fromUtf8(byte[] bytes);
// Validation
public static void assertNotNullOrEmpty(String value, String fieldName);
public static void assertStringNotEmpty(String value, String fieldName);
}// Input/output stream utilities
class IOUtils {
// Stream to byte array conversion
public static byte[] toByteArray(InputStream input) throws IOException;
public static byte[] toByteArray(InputStream input, long length) throws IOException;
// Stream to string conversion
public static String toString(InputStream input) throws IOException;
public static String toString(InputStream input, String encoding) throws IOException;
// Resource management
public static void closeQuietly(Closeable closeable);
public static void closeQuietly(Closeable... closeables);
// Stream operations
public static long copy(InputStream input, OutputStream output) throws IOException;
public static void drainInputStream(InputStream inputStream);
// Buffer operations
public static InputStream toInputStream(String input);
public static InputStream toInputStream(byte[] input);
// Release operations
public static void release(Closeable is, Level level);
}// Binary data utilities
class BinaryUtils {
// Base64 encoding/decoding
public static String toBase64(byte[] data);
public static byte[] fromBase64(String b64Data);
public static String toBase64(ByteBuffer data);
public static ByteBuffer fromBase64(String b64Data, ByteBuffer byteBuffer);
// Hex encoding/decoding
public static String toHex(byte[] data);
public static byte[] fromHex(String hexData);
// ByteBuffer operations
public static ByteBuffer copyBytesFrom(String s);
public static ByteBuffer copyBytesFrom(byte[] bytes);
public static byte[] copyAllBytesFrom(ByteBuffer bb);
public static String toStream(ByteBuffer byteBuffer);
// Hash operations
public static byte[] hash(String text);
public static byte[] hash(byte[] data);
public static byte[] hash(InputStream input) throws IOException;
// Comparison operations
public static boolean equals(byte[] a, byte[] b);
}// Date and time utilities
class DateUtils {
// Date formatting
public static String formatISO8601Date(Date date);
public static String formatRFC822Date(Date date);
public static String formatUnixTimestamp(Date date);
public static String formatServiceSpecificDate(Date date);
// Date parsing
public static Date parseISO8601Date(String dateString);
public static Date parseRFC822Date(String dateString);
public static Date parseUnixTimestamp(String dateString);
public static Date parseServiceSpecificDate(String dateString);
public static Date parseCompressedISO8601Date(String dateString);
// Date operations
public static Date cloneDate(Date date);
public static long numberOfDaysSinceEpoch(long milliSinceEpoch);
// Thread-safe date formatters
public static final DateFormat ISO8601_DATE_FORMAT;
public static final DateFormat RFC822_DATE_FORMAT;
public static final DateFormat COMPRESSED_ISO8601_DATE_FORMAT;
public static final DateFormat UNIX_TIMESTAMP_FORMAT;
}// Input validation utilities
class ValidationUtils {
// Null checks
public static <T> T assertNotNull(T object, String fieldName) throws IllegalArgumentException;
public static void assertNotEmpty(Collection<?> collection, String fieldName) throws IllegalArgumentException;
public static void assertNotEmpty(Map<?, ?> map, String fieldName) throws IllegalArgumentException;
public static void assertNotEmpty(String string, String fieldName) throws IllegalArgumentException;
// String validation
public static void assertStringNotEmpty(String string, String fieldName) throws IllegalArgumentException;
public static String assertStringNotEmpty(String string, String fieldName, String errorMessage) throws IllegalArgumentException;
// Numeric validation
public static void assertIsPositive(int num, String fieldName) throws IllegalArgumentException;
public static void assertIsPositive(long num, String fieldName) throws IllegalArgumentException;
public static void assertIsPositive(double num, String fieldName) throws IllegalArgumentException;
// Collection validation
public static <T> List<T> assertNotNullOrEmpty(List<T> list, String fieldName) throws IllegalArgumentException;
public static <T> T[] assertNotNullOrEmpty(T[] array, String fieldName) throws IllegalArgumentException;
// Boolean validation
public static void assertTrue(boolean expression, String errorMessage) throws IllegalArgumentException;
public static void assertFalse(boolean expression, String errorMessage) throws IllegalArgumentException;
}// Base16 encoding/decoding
class Base16 {
public static String encodeAsString(byte[] bytes);
public static byte[] encode(byte[] bytes);
public static byte[] decode(String b16);
public static byte[] decode(byte[] b16);
}
// Base32 encoding/decoding
class Base32 {
public static String encodeAsString(byte[] bytes);
public static byte[] encode(byte[] bytes);
public static byte[] decode(String b32);
public static byte[] decode(byte[] b32);
}
// Base64 encoding/decoding
class Base64 {
public static String encodeAsString(byte[] bytes);
public static byte[] encode(byte[] bytes);
public static byte[] decode(String b64);
public static byte[] decode(byte[] b64);
public static boolean isBase64(String str);
}// MD5 hashing utilities
class Md5Utils {
// MD5 hash computation
public static byte[] computeMD5Hash(InputStream is) throws IOException;
public static byte[] computeMD5Hash(byte[] input);
public static String md5AsBase64(byte[] input);
public static String md5AsBase64(InputStream is) throws IOException;
// MD5 hash validation
public static byte[] md5(String text);
public static String md5Hex(String text);
public static String md5Hex(byte[] data);
// Stream MD5 computation
public static DigestInputStream md5DigestStream(InputStream stream);
}// HTTP utilities for SDK
class SdkHttpUtils {
// URL encoding/decoding
public static String urlEncode(String value, boolean path);
public static String urlDecode(String value);
public static String encodeParameters(Request<?> request);
// Header operations
public static boolean isValidHostnameForURI(String hostname);
public static String appendUri(String baseUri, String path);
public static String appendUri(String baseUri, String path, boolean escapeDoubleSlash);
// Query parameter operations
public static Map<String, List<String>> parseQueryString(String queryString);
public static String encodeQueryString(Map<String, List<String>> parameters);
// Content operations
public static long getContentLength(Request<?> request);
public static InputStream getRequestPayloadStream(Request<?> request);
// Utility methods
public static boolean usePayloadForQueryParameters(Request<?> request);
}
// Runtime HTTP utilities
class RuntimeHttpUtils {
// Content type operations
public static String toContentType(String contentType);
public static String toContentEncoding(String contentEncoding);
// Header utilities
public static String fetchUserAgent();
public static Map<String, String> convertHeadersToMap(Header[] headers);
}
// AWS hostname utilities
class AwsHostNameUtils {
// Hostname parsing
public static String parseRegionName(String hostname, String serviceHint);
public static String parseServiceName(String hostname);
public static String parseRegion(String host, String serviceHint);
// S3 specific utilities
public static String parseS3BucketName(String host, String serviceHint);
public static boolean isS3USStandardEndpoint(String endpoint);
}// JSON manipulation utilities
class JsonUtils {
// JSON parsing
public static <T> T jsonToObject(String json, Class<T> clazz) throws IOException;
public static String objectToJson(Object obj) throws IOException;
// JSON node operations
public static JsonNode getJsonNodeFromJsonText(String json);
public static String getStringFromJsonNode(JsonNode node, String key);
public static Integer getIntegerFromJsonNode(JsonNode node, String key);
public static Boolean getBooleanFromJsonNode(JsonNode node, String key);
public static Date getDateFromJsonNode(JsonNode node, String key);
// JSON validation
public static boolean isValidJson(String json);
public static void assertValidJson(String json, String fieldName);
}
// Jackson JSON processing utilities
class Jackson {
// ObjectMapper operations
public static final ObjectMapper OBJECT_MAPPER;
// JSON string operations
public static String toJsonString(Object value);
public static <T> T fromJsonString(String json, Class<T> valueType);
public static <T> T fromJsonString(String json, TypeReference<T> typeReference);
// JSON pretty printing
public static String toJsonPrettyString(Object value);
// JSON validation
public static boolean isValidJson(String json);
// Stream operations
public static JsonGenerator jsonGeneratorOf(OutputStream out) throws IOException;
public static JsonParser jsonParserOf(String json) throws IOException;
public static JsonParser jsonParserOf(InputStream json) throws IOException;
}// Collection manipulation utilities
class CollectionUtils {
// Null/empty checks
public static boolean isNullOrEmpty(Collection<?> collection);
public static boolean isNullOrEmpty(Map<?, ?> map);
// Collection operations
public static <T> List<T> mergeLists(List<T>... lists);
public static <T> Set<T> mergeSets(Set<T>... sets);
// Map operations
public static <K, V> Map<K, V> mergeMaps(Map<K, V>... maps);
public static <K, V> void putIfNotNull(Map<K, V> map, K key, V value);
// Conversion operations
public static <T> List<T> join(List<T> list1, List<T> list2);
public static String joinWithComma(Collection<String> toJoin);
// Utility methods
public static <T> boolean equals(Collection<T> list1, Collection<T> list2);
}// Class loading utilities
class Classes {
// Class loading
public static Class<?> childClassOf(Class<?> childClass, Class<?> parentClass);
public static <T> Class<T> jarFileOf(Class<T> klass);
// Resource loading
public static URL getResource(String resource);
public static InputStream getResourceAsStream(String resource);
// Class information
public static String getClassName(Class<?> clazz);
public static String getClassPath(Class<?> clazz);
}// Version information utilities
class VersionInfoUtils {
// Version retrieval
public static String getVersion();
public static String getPlatform();
public static String getUserAgent();
public static String getVersionFromFullVersionString(String fullVersionString);
// User agent operations
public static String formatUserAgent(String clientName, String clientVersion);
public static String formatUserAgent(String clientName, String clientVersion,
String platformInfo, String languageInfo);
}// Fake IO exception for testing
class FakeIOException extends IOException {
public FakeIOException(String message);
}
// Input stream with length checking
class LengthCheckInputStream extends InputStream {
public LengthCheckInputStream(InputStream in, long expectedLength, boolean includeSkipped);
public int read() throws IOException;
public int read(byte[] b, int off, int len) throws IOException;
public long skip(long n) throws IOException;
public void close() throws IOException;
}
// Input stream with byte counting
class CountingInputStream extends FilterInputStream {
public CountingInputStream(InputStream in);
public long getByteCount();
public int read() throws IOException;
public int read(byte[] b, int off, int len) throws IOException;
public long skip(long n) throws IOException;
}// SDK runtime utilities
class SdkRuntime {
// Runtime information
public static String getApplicationName();
public static String getApplicationVersion();
public static String getClientName();
public static String getClientVersion();
// System information
public static String getJavaVersion();
public static String getJavaVendor();
public static String getJavaVmName();
public static String getJavaVmVersion();
public static String getOsName();
public static String getOsVersion();
public static String getOsArch();
// User agent construction
public static String getUserAgent();
public static String getUserAgentFromClientName(String clientName);
}// Timestamp format utilities
class TimestampFormat {
// Timestamp formats
public static final String ISO_8601 = "iso8601";
public static final String UNIX_TIMESTAMP = "unixTimestamp";
public static final String RFC_822 = "rfc822";
// Format operations
public static String format(String format, Date date);
public static Date parse(String format, String dateString);
public static boolean isValidFormat(String format);
// Validation
public static void validateFormat(String format);
}import com.amazonaws.util.StringUtils;
// Basic string operations
String input = " Hello World ";
boolean isEmpty = StringUtils.isNullOrEmpty(input); // false
String trimmed = StringUtils.trim(input); // "Hello World"
String defaultValue = StringUtils.defaultString(null, "N/A"); // "N/A"
// String joining and splitting
String[] parts = {"Hello", "World", "AWS"};
String joined = StringUtils.join(", ", parts); // "Hello, World, AWS"
String[] split = StringUtils.split("a,b,c", ','); // ["a", "b", "c"]
// URL encoding
String url = "https://example.com/path with spaces";
String encoded = StringUtils.urlEncode(url, true); // Keep path slashes
String decoded = StringUtils.urlDecode(encoded);
// UTF-8 operations
byte[] utf8Bytes = StringUtils.utf8("Hello World");
String utf8String = StringUtils.fromUtf8(utf8Bytes);
// Validation
try {
StringUtils.assertNotNullOrEmpty(input, "input");
StringUtils.assertStringNotEmpty(trimmed, "trimmed");
} catch (IllegalArgumentException e) {
System.err.println("Validation failed: " + e.getMessage());
}import com.amazonaws.util.IOUtils;
import java.io.*;
// Stream to byte array conversion
try (InputStream inputStream = new FileInputStream("example.txt")) {
byte[] content = IOUtils.toByteArray(inputStream);
String contentString = IOUtils.toString(new ByteArrayInputStream(content));
// Create input stream from string
InputStream stringStream = IOUtils.toInputStream("Hello World");
// Copy streams
try (OutputStream output = new FileOutputStream("copy.txt")) {
long bytesCopied = IOUtils.copy(stringStream, output);
System.out.println("Copied " + bytesCopied + " bytes");
}
} catch (IOException e) {
e.printStackTrace();
} finally {
// Safe resource cleanup
IOUtils.closeQuietly(inputStream, outputStream);
}
// Drain input stream
try (InputStream stream = new URL("https://example.com").openStream()) {
IOUtils.drainInputStream(stream);
}import com.amazonaws.util.BinaryUtils;
import java.nio.ByteBuffer;
// Base64 operations
String text = "Hello World";
byte[] data = text.getBytes();
String base64 = BinaryUtils.toBase64(data); // SGVsbG8gV29ybGQ=
byte[] decoded = BinaryUtils.fromBase64(base64);
// Hex operations
String hex = BinaryUtils.toHex(data); // 48656c6c6f20576f726c64
byte[] fromHex = BinaryUtils.fromHex(hex);
// ByteBuffer operations
ByteBuffer buffer = BinaryUtils.copyBytesFrom(text);
byte[] allBytes = BinaryUtils.copyAllBytesFrom(buffer);
String streamString = BinaryUtils.toStream(buffer);
// Hash operations
byte[] hash = BinaryUtils.hash(text);
String hashHex = BinaryUtils.toHex(hash);
// ByteBuffer from Base64
ByteBuffer base64Buffer = ByteBuffer.allocate(1024);
BinaryUtils.fromBase64(base64, base64Buffer);import com.amazonaws.util.DateUtils;
import java.util.Date;
Date now = new Date();
// Format dates in different formats
String iso8601 = DateUtils.formatISO8601Date(now); // 2023-12-01T10:30:00.000Z
String rfc822 = DateUtils.formatRFC822Date(now); // Fri, 01 Dec 2023 10:30:00 GMT
String unixTimestamp = DateUtils.formatUnixTimestamp(now); // 1701426600
// Parse dates from different formats
try {
Date parsedISO = DateUtils.parseISO8601Date("2023-12-01T10:30:00.000Z");
Date parsedRFC = DateUtils.parseRFC822Date("Fri, 01 Dec 2023 10:30:00 GMT");
Date parsedUnix = DateUtils.parseUnixTimestamp("1701426600");
// Clone date safely
Date cloned = DateUtils.cloneDate(now);
// Calculate days since epoch
long days = DateUtils.numberOfDaysSinceEpoch(now.getTime());
} catch (Exception e) {
System.err.println("Date parsing failed: " + e.getMessage());
}import com.amazonaws.util.ValidationUtils;
import java.util.*;
// Object validation
String name = "John Doe";
ValidationUtils.assertNotNull(name, "name");
ValidationUtils.assertStringNotEmpty(name, "name");
// Collection validation
List<String> items = Arrays.asList("item1", "item2", "item3");
ValidationUtils.assertNotEmpty(items, "items");
ValidationUtils.assertNotNullOrEmpty(items, "items");
// Numeric validation
int count = 10;
ValidationUtils.assertIsPositive(count, "count");
// Boolean validation
boolean condition = true;
ValidationUtils.assertTrue(condition, "Condition must be true");
// Custom validation with error messages
try {
ValidationUtils.assertStringNotEmpty("", "username", "Username cannot be empty");
} catch (IllegalArgumentException e) {
System.err.println("Validation error: " + e.getMessage());
}import com.amazonaws.util.JsonUtils;
import com.amazonaws.util.Jackson;
import java.util.Map;
// JSON string to object conversion
String jsonString = "{\"name\":\"John\",\"age\":30,\"active\":true}";
try {
// Using JsonUtils
Map<String, Object> map = JsonUtils.jsonToObject(jsonString, Map.class);
String backToJson = JsonUtils.objectToJson(map);
// Using Jackson
Map<String, Object> jacksonMap = Jackson.fromJsonString(jsonString, Map.class);
String prettyJson = Jackson.toJsonPrettyString(jacksonMap);
// JSON validation
boolean isValid = JsonUtils.isValidJson(jsonString);
if (!isValid) {
throw new IllegalArgumentException("Invalid JSON");
}
System.out.println("Pretty JSON: " + prettyJson);
} catch (Exception e) {
System.err.println("JSON processing failed: " + e.getMessage());
}import com.amazonaws.util.Md5Utils;
import java.io.*;
// MD5 hash computation
String text = "Hello World";
byte[] textBytes = text.getBytes();
// Hash from byte array
byte[] md5Hash = Md5Utils.computeMD5Hash(textBytes);
String md5Base64 = Md5Utils.md5AsBase64(textBytes);
String md5Hex = Md5Utils.md5Hex(textBytes);
System.out.println("MD5 Base64: " + md5Base64);
System.out.println("MD5 Hex: " + md5Hex);
// Hash from input stream
try (InputStream stream = new ByteArrayInputStream(textBytes)) {
byte[] streamMd5 = Md5Utils.computeMD5Hash(stream);
String streamMd5Base64 = Md5Utils.md5AsBase64(stream);
// Create MD5 digest stream for progressive hashing
DigestInputStream digestStream = Md5Utils.md5DigestStream(stream);
// Read from digestStream to compute hash progressively
} catch (IOException e) {
e.printStackTrace();
}Null Safety: Always use validation utilities to check for null values before processing.
Resource Management: Use IOUtils.closeQuietly() for safe resource cleanup in finally blocks.
String Operations: Use StringUtils for null-safe string operations and proper encoding.
Date Handling: Use appropriate date formats for different contexts (ISO8601 for APIs, RFC822 for headers).
JSON Processing: Validate JSON strings before parsing and handle parsing exceptions appropriately.
Binary Data: Use appropriate encoding (Base64, Hex) based on the target system requirements.
Collection Safety: Check for null or empty collections before iteration or processing.
Input Validation: Validate all inputs at service boundaries using validation utilities.
Hash Operations: Use MD5 for checksums and integrity verification, not for security purposes.
Performance: Use streaming operations for large data sets to avoid memory issues.
The utility classes provide comprehensive support for common operations, enabling robust and efficient data processing with proper error handling and validation throughout AWS SDK operations.
Install with Tessl CLI
npx tessl i tessl/maven-com-amazonaws--aws-java-sdk-core