java-fwf is a fast, type-safe Java 17+ library for parsing, validating, hydrating, and exporting Fixed Width Files (FWF).
It is part of the Fixed Width File Ecosystem and fully implements the fwf-compliance-tests v1.0.0 specification.
- Type-Safe Columns:
CharColumn,RightCharColumn,PositiveIntegerColumn,PositiveDecimalColumn,DateColumn,TimeColumn, andDateTimeColumn. - Flexible Descriptors: Structured records with
HeaderRowDescriptor,DetailRowDescriptor, andFooterRowDescriptor. - Cross-Language Hydration: Dehydrate/Hydrate descriptors to/from JSON representations compatible with Python
pyfwfand PHPphp-fwf. - Multiple Output Renders: Export layout specifications to Markdown, ReStructuredText (RST), or HTML tables via
RenderUtils. - Full Test Suite & Coverage: Verified line (>95%) and branch (>85%) coverage via JaCoCo and JUnit 5.
- Git Hooks Ready: Pre-configured
pre-commitandpre-pushhooks.
Add the dependency to your pom.xml:
<dependency>
<groupId>io.github.kelsoncm</groupId>
<artifactId>fwf</artifactId>
<version>1.0.0</version>
</dependency>implementation 'io.github.kelsoncm:fwf:1.0.0'import io.github.kelsoncm.fwf.columns.*;
import io.github.kelsoncm.fwf.descriptors.*;
import io.github.kelsoncm.fwf.readers.Reader;
import java.util.List;
import java.util.Map;
public class Quickstart {
public static void main(String[] args) {
// 1. Define columns
CharColumn nameCol = new CharColumn("name", 20, "User Name");
PositiveIntegerColumn ageCol = new PositiveIntegerColumn("age", 3, "Age in years");
// 2. Define row and file descriptors
DetailRowDescriptor detail = new DetailRowDescriptor(List.of(nameCol, ageCol));
FileDescriptor fileDescriptor = new FileDescriptor(List.of(detail));
// 3. Read fixed-width file content
String content = "KELSON MEDEIROS 045\nMARIA SILVA 030\n";
Reader reader = new Reader(content, fileDescriptor, "\n");
for (Map<String, Object> row : reader) {
System.out.println("Name: " + row.get("name") + " | Age: " + row.get("age"));
}
}
}Generated Javadoc is published to GitHub Pages:
- Landing Page: docs/index.html
- Javadoc API: docs/apidocs/index.html
Run unit tests and JaCoCo coverage check:
mvn clean testSet up pre-commit and pre-push hooks:
pre-commit install
pre-commit install --hook-type pre-pushRun checks manually:
pre-commit run --all-filesThis project is licensed under the MIT License - see the LICENSE file for details.