Java CLI and tools
The Java command-line and utility modules give users practical ways to convert, inspect, validate, and generate MapLibre Tile (MLT) data. The CLI extends the Java tile library with user-facing workflows and uses the Java core codec for tile work, while the tools module creates controlled MLT fixtures for development and cross-implementation checks.
User-facing operations
Encoding interface
The encode command turns one MVT tile or a tile container into MLT output. It accepts local files and PMTiles locations, then applies one conversion policy to the selected tiles. Users can choose an output file or directory and can limit batch work by zoom range or layer.
The command also exposes quality and size controls without requiring users to call the core library directly. These controls cover feature IDs, layer selection, column grouping, geometry preparation, integer and string compression, output compression, and parallel work. The accepted output compression choices depend on the selected input container.
| Input form | Main result | Scope |
|---|---|---|
| Individual MVT file | Individual MLT file | One tile |
| MBTiles file | MLT MBTiles file | SQLite tile set |
| Offline database | Updated copy of the database | Existing database schema |
| PMTiles file or URI | MLT PMTiles file | Local or range-readable archive |
References: java/…/Encode.kt• L28-234 java/…/EncodeCommandLine.kt• L92-165 java/…/EncodeCommandLine.kt• L468-505
Decoding interface
The decode command reads an MLT tile and turns it into a JSON view for inspection. It can repeat the decode to measure time, which makes it useful for quick checks of tile contents and decode cost rather than for bulk conversion.
The encode command can use the same decode path after conversion. This lets a user print the round-tripped MLT or MVT view and compare geometry or properties with the source tile.
References: java/…/Decode.kt• L17-103 java/…/Encode.kt• L293-329 java/…/EncodeCommandLine.kt• L381-467
Conversion flow
The conversion flow reads source tile bytes, creates the tile description needed by the codec, encodes MLT bytes, and optionally checks the result. Container modes add tile selection, metadata handling, and archive writing around the same per-tile conversion.
This diagram shows how both single-tile and container inputs reach the shared conversion path.
flowchart LR
A[ MVT tile ] --> C[Read and decode source]
B[MBTiles, offline DB, or PMTiles] --> S[Select tiles and metadata]
S --> C
C --> E[Encode MLT]
E --> Q[Optional compression]
Q --> O[Write MLT tile or archive]
E --> V[Optional decode, print, time, or compare]
The CLI reports failures through its process result and log output. Batch modes can stop on the first failure or continue where possible, so callers must choose the error policy when they need a complete archive or a best-effort conversion.
References: java/…/Conversion.kt• L172-307 java/…/EncodeCommandLine.kt• L565-624
Container workflows
MBTiles conversion produces a new SQLite tile set and carries source metadata into the result. Offline database conversion keeps the source database structure by updating tile records in a copied file. PMTiles conversion reads tile ranges from a local file or URI and writes a new archive with MLT format metadata and the resolved tile compression.
PMTiles work can use zoom bounds, parallel tasks, range caching, and content reuse. The reader groups coordinates that share a source byte range, and the writer reuses converted content for repeated ranges. These features reduce repeated reads and repeated writes for large archives, while the format check prevents non-MVT PMTiles input from entering the MVT-to-MLT conversion path.
References: java/…/MBTiles.kt• L24-29 java/…/OfflineDB.kt• L23-28 java/…/PMTiles.kt• L127-179 java/…/PMTiles.kt• L244-273
Remote archive access
PMTiles input is treated as a range-readable archive. The reader resolves tile coordinates through the archive directory, loads only the needed byte ranges, and exposes ranges of repeated tile content as one conversion unit. This supports local files and storage locations that provide byte-range reads.
The archive reader also carries archive metadata into the output. Its tile-coordinate range view lets the converter apply zoom limits before it schedules tile work.
References: java/…/ReadablePmtiles.kt• L17-20 java/…/ReadablePmtiles.kt• L66-103 java/…/ReadablePmtiles.kt• L192-223
Analysis and control
Validation controls
The CLI provides checks that compare the decoded result with the source. Users can check geometry, properties, or both. They can also ask the command to decode after a single-tile encode, print JSON views, and report elapsed time.
These controls serve two different needs: comparison checks protect conversion fidelity, while printing and timing help an engineer inspect or measure a tile. They do not replace the core codec's normal decode contract.
References: java/…/EncodeCommandLine.kt• L381-467 java/…/Conversion.kt• L285-301
Conversion policy
Command options map user choices into one conversion policy before tile work starts. The policy can preserve or remove IDs, handle property type mismatches by failing, coercing, or eliding values, select layer patterns, and request geometry or column optimizations.
The CLI validates the input mode and incompatible output choices before conversion. It also validates regular expressions, tessellation URLs, and compression names so that a bad request fails before it creates a partial result. PMTiles conversion then resolves absent compression settings from the source archive and carries the result into output metadata.
References: java/…/EncodeCommandLine.kt• L567-624 java/…/EncodeCommandLine.kt• L693-785 java/…/PMTiles.kt• L153-179
Parallel processing
Batch conversion can run tile tasks in parallel while keeping the work queue bounded. The queue limit can be tuned with MLT_THREAD_QUEUE_SIZE; when the queue is full, work runs in the caller instead of growing memory without limit. A serial mode remains available when parallel work is not requested.
Archive writers are shared resources, so the batch paths protect writes while allowing conversion work to run concurrently. The command waits for all scheduled work before it finalizes an output archive.
References: java/…/TaskRunner.kt• L7-45 java/…/MBTiles.kt• L75-146 java/…/PMTiles.kt• L181-215 java/…/PMTiles.kt• L440-449
Encoding service
The encode entry point can run as a small socket service. A client sends one command line and the service passes it through the same command parser as direct CLI use. This provides a simple way to submit repeated conversion requests without starting a new process for each request.
The service checks the requested port before it starts. It does not define a separate request format or a separate conversion feature set.
References: java/…/Server.kt• L10-60 java/…/Encode.kt• L36-49
Utility generation
Synthetic MLT fixtures
The mlt-tools module generates small, named MLT fixtures from controlled geometry, IDs, and property values. The fixtures cover normal tile content and combinations that are useful for checking codec behavior across supported encodings.
The generator writes both binary MLT data and a decoded JSON view. It forces the requested encoding choices instead of allowing size heuristics to replace them. It decodes each generated tile and compares the result with the expected view before it writes the fixture, so the output acts as a repeatable contract for codec changes.
References: java/…/SyntheticMltGenerator.java• L57-93 java/…/SyntheticMltUtil.java• L312-367
Fixture coverage
The utility set is aimed at edge conditions that are hard to inspect in large real tiles. Its generated cases include:
- Point, line, polygon, and multi-geometry shapes.
- Polygon holes, mixed geometry layers, and tessellated variants.
- Feature IDs and missing IDs.
- Numeric, string, boolean, null, and mixed properties.
- Integer encodings, string compression, shared dictionaries, and Morton ordering.
- Tile extents and byte-alignment cases for encoded integer streams.
The generator owns the Java-created binary and JSON files for the supported wire tag. It expects the fixture directory to contain only cross-language-owned hexdumps before generation, which prevents stale Java outputs from mixing with new results. Other generated views, such as hexdumps, remain owned by the matching cross-language tooling.
References: java/…/SyntheticMltGenerator.java• L57-93 java/…/SyntheticMltGenerator.java• L95-225 java/…/SyntheticMltGenerator.java• L284-619 java/…/SyntheticMltUtil.java• L47-56
Build and delivery
Standalone CLI artifacts
The Java build includes mlt-core, mlt-cli, and mlt-tools as separate Gradle modules. The CLI module packages standalone encode and decode jars, so users can run the commands with java -jar without assembling the dependency set themselves.
The CLI depends on the core module for tile conversion and adds support for archive formats, compression, logging, and Kotlin-based command code. The tools module depends on the same core module and exposes a Gradle task for fixture generation rather than a user-facing archive converter.
References: java/settings.gradle• L5-9 java/…/build.gradle• L25-63 java/…/build.gradle• L134-178 java/…/build.gradle• L22-58
Runtime configuration
Environment settings tune batch conversion without changing the command line. They control compression thresholds, progress logging, task queue size, and PMTiles cache size, heap-based limit, block size, and duplicate tracking.
Values with invalid syntax fall back to defaults and produce a warning. Values outside a required range fail a range check instead. A zero tile-log interval means that progress logging does not run, while a zero cache block size disables block alignment. The CLI help presents these settings with the options that use them.
References: java/…/Environment.kt• L3-40 java/…/Environment.kt• L42-100 java/…/EnvironmentResolverTest.kt• L25-179 java/…/EncodeCommandLine.kt• L627-655
Change checklist
When these files or sections are changed, remember to consider these:
- Keep the
encodeanddecodejar main classes aligned with their documented command roles in mlt-cli/build.gradle. - Keep accepted input types, output naming, and compression rules aligned between
EncodeCommandLinevalidation and the per-container conversion paths. - Keep PMTiles tile-type, compression, and output metadata mappings aligned with the archive reader and writer.
- Keep PMTiles duplicate-content tracking limits aligned with cache settings and archive write behavior.
- Keep synthetic fixture cleanup, exact-encoding behavior, and ownership rules aligned with
generateSyntheticMltso stale Java outputs cannot pass the cross-language check. - Keep environment variable names, range rules, and help text aligned with the values consumed by batch conversion and PMTiles caching.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| More than one input mode is supplied | The encode request is rejected before conversion | Require exactly one input mode |
| A single output file is used for several individual tiles | Multiple tiles would target one path | Use an output directory for multi-file input |
| PMTiles input is not MVT | The archive cannot enter the MVT-to-MLT path | Check the archive tile type |
| PMTiles source compression cannot be mapped to a supported output compression | Archive conversion fails before a valid MLT archive is finalized | Use a supported compression or set an explicit compatible option |
| A tile cannot be decoded or converted | The tile is skipped or the batch fails according to the error policy | Use comparison checks and choose --continue only for best-effort batches |
| A shared archive writer receives concurrent writes | Output data can be corrupted | Serialize archive writes and wait before finalization |
| Synthetic output already contains non-owned files | Fixture generation can overwrite or mix stale results | Refuse generation until the fixture directory is clean |
| An environment value passes parsing but fails its range rule | Startup or conversion configuration fails instead of using a safe value | Keep range checks aligned with the documented variable behavior |
Key files
| File | Why to read it |
|---|---|
| java/…/Encode.kt | Main encode lifecycle and user-visible operation selection |
| java/…/EncodeCommandLine.kt | Supported input, output, analysis, compression, and conversion controls |
| java/…/Conversion.kt | Shared per-tile conversion and validation path |
| java/…/MBTiles.kt | MBTiles batch conversion and metadata transfer |
| java/…/OfflineDB.kt | Offline database copy-and-update workflow |
| java/…/PMTiles.kt | PMTiles range conversion, caching, compression, and archive output |
| java/…/Decode.kt | Standalone MLT inspection and timing command |
| java/…/ReadablePmtiles.kt | PMTiles metadata and tile-range view used by conversion |
| java/…/Environment.kt | Runtime tuning values and validation rules |
| java/…/EnvironmentResolverTest.kt | Guarantees for environment parsing, defaults, and range checks |
| java/…/SyntheticMltGenerator.java | Synthetic fixture scope, cleanup contract, and generated case families |
| java/…/SyntheticMltUtil.java | Fixture validation and output contract |
| java/…/build.gradle | Standalone CLI jar tasks and module runtime boundary |
| java/…/build.gradle | Synthetic fixture generation task |