Java API Reference¶
Java library for ISCC (ISO 24138:2024) code generation via JNI. All 35 Tier 1 symbols are exposed as
static methods on the IsccLib class. The native library is loaded automatically from the JAR's
META-INF/native/ directory, with fallback to System.loadLibrary for development environments.
Installation¶
Quick Example¶
import io.iscc.iscc_lib.IsccLib;
String iscc = IsccLib.genMetaCodeV0("Die Unendliche Geschichte", null, null, 64);
System.out.println(iscc); // e.g. "ISCC:AAA..."
Constants¶
Algorithm constants exposed as public static final int fields on IsccLib.
| Constant | Value | Description |
|---|---|---|
META_TRIM_NAME |
128 |
Maximum UTF-8 byte length for the name parameter |
META_TRIM_DESCRIPTION |
4096 |
Maximum UTF-8 byte length for the description parameter |
META_TRIM_META |
128_000 |
Maximum decoded payload size in bytes for the meta element |
IO_READ_SIZE |
4_194_304 |
Default read buffer size for streaming I/O (4 MB) |
TEXT_NGRAM_SIZE |
13 |
N-gram window size for text similarity hashing |
Classes¶
IsccDecodeResult¶
Result of decoding an ISCC unit string via IsccLib.isccDecode(). All fields are public final.
package io.iscc.iscc_lib;
public class IsccDecodeResult {
public final int maintype;
public final int subtype;
public final int version;
public final int length;
public final byte[] digest;
}
| Field | Type | Description |
|---|---|---|
maintype |
int |
MainType enum value (0–7) |
subtype |
int |
SubType enum value (0–7) |
version |
int |
Version enum value (0–255) |
length |
int |
Length index from the ISCC header |
digest |
byte[] |
Raw digest bytes |
SumCodeResult¶
Result of IsccLib.genSumCodeV0(). All fields are public final.
package io.iscc.iscc_lib;
public class SumCodeResult {
public final String iscc;
public final String datahash;
public final long filesize;
public final String[] units;
}
| Field | Type | Description |
|---|---|---|
iscc |
String |
Composite ISCC-CODE string |
datahash |
String |
Hex-encoded BLAKE3 multihash of the file |
filesize |
long |
Byte length of the file |
units |
String[] |
[Data-Code, Instance-Code] ISCC strings, or null unless addUnits |
Conformance¶
conformanceSelftest¶
Run all ISCC conformance tests against vendored test vectors.
Returns true if all tests pass, false otherwise.
Code Generation¶
genSumCodeV0 returns a SumCodeResult; the nine other gen*V0 methods and
genIsccIdV1 return an ISCC string (prefixed with ISCC:) on success. All throw
IllegalArgumentException on invalid input.
genMetaCodeV0¶
Generate a Meta-Code from name and optional metadata.
public static native String genMetaCodeV0(
String name,
String description,
String meta,
int bits
);
| Parameter | Type | Description |
|---|---|---|
name |
String |
Title or name of the content (required, trimmed to 128 bytes) |
description |
String |
Optional description text (nullable, trimmed to 4096 bytes) |
meta |
String |
Optional JSON string or data: URL (nullable) |
bits |
int |
Bit length of the generated code (default: 64, multiple of 32, 32 to 256) |
genTextCodeV0¶
Generate a Text-Code from plain text content.
| Parameter | Type | Description |
|---|---|---|
text |
String |
Plain text content (required) |
bits |
int |
Bit length of the generated code (default: 64, multiple of 32, 32 to 256) |
genImageCodeV0¶
Generate an Image-Code from 1024 grayscale pixel bytes.
| Parameter | Type | Description |
|---|---|---|
pixels |
byte[] |
32×32 grayscale pixel array (1024 bytes, values 0–255) |
bits |
int |
Bit length of the generated code (default: 64, max 256) |
byte[] pixels = new byte[1024]; // 32×32 grayscale thumbnail
String iscc = IsccLib.genImageCodeV0(pixels, 64);
genAudioCodeV0¶
Generate an Audio-Code from a Chromaprint feature vector.
| Parameter | Type | Description |
|---|---|---|
cv |
int[] |
Signed 32-bit Chromaprint feature values |
bits |
int |
Bit length of the generated code (default: 64, multiple of 32, 32 to 256) |
int[] fingerprint = {123456, -789012, 345678};
String iscc = IsccLib.genAudioCodeV0(fingerprint, 64);
genVideoCodeV0¶
Generate a Video-Code from frame signature data.
| Parameter | Type | Description |
|---|---|---|
frameSigs |
int[][] |
Array of MPEG-7 frame signature vectors (each int[]) |
bits |
int |
Bit length of the generated code (default: 64, multiple of 32, 32 to 256) |
Each frame signature is a 380-element int[] array.
int[][] frameSigs = {new int[380], new int[380]};
String iscc = IsccLib.genVideoCodeV0(frameSigs, 64);
genMixedCodeV0¶
Generate a Mixed-Code from multiple Content-Code strings.
| Parameter | Type | Description |
|---|---|---|
codes |
String[] |
Array of ISCC Content-Code strings (requires >= 2) |
bits |
int |
Bit length of the generated code (default: 64, multiple of 32, 32 to 256) |
genDataCodeV0¶
Generate a Data-Code from raw byte data.
| Parameter | Type | Description |
|---|---|---|
data |
byte[] |
Raw byte content |
bits |
int |
Bit length of the generated code (default: 64, multiple of 32, 32 to 256) |
genInstanceCodeV0¶
Generate an Instance-Code from raw byte data.
| Parameter | Type | Description |
|---|---|---|
data |
byte[] |
Raw byte content |
bits |
int |
Bit length of the generated code (default: 64, multiple of 32, 32 to 256) |
genIsccCodeV0¶
Generate a composite ISCC-CODE from individual unit codes.
| Parameter | Type | Description |
|---|---|---|
codes |
String[] |
Array of ISCC unit code strings (must include Data + Instance) |
wide |
boolean |
true for 256-bit output, false for 128-bit |
String dataCode = IsccLib.genDataCodeV0(data, 64);
String instanceCode = IsccLib.genInstanceCodeV0(data, 64);
String isccCode = IsccLib.genIsccCodeV0(
new String[]{dataCode, instanceCode}, false
);
genSumCodeV0¶
Generate a composite ISCC-CODE from a file in a single pass, computing Data-Code and Instance-Code together.
public static native SumCodeResult genSumCodeV0(String path, int bits, boolean wide, boolean addUnits);
| Parameter | Type | Description |
|---|---|---|
path |
String |
Path of the file to process |
bits |
int |
Bit length of the generated codes (default: 64, multiple of 32, 64 to 256) |
wide |
boolean |
true for 256-bit output (requires bits >= 128) |
addUnits |
boolean |
true to include the Data-Code and Instance-Code in units |
Throws IllegalArgumentException on invalid input or a file I/O error.
SumCodeResult result = IsccLib.genSumCodeV0("example.bin", 64, false, true);
System.out.println(result.iscc); // "ISCC:KUA..."
System.out.println(result.filesize); // size in bytes
genIsccIdV1¶
Mint an experimental ISCC-IDv1 from an explicit timestamp.
| Parameter | Type | Description |
|---|---|---|
timestamp |
long |
Microsecond timestamp, 52-bit range (0 to 2^52 - 1) |
hubId |
int |
HUB-ID, 12-bit range (0 to 4095) |
realm |
int |
Realm identifier, encoded as the SubType (0 or 1) |
Produces an 80-bit ISCC-IDv1 (a 52-bit microsecond timestamp plus a 12-bit HUB-ID) and returns the
ISCC string directly. Throws IllegalArgumentException on out-of-range values.
There is no dedicated decoder — recover the fields with isccDecode and unpack the 8-byte
big-endian digest:
String iscc = IsccLib.genIsccIdV1(1751831876325218L, 1, 0);
// iscc == "ISCC:MAIGHFECJMOPMIAB"
IsccDecodeResult d = IsccLib.isccDecode(iscc);
// d.version == 1 (ISCC-IDv1)
long n = new java.math.BigInteger(1, java.util.Arrays.copyOf(d.digest, 8)).longValue();
long timestamp = n >>> 12; // 1751831876325218
int hubId = (int) (n & 0xFFF); // 1
int realm = d.subtype; // 0
Experimental
ISCC-IDv1 is not part of ISO 24138 and may change in a minor release.
Text Utilities¶
Text processing functions for normalization and cleaning.
textClean¶
Clean and normalize text for display. Applies NFKC normalization, removes control characters (except newlines), normalizes CRLF to LF, collapses consecutive empty lines, and strips leading/trailing whitespace.
textRemoveNewlines¶
Remove newlines and collapse whitespace to single spaces.
textTrim¶
Trim text so its UTF-8 encoded size does not exceed nbytes. Multi-byte characters that would be
split are dropped entirely. Leading/trailing whitespace is stripped from the result.
| Parameter | Type | Description |
|---|---|---|
text |
String |
Input text |
nbytes |
int |
Maximum UTF-8 byte length |
textCollapse¶
Normalize and simplify text for similarity hashing. Applies NFD normalization, lowercasing, removes whitespace and characters in Unicode categories C, M, and P, then recombines with NFKC normalization.
Encoding¶
encodeBase64¶
Encode bytes as base64url (RFC 4648 section 5, no padding).
jsonToDataUrl¶
Convert a JSON string to a data URL with base64 encoding. Uses application/ld+json media type when
the JSON contains an @context key, otherwise application/json.
Throws IllegalArgumentException on invalid JSON input.
Codec¶
encodeComponent¶
Encode header fields and a raw digest into a base32-encoded ISCC unit string (without ISCC:
prefix).
public static native String encodeComponent(
int mtype,
int stype,
int version,
int bitLength,
byte[] digest
);
| Parameter | Type | Description |
|---|---|---|
mtype |
int |
MainType enum value (0–255) |
stype |
int |
SubType enum value (0–255) |
version |
int |
Version enum value (0–255) |
bitLength |
int |
Digest bit length (multiple of 32, 32 to 256, for Meta through Flake; 64, 72, 80 or 96 for ID) |
digest |
byte[] |
Raw digest bytes (length >= bitLength / 8) |
Throws IllegalArgumentException on invalid input.
isccDecode¶
Decode an ISCC unit string into its header components and raw digest. Strips an optional ISCC:
prefix before decoding.
Returns an IsccDecodeResult with maintype, subtype, version, length, and digest fields.
Throws IllegalArgumentException on invalid input.
IsccDecodeResult result = IsccLib.isccDecode("ISCC:EAASKDNZNYGUUF5A");
System.out.println(result.maintype); // 2 (Content)
System.out.println(result.subtype); // 0 (Text)
isccDecompose¶
Decompose a composite ISCC-CODE into individual ISCC-UNITs.
Returns an array of base32-encoded ISCC-UNIT strings (without ISCC: prefix). Throws
IllegalArgumentException on invalid input.
encodeSeq¶
Encode ISCC-UNITs into an ISCC-SEQ byte string (IEP-0020).
Returns the concatenated raw unit bytes (header + body per unit) in the given order. Each unit may
be given with or without the ISCC: prefix, in any case. Base32 decoding is strict: = padding,
non-zero spare bits and non-ASCII case-fold aliases are rejected. Units of MainType ISCC-CODE, ID or
FLAKE are rejected. Throws IllegalArgumentException if units is empty or a unit is invalid.
decodeSeq¶
Decode an ISCC-SEQ byte string into ISCC-UNITs (IEP-0020).
Returns ISCC:-prefixed ISCC-UNIT strings in wire order. Strict reader: throws
IllegalArgumentException on empty input, malformed units and trailing bytes.
byte[] data = IsccLib.encodeSeq(new String[] {
"ISCC:EAD2RASIYU5IKLENP2OFI4CHZGRWYQCSW2WKX3Y6FJGOCXSYNYGLGBI"
});
// data.length == 34, starts with 0x20 0x07 0xa8 0x82 0x48 0xc5
String[] units = IsccLib.decodeSeq(data);
// units: ["ISCC:EAD2RASIYU5IKLENP2OFI4CHZGRWYQCSW2WKX3Y6FJGOCXSYNYGLGBI"]
// The round trip is defined on bytes: encodeSeq(decodeSeq(data)) reproduces data
assert java.util.Arrays.equals(IsccLib.encodeSeq(units), data);
Sliding Window¶
slidingWindow¶
Generate sliding window n-grams from a string.
| Parameter | Type | Description |
|---|---|---|
seq |
String |
Input string |
width |
int |
Window width in Unicode characters (must be >= 2) |
Throws IllegalArgumentException if width is less than 2.
String[] ngrams = IsccLib.slidingWindow("Hello World", 3);
// ["Hel", "ell", "llo", "lo ", "o W", " Wo", "Wor", "orl", "rld"]
Algorithm Primitives¶
Low-level algorithm functions for SimHash, MinHash, content-defined chunking, and video hashing.
algSimhash¶
Compute a SimHash from a sequence of equal-length hash digests. The output length matches the input digest length.
Throws IllegalArgumentException on invalid input (empty array or unequal digest lengths).
algMinhash256¶
Compute a 256-bit MinHash digest from 32-bit integer features. Uses 64 universal hash functions with bit-interleaved compression.
Returns a 32-byte MinHash digest. Throws IllegalArgumentException for an empty array.
algCdcChunks¶
Split data into content-defined chunks using gear rolling hash.
| Parameter | Type | Description |
|---|---|---|
data |
byte[] |
Raw byte data to split |
utf32 |
boolean |
If true, align cut points to 4-byte boundaries |
avgChunkSize |
int |
Target average chunk size (default 1024) |
softHashVideoV0¶
Compute a similarity-preserving hash from video frame signatures.
| Parameter | Type | Description |
|---|---|---|
frameSigs |
int[][] |
Array of MPEG-7 frame signature vectors |
bits |
int |
Output bit length |
Returns a byte array of length bits / 8. Throws IllegalArgumentException if input is empty.
Streaming Hashers¶
Streaming hashers process large data incrementally without loading the entire content into memory.
Each hasher follows the lifecycle: *New() → *Update() (repeated) → *Finalize() → *Free().
Streaming hashers use opaque long handles for native memory management. Callers must call the
corresponding *Free method to release native memory.
Warning
The first *Finalize() call consumes the hasher state, even when it fails (for example on an
invalid bits value). After that, subsequent *Update() or *Finalize() calls throw
IllegalStateException. You must still call *Free() to release the wrapper.
DataHasher¶
Streaming Data-Code hasher using content-defined chunking and MinHash.
// Create a new DataHasher — returns an opaque handle
long hasher = IsccLib.dataHasherNew();
// Push data into the hasher (repeatable)
IsccLib.dataHasherUpdate(hasher, chunk1);
IsccLib.dataHasherUpdate(hasher, chunk2);
// Finalize and get the ISCC string
String iscc = IsccLib.dataHasherFinalize(hasher, 64);
// Free the native memory (required)
IsccLib.dataHasherFree(hasher);
dataHasherNew¶
Returns an opaque long handle to the hasher.
dataHasherUpdate¶
Throws IllegalStateException if the hasher has been finalized and IllegalArgumentException for a
zero handle.
dataHasherFinalize¶
Throws IllegalStateException if already finalized and IllegalArgumentException for a zero handle
or on error. The first call consumes the hasher even when it throws IllegalArgumentException.
dataHasherFree¶
Zero/null handle is a no-op. Each handle must be freed exactly once.
InstanceHasher¶
Streaming Instance-Code hasher using BLAKE3.
// Create a new InstanceHasher — returns an opaque handle
long hasher = IsccLib.instanceHasherNew();
// Push data into the hasher (repeatable)
IsccLib.instanceHasherUpdate(hasher, chunk1);
IsccLib.instanceHasherUpdate(hasher, chunk2);
// Finalize and get the ISCC string
String iscc = IsccLib.instanceHasherFinalize(hasher, 64);
// Free the native memory (required)
IsccLib.instanceHasherFree(hasher);
instanceHasherNew¶
Returns an opaque long handle to the hasher.
instanceHasherUpdate¶
Throws IllegalStateException if the hasher has been finalized and IllegalArgumentException for a
zero handle.
instanceHasherFinalize¶
Throws IllegalStateException if already finalized and IllegalArgumentException for a zero handle
or on error. The first call consumes the hasher even when it throws IllegalArgumentException.
instanceHasherFree¶
Zero/null handle is a no-op. Each handle must be freed exactly once.
Error Handling¶
All methods that accept user input throw IllegalArgumentException on invalid arguments:
- Empty or null required parameters (e.g., empty
nameingenMetaCodeV0) - Invalid
bitsvalues (must be a multiple of 32, range 32–256) - Malformed ISCC strings passed to
isccDecodeorisccDecompose - A zero handle passed to a streaming hasher's
*Updateor*Finalize
try {
String iscc = IsccLib.genTextCodeV0("Hello World", 64);
System.out.println(iscc);
} catch (IllegalArgumentException e) {
System.err.println("Error: " + e.getMessage());
}
Streaming hasher operations after finalization throw IllegalStateException. A failed JVM
allocation inside a native call (e.g., a result larger than the Java heap) surfaces as
OutOfMemoryError.
Memory Management¶
Most Java types (String, byte[], int[]) are managed by the JVM garbage collector. The only
resources requiring manual cleanup are streaming hasher handles:
dataHasherFree(long ptr)— release a DataHasherinstanceHasherFree(long ptr)— release an InstanceHasher
Use try-finally to ensure cleanup: