Dependency-free Java 17 binding for FastFileLink, backed by the bundled portable
ffl.com APE.
The public API is handwritten Java semantics on top of a low-level binding generated by APEBind. The generated layer is reproducible and can be replaced without overwriting the public API.
- Java 17 or newer.
- No runtime Java dependencies.
- No external Python installation is required by the generated binding or by
ffl.com.
With Maven:
mvn packageOr with the repository's dependency-free build script:
python scripts/build.pyThe latter writes build/ffl-java-0.1.2.jar using only javac and jar.
If an operation fails with TLSError([0x6300]), WSL may be routing the bundled
.com APE through Windows interop. Run the following in WSL, then restart the WSL
session:
sudo sh -c 'echo -1 > /proc/sys/fs/binfmt_misc/WSLInterop'import io.fastfilelink.ffl.Ffl;
import java.nio.file.Path;
System.out.println(Ffl.version());
try (var session = Ffl.share(Path.of("release.zip"))) {
System.out.println(session.link());
session.on("completed", event -> System.out.println(event.name()));
}session.on(name, listener) follows FFL's integrated events: ready is
/share/available, link is /share/link/create, started is /transfer/create,
progress is /transfer/progress, completed is /transfer/complete, and
failed is /transfer/fail. HTTP, WebRTC, and direct P2P also emit their own
events, such as /download/complete. Those stay on session.onRaw, with every
wire name available as a constant on FFLHookEvents and the payloads documented
in binding/ffl.hook-events.md; event.link(), event.error() and
event.progress() read the common fields. completed follows
/transfer/complete, so one transfer notifies that listener once. Each accepted
hook POST is answered with HTTP 200 and {} unless a ShareOptions responder
answers it (respondTo, uploadConfirmation). The bundled ffl.com emits these
names.
session.onStdoutLine(listener) and session.onStderrLine(listener) hand over the
process's stdout and stderr line by line (the core's log lines and tracebacks go to
stderr), replaying what was printed before the listener was attached.
session.onAny(listener) receives every hook event whatever its name, for a single
dispatcher. session.link() waits for the core's --json result the first time it
is called (up to 20 seconds; a timeout throws APETimeoutException and leaves the
share running), so an app that only listens to the link event never blocks on it;
in upload mode the core writes that file only after the upload, so prefer the event
there. FFL.shareVfs("vfs://host:port", options) shares a tree served by a VFS
endpoint instead of local files: the URI is the share target itself, and the
core's own --vfs server mode is not involved. FFLEnvironment.language(...) and
FFLEnvironment.loggingLevel(...) build the variables the core reads at start-up
for APERuntime.builder().environment(...).
Routes a /hook/server/endpoints/register responder registers (a share page's
/manifest, /thumb, ...) are fetched by the core from the hook URL's host and
port, which is ffl-java's own receiver. ShareOptions.Builder.hookEndpointProxy(base)
makes the receiver forward every request that is not a hook event to base + path
(method, query, headers and body included) and relay the status, headers and body
back; without it those requests are answered 405.
Account commands: FFL.login(email) starts the one-time-code dialogue of ffl login --mode cli and returns a LoginSession (otpRequested(), submitOtp(code),
onOtpRejected(...), result()); the core is detected waiting for the code by its
unterminated prompt, so this works in any UI language, and the mail stays in the
user's language. FFL.status() parses ffl status into an AuthStatus (that
command runs with FFL_LANGUAGE=en because the core prints text only) and
FFL.logout() clears the stored credentials.
Configure sharing with a normal Java builder:
import io.fastfilelink.ffl.ShareOptions;
var options = ShareOptions.builder()
.e2ee(true)
.maxDownloads(1)
.timeoutSeconds(1800)
.receipt("me@example.com")
.build();
try (var session = Ffl.share(Path.of("release.zip"), options)) {
System.out.println(session.link());
}Flags whose CLI value is optional have two Java forms:
ShareOptions.builder().upload(); // --upload
ShareOptions.builder().upload("6 hours"); // --upload "6 hours"
ShareOptions.builder().receipt(); // --receipt
ShareOptions.builder().receipt("a@b.com");Share in-memory data without managing a temporary file yourself:
try (var session = Ffl.shareText("hello", "message.txt")) {
System.out.println(session.link());
}
try (var session = Ffl.shareBytes(bytes, "payload.bin")) {
System.out.println(session.link());
}The temporary source remains alive for the share session and is removed when the session is stopped or closed.
Download:
import io.fastfilelink.ffl.DownloadOptions;
var result = Ffl.download(
"https://example.fastfilelink/...",
DownloadOptions.builder()
.outputPath(Path.of("download.zip"))
.resume(true)
.build()
);
System.out.println(result.outputPath());
System.out.println(result.transferMode());The same classes run inside an Android app (minSdk 26, no core library desugaring):
the Java 9-11 helpers the library uses are on D8's backport list and records are
desugared. The app ships the core itself as jniLibs/<abi>/libffl.so (the APE renamed)
and describes its process environment with APERuntime:
APERuntime runtime = APERuntime.builder()
.binary(Paths.get(nativeLibraryDir, "libffl.so"))
.launcher(Paths.get(nativeLibraryDir, "libape.so").toString()) // optional ape loader
.shellWrapper(false) // no /bin/sh -c in an app sandbox
.workingDirectory(filesDir.toPath())
.environment("TMPDIR", tmpDir)
.environment(FFLEnvironment.language("zh_Hant"))
.build();
FFLClient client = new FFLClient(runtime);Share a tree served by the app's own VFS server with client.shareVfs("vfs://127.0.0.1:port", options) and point ShareOptions.Builder.hookEndpointProxy("http://127.0.0.1:port") at the
same server so the share page's /manifest and /thumb routes reach it. The hook receiver
runs on a loopback ServerSocket, so the app needs no com.sun.net.httpserver.
scripts/build-android.ps1 (or .sh) builds build/android/ffl-java-<version>.jar:
the compiled classes without the 48 MB apebind/ffl.com, for implementation files(...) in
Gradle. docs/apebind-upstream-notes.md lists the generated-layer changes behind all this.
For shares protected with HTTP Basic Auth, set FFL_AUTH_PASSWORD in the application
environment and configure only the username. The bundled FFL subprocess inherits the
environment, so the password stays out of its command line:
export FFL_AUTH_PASSWORD='use-your-secret-manager'$env:FFL_AUTH_PASSWORD = 'use-your-secret-manager'var options = ShareOptions.builder()
.authUser("deploy")
.build();
try (var session = Ffl.share(Path.of("release.zip"), options)) {
System.out.println(session.link());
}Do not also configure authPassword: FFL gives the explicit CLI option precedence
over FFL_AUTH_PASSWORD. The environment variable applies to the sharing side; pass
download credentials explicitly when downloading a protected link.
Key generation:
var keys = Ffl.keygen("alice");
System.out.println(keys.privateKeyPath());
System.out.println(keys.publicKeyPath());Raw CLI escape hatch:
var result = Ffl.raw(java.util.List.of("download", "--help"));
System.out.println(result.stdout());Machine-owned files live under:
src/main/java/apebind/generated/ffl/
src/main/resources/apebind/ffl.com
Handwritten FFL semantics live under:
src/main/java/io/fastfilelink/ffl/
apebind generate (see "Updating FFL" below) rewrites only the machine-owned
layer.
The binding workflow is:
ffl.com
-> inspect raw CLI grammar
-> review binding/ffl.discovered.apebind.yaml
-> manually maintain binding/ffl.apebind.yaml semantics
-> regenerate low-level Java binding
-> handwritten ffl-java API
Hidden commands that root help does not enumerate are listed in
binding/ffl.commands.yaml.
The test groups deliberately run independently because some Linux Cosmopolitan runner environments can become unreliable after many APE executions in one long process chain. This is not required on normal Windows APE execution, but keeping the groups independent also makes failures easier to isolate.
python scripts/test.py unit
python scripts/test.py packaging
python scripts/test.py realunittests semantic option mapping and FFL-specific output parsing without network I/O.packagingbuilds a JAR, compiles a clean consumer against it, then callsFfl.version()through the bundledffl.com.realexecutes the bundled FastFileLink v4.2.3 APE, verifies hiddendownload/keygencommands, and performs a real key generation.
The generated layer under src/main/java/apebind/generated/ffl/ is plain
APEBind output; never edit it by hand. When the
core gains flags or commands, merge them into binding/ffl.apebind.yaml (hidden commands
into binding/ffl.commands.yaml), replace src/main/resources/apebind/ffl.com, then
regenerate from an APEBind checkout:
python -m apebind generate ..\ffl-java\binding\ffl.apebind.yaml `
--ape ..\ffl-java\src\main\resources\apebind\ffl.com --lang java -o build\gen-ffl
Copy-Item build\gen-ffl\src\main\java\apebind\generated\ffl\*.java ..\ffl-java\src\main\java\apebind\generated\ffl\Then run scripts/test.ps1 unit and scripts/test.ps1 real. docs/apebind-upstream-notes.md
has the details, including the three generated classes FFL does not use.