Groovy Examples

GroovyOct 23, 2026

Render an aligned plain-text table in Groovy

Measures column widths and pads each cell so rows line up in a plain-text table with a separator rule.

formattingtablecli
000
GroovyOct 23, 2026

Base64 encode and decode strings in Groovy

Converts text to Base64 and back using UTF-8, turning malformed input into a clear IllegalArgumentException.

encodingstringsbase64
000
GroovyOct 23, 2026

Validate form input fields with clear Groovy errors

Checks required, email, and age fields, collecting field-level messages instead of stopping at the first problem.

errorsvalidationforms
000
GroovyOct 23, 2026

Encode and parse URL query strings in Groovy

Builds URL-encoded query strings from maps and parses them back, keeping encoded separators inside values intact.

query-stringurlencoding
000
GroovyOct 23, 2026

Groovy JSON parsing with readable error messages

Wraps JsonSlurper so empty or malformed input fails with a short, specific message while keeping the original cause.

parsingerrorsjson
000
GroovyOct 23, 2026

Groovy fixed worker pool with collected errors

Submits tasks to a fixed thread pool, then prints each result or failure without letting one job cancel the rest.

concurrencythreadsexecutor
000
GroovyOct 23, 2026

Groovy HTTP GET JSON request with timeouts

Sends a GET with connect and request timeouts, rejects non-200 responses, and parses the body as JSON.

httpjsontimeout
000
GroovyOct 23, 2026

Validate environment variables with Groovy defaults

Reads settings from environment variables with sane defaults, then reports all validation failures in one message.

environmentconfigvalidation
000
GroovyOct 23, 2026

Thread-safe token bucket limiter in Groovy

Refills tokens at a steady rate up to a fixed capacity, allowing short bursts while limiting the long-run rate.

concurrencytoken-bucketrate-limit
000
GroovyOct 23, 2026

Groovy LRU cache backed by LinkedHashMap

Extends LinkedHashMap in access order so the least recently used entry is evicted once the size limit is passed.

lrucachecollections
000
GroovyOct 23, 2026

Split an iterable into fixed-size Groovy batches

Splits any iterable into ordered lists of a given size and keeps the final short batch instead of dropping it.

chunkingcollectionsiterables
000
GroovyOct 23, 2026

Multi-key Groovy list sort with null handling

Sorts a list of maps by score descending and age ascending, with explicit null placement and a name tie-break.

nullssortingcomparator
000
GroovyOct 23, 2026

Read a text file line by line in Groovy

Streams a text file line by line with a closing reader, skipping blank and comment lines while counting stats.

streamingiofiles
000
GroovyOct 23, 2026

Groovy deep clone and recursive map merge

Copies nested maps and lists so the source stays untouched, then merges two maps recursively key by key.

mergedeep-copycollections
000
GroovyOct 23, 2026

Groovy retry wrapper with capped exponential backoff

Runs a closure up to a fixed number of attempts with capped exponential backoff and jitter between tries.

resilienceclosuresbackoffretry
000