Java quickstart

This is a ~60-second round-trip with no cloud account and no setup: snapshot a directory, push it to a local file:// store, pull it back somewhere else, and confirm it is byte-for-byte identical — all through the Java binding. Every snapshot ID is a 64-character lowercase hex string, bit-identical to the one the snapdir CLI and every other binding produce for the same content.

1. Install

Add the dependency (Maven org.snapdir:snapdir:1.11.0 or Gradle implementation("org.snapdir:snapdir:1.11.0")) — see Install snapdir for Java for the JDK 17 run flags and platform notes. The jar embeds the native library, so there is nothing else to build.

2. Snapshot + push

Compute the content-addressed ID of a directory with the synchronous Snapdir.id, then upload it to a local store with the async Snapdir.push. The store is addressed by a URI — for a no-setup round-trip that is file://$PWD/store, just a directory on disk:

import io.snapdir.Snapdir;

public class Push {
    public static void main(String[] args) throws Exception {
        String dir = "./demo";

        // Nothing is stored yet — id() just hashes the directory.
        String id = Snapdir.id(dir, null);
        System.out.println(id);   // 64-char lowercase hex, e.g. <snapshot-id>

        // file://$PWD/store — a local store, no cloud account needed.
        String store = "file://" + System.getProperty("user.dir") + "/store";

        // push() uploads the snapshot and returns the same id.
        String pushed = Snapdir.push(dir, store, null).get();
        System.out.println(pushed);
    }
}

push returns exactly the ID that id printed. Objects are stored at content-addressed keys, so unchanged files are never uploaded twice.

3. Pull it back

Pull the snapshot into a fresh directory. pull fetches every object from the store, re-hashes it, and checks it out — so a successful pull is a proof of integrity. Re-running id on the restored directory yields the same ID:

import io.snapdir.Snapdir;

public class Pull {
    public static void main(String[] args) throws Exception {
        String id = args[0];   // the <snapshot-id> from step 2
        String store = "file://" + System.getProperty("user.dir") + "/store";

        Snapdir.pull(id, store, "./restored", null).get();

        // Byte-for-byte identical — prints the same <snapshot-id>.
        System.out.println(Snapdir.id("./restored", null));
    }
}

That is the same snapshot ID you would get from snapdir id or snapdir push on the CLI — the manifests are bit-identical across every binding.