or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

configuration-management.mddata-structure-utilities.mdframework-integration.mdindex.mdio-file-operations.mdnetwork-operations.mdpath-template-matching.mdsecurity-cryptography.mdstring-processing.mdtime-date-operations.md
tile.json

tessl/maven-com-networknt--utility

A comprehensive utility library for Light-4J microservices framework providing string manipulation, networking, I/O, security, and configuration utilities.

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
mavenpkg:maven/com.networknt/utility@2.2.x

To install, run

npx @tessl/cli install tessl/maven-com-networknt--utility@2.2.0

index.mddocs/

NetworkNT Utility Library

A comprehensive collection of utility classes designed for the Light-4J microservices framework, providing essential utilities for string manipulation, networking operations, I/O operations, security operations, data structure utilities, time and date operations, configuration management, path template matching, and more. This library minimizes external dependencies by incorporating selected functionality from Apache Commons libraries directly, ensuring a lightweight footprint for cloud-native microservices deployment.

Package Information

  • Package Name: com.networknt/utility
  • Package Type: maven
  • Language: Java
  • Installation:
    <dependency>
      <groupId>com.networknt</groupId>
      <artifactId>utility</artifactId>
      <version>2.2.1</version>
    </dependency>

Core Imports

import com.networknt.utility.*;

For specific utilities:

import com.networknt.utility.StringUtils;
import com.networknt.utility.NetUtils;
import com.networknt.utility.HashUtil;
import com.networknt.utility.PathTemplateMatcher;

Basic Usage

import com.networknt.utility.StringUtils;
import com.networknt.utility.NetUtils;
import com.networknt.utility.HashUtil;

// String manipulation
String cleaned = StringUtils.trimToEmpty("  hello world  ");
boolean isValid = StringUtils.isEmail("user@example.com");

// Network operations
InetAddress localAddr = NetUtils.getLocalAddress();
int availablePort = NetUtils.getAvailablePort();

// Security operations
String uuid = HashUtil.generateUUID();
String hash = HashUtil.md5Hex("password");

// Path template matching for REST APIs
PathTemplateMatcher<String> matcher = new PathTemplateMatcher<>();
matcher.add("/api/users/{id}", "getUserById");
PathMatchResult<String> result = matcher.match("/api/users/123");

Architecture

The utility library is organized around functional areas rather than object hierarchies:

  • String Processing: Comprehensive string manipulation, validation, and formatting utilities
  • Network Operations: IP address handling, port management, and network utilities
  • Security & Cryptography: Hashing, PKCE implementation, and certificate fingerprinting
  • I/O & NIO: Stream operations, file handling, and byte conversions
  • Path Template Matching: Fast REST API path routing with parameter extraction
  • Data Structures: Thread-safe collections and null-safe operations
  • Configuration Management: Service mapping and configuration utilities
  • Time & Date: ISO 8601 formatting and time unit conversions
  • Framework Integration: Constants and module registry for Light-4J ecosystem

All utilities are designed as static methods or simple constructors for easy integration into microservices architectures.

Capabilities

String Manipulation

Comprehensive string processing utilities including validation, transformation, formatting, and pattern matching. Includes email validation, JWT token checking, and environment variable expansion.

public class StringUtils {
    public static boolean isNullOrEmpty(String value);
    public static String expandEnvVars(String text);
    public static boolean isEmail(String userIdEmail);
    public static String replace(String text, String searchString, String replacement, int max);
    public static String[] split(String str, String separatorChars);
    public static String join(Object[] array, char separator);
    public static boolean isNumeric(String str);
    public static boolean matchPathToPattern(String requestPath, String endpointPattern);
}

String Processing

Network Operations

Network utilities for IP address handling, port management, and network validation. Includes local address detection, hostname resolution, and URL formatting for IPv4/IPv6.

public class NetUtils {
    public static InetAddress getLocalAddress();
    public static boolean isValidAddress(String address);
    public static int getAvailablePort();
    public static String resolveHost2Address(String fqdn);
    public static String ipAddressToUrlString(InetAddress address);
}

Network Operations

Security & Cryptography

Security utilities including hash calculation, UUID generation, PKCE (Proof Key for Code Exchange) implementation, and certificate fingerprinting for OAuth and authentication workflows.

public class HashUtil {
    public static String generateUUID();
    public static String md5Hex(String message);
    public static String generateStrongPasswordHash(String password);
    public static boolean validatePassword(char[] originalPassword, String storedPassword);
}

public class CodeVerifierUtil {
    public static String generateRandomCodeVerifier();
    public static String deriveCodeVerifierChallenge(String codeVerifier);
}

public class FingerPrintUtil {
    public static String getCertFingerPrint(Certificate cert);
}

Security & Cryptography

Path Template Matching

Fast path template matching system for REST API routing with parameter extraction. Optimized for high-performance microservices with stem-based matching algorithms.

public class PathTemplateMatcher<T> {
    public PathTemplateMatcher<T> add(String pathTemplate, T value);
    public PathMatchResult<T> match(String path);
    public Set<PathTemplate> getPathTemplates();
}

public class PathTemplate implements Comparable<PathTemplate> {
    public static PathTemplate create(String inputPath);
    public boolean matches(String path, Map<String, String> pathParameters);
    public Set<String> getParameterNames();
}

Path Template Matching

I/O & File Operations

Stream processing, NIO operations, file handling, and byte conversions. Includes zip file handling, stream copying, and ByteBuffer operations for efficient I/O.

public class StreamUtils {
    public static byte[] copyToByteArray(InputStream in);
    public static String copyToString(InputStream in, Charset charset);
    public static int copy(InputStream in, OutputStream out);
    public static long copyRange(InputStream in, OutputStream out, long start, long end);
}

public class NioUtils {
    public static void unzip(String zipFilename, String destDirname);
    public static ByteBuffer toByteBuffer(String s);
    public static String getFileExtension(String name);
}

I/O & File Operations

Data Structure Utilities

Thread-safe collections and null-safe operations for working with maps, sets, and collections. Includes concurrent data structures and utility methods for safe data manipulation.

public class ConcurrentHashSet<E> extends AbstractSet<E> {
    public ConcurrentHashSet();
    public ConcurrentHashSet(int initialCapacity);
}

public class CollectionUtils {
    public static boolean isEmpty(Collection<?> collection);
    public static <E> E findFirstMatch(Collection<?> source, Collection<E> candidates);
    public static Object matchEndpointKey(String path, Map<String, Object> map);
}

public class MapUtil {
    public static <V> Optional<V> getValueIgnoreCase(Map<String, V> map, String key);
}

Data Structure Utilities

Configuration Management

Configuration utilities for service mapping, path normalization, and key management in microservices environments. Designed for Light-4J framework configuration patterns.

public class ConfigUtils {
    public static String findServiceEntry(String method, String searchKey, Map<String, Object> mapping);
    public static String normalisePath(String requestPath);
    public static String toInternalKey(String method, String path);
    public static Map<String, Object> normalizeMap(Map<String, Object> map, List<String> keysToNotSort);
}

Configuration Management

Time & Date Operations

Time unit conversions and ISO 8601 date formatting utilities for consistent time handling across microservices.

public class TimeUtil {
    public static long oneTimeUnitMillisecond(TimeUnit timeUnit);
    public static long nextStartTimestamp(TimeUnit timeUnit, long start);
}

public class DateUtil {
    public static String formatIso8601Date(Instant date);
    public static Instant parseIso8601Date(String dateString);
    public static long parseIso8601DateToMillis(String dateString);
}

Time & Date Operations

Framework Constants & Integration

Framework constants and module registry functionality for Light-4J ecosystem integration, including HTTP headers, JWT claims, and component registration.

public class Constants {
    public static final String CORRELATION_ID_STRING = "X-Correlation-Id";
    public static final String USER_ID_STRING = "user_id";
    public static final String CLIENT_ID_STRING = "client_id";
    public static final String LIGHT_4J = "light-4j";
    // ... 60+ additional constants
}

public class ModuleRegistry {
    public static void registerModule(String configName, String moduleClass, Map<String, Object> config, List<String> masks);
    public static Map<String, Object> getModuleRegistry();
    public static void registerPlugin(String pluginName, String pluginVersion, String configName, String pluginClass, Map<String, Object> config, List<String> masks);
}

Framework Constants & Integration

Types

public class Tuple<T, T2> {
    public final T first;
    public final T2 second;
    
    public Tuple(T first, T2 second);
}

public class PathTemplateMatch {
    public PathTemplateMatch(String matchedTemplate, Map<String, String> parameters);
    public String getMatchedTemplate();
    public Map<String, String> getParameters();
}

public interface PathMatchResult<T> extends PathTemplateMatch {
    T getValue();
}