{"id":15038934,"url":"https://github.com/lz4/lz4-java","last_synced_at":"2025-05-13T23:04:36.548Z","repository":{"id":4001807,"uuid":"5099453","full_name":"lz4/lz4-java","owner":"lz4","description":"LZ4 compression for Java","archived":false,"fork":false,"pushed_at":"2024-09-19T17:00:16.000Z","size":13006,"stargazers_count":1126,"open_issues_count":74,"forks_count":252,"subscribers_count":54,"default_branch":"master","last_synced_at":"2025-04-08T21:18:04.149Z","etag":null,"topics":["compressor","decompression","java","jni-bindings","lz4-compression","lz4-compressors","lz4-java"],"latest_commit_sha":null,"homepage":null,"language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"dc42/RepRapFirmware","license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lz4.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGES.md","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2012-07-18T17:26:42.000Z","updated_at":"2025-03-25T05:50:54.000Z","dependencies_parsed_at":"2023-02-16T14:15:47.029Z","dependency_job_id":"f9fc6c7d-08ec-4d8b-ab1d-408ba959ba73","html_url":"https://github.com/lz4/lz4-java","commit_stats":{"total_commits":405,"total_committers":30,"mean_commits":13.5,"dds":0.5037037037037038,"last_synced_commit":"7c931bef32d179ec3d3286ee71638b23ebde3459"},"previous_names":["jpountz/lz4-java"],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lz4%2Flz4-java","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lz4%2Flz4-java/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lz4%2Flz4-java/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lz4%2Flz4-java/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lz4","download_url":"https://codeload.github.com/lz4/lz4-java/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251564613,"owners_count":21609932,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["compressor","decompression","java","jni-bindings","lz4-compression","lz4-compressors","lz4-java"],"created_at":"2024-09-24T20:40:49.810Z","updated_at":"2025-04-29T18:50:39.032Z","avatar_url":"https://github.com/lz4.png","language":"Java","readme":"# LZ4 Java\n\nLZ4 compression for Java, based on Yann Collet's work available at\nhttp://code.google.com/p/lz4/.\n\nThis library provides access to two compression methods that both generate a\nvalid LZ4 stream:\n - fast scan (LZ4):\n   - low memory footprint (~ 16 KB),\n   - very fast (fast scan with skipping heuristics in case the input looks\n     incompressible),\n   - reasonable compression ratio (depending on the redundancy of the input).\n - high compression (LZ4 HC):\n   - medium memory footprint (~ 256 KB),\n   - rather slow (~ 10 times slower than LZ4),\n   - good compression ratio (depending on the size and the redundancy of the\n     input).\n - interoperable (LZ4 Frame):\n   - overlay on top of lz4, that makes it system and library independent\n   - this is the version to employ in order to share lz4 compressed data\n     with other systems using different lz4 frameworks.\n\nThe streams produced by LZ4 and LZ4 HC use the same compression format,\nare very fast to decompress and can be decompressed by the same lz4-java decompressor instance.\n\nThe streams produced by LZ4 Frame can be read by other independent implementations of LZ4 Frame in any other language, including the `lz4` CLI tool.\n\n## Implementations\n\nFor LZ4 compressors, LZ4 HC compressors and decompressors, 3 implementations are\navailable:\n - JNI bindings to the original C implementation by Yann Collet,\n - a pure Java port of the compression and decompression algorithms,\n - a Java port that uses the sun.misc.Unsafe API in order to achieve compression\n   and decompression speeds close to the C implementation.\n\nHave a look at LZ4Factory for more information.\n\n## Compatibility notes\n\n - Compressors and decompressors are interchangeable: it is perfectly correct\n   to compress with the JNI bindings and to decompress with a Java port, or the\n   other way around.\n\n - Compressors might not generate the same compressed streams on all platforms,\n   especially if CPU endianness differs, but the compressed streams can be\n   safely decompressed by any decompressor implementation on any platform.\n\n## Examples\n\n```java\nLZ4Factory factory = LZ4Factory.fastestInstance();\n\nbyte[] data = \"12345345234572\".getBytes(\"UTF-8\");\nfinal int decompressedLength = data.length;\n\n// compress data\nLZ4Compressor compressor = factory.fastCompressor();\nint maxCompressedLength = compressor.maxCompressedLength(decompressedLength);\nbyte[] compressed = new byte[maxCompressedLength];\nint compressedLength = compressor.compress(data, 0, decompressedLength, compressed, 0, maxCompressedLength);\n\n// decompress data\n// - method 1: when the decompressed length is known\nLZ4FastDecompressor decompressor = factory.fastDecompressor();\nbyte[] restored = new byte[decompressedLength];\nint compressedLength2 = decompressor.decompress(compressed, 0, restored, 0, decompressedLength);\n// compressedLength == compressedLength2\n\n// - method 2: when the compressed length is known (a little slower)\n// the destination buffer needs to be over-sized\nLZ4SafeDecompressor decompressor2 = factory.safeDecompressor();\nint decompressedLength2 = decompressor2.decompress(compressed, 0, compressedLength, restored, 0);\n// decompressedLength == decompressedLength2\n```\n\n```java\nbyte[] data = \"12345345234572\".getBytes(\"UTF-8\");\nfinal int decompressedLength = data.length;\n\nLZ4FrameOutputStream outStream = new LZ4FrameOutputStream(new FileOutputStream(new File(\"test.lz4\")));\noutStream.write(data);\noutStream.close();\n\nbyte[] restored = new byte[decompressedLength];\nLZ4FrameInputStream inStream = new LZ4FrameInputStream(new FileInputStream(new File(\"test.lz4\")));\ninStream.read(restored);\ninStream.close();\n```\n\n# xxhash Java\n\nxxhash hashing for Java, based on Yann Collet's work available at https://github.com/Cyan4973/xxHash (old version\nhttp://code.google.com/p/xxhash/). xxhash is a non-cryptographic, extremly fast\nand high-quality ([SMHasher](http://code.google.com/p/smhasher/wiki/SMHasher)\nscore of 10) hash function.\n\n## Implementations\n\nSimilarly to LZ4, 3 implementations are available: JNI bindings, pure Java port\nand pure Java port that uses sun.misc.Unsafe.\n\nHave a look at XXHashFactory for more information.\n\n## Compatibility notes\n\n - All implementation return the same hash for the same input bytes:\n   - on any JVM,\n   - on any platform (even if the endianness or integer size differs).\n\n## Example\n\n```java\nXXHashFactory factory = XXHashFactory.fastestInstance();\n\nbyte[] data = \"12345345234572\".getBytes(\"UTF-8\");\nByteArrayInputStream in = new ByteArrayInputStream(data);\n\nint seed = 0x9747b28c; // used to initialize the hash value, use whatever\n                       // value you want, but always the same\nStreamingXXHash32 hash32 = factory.newStreamingHash32(seed);\nbyte[] buf = new byte[8]; // for real-world usage, use a larger buffer, like 8192 bytes\nfor (;;) {\n  int read = in.read(buf);\n  if (read == -1) {\n    break;\n  }\n  hash32.update(buf, 0, read);\n}\nint hash = hash32.getValue();\n```\n\n# Download\n\nYou can download released artifacts from [Maven Central](https://search.maven.org/search?q=g:org.lz4%20a:lz4-java).\n\nYou can download pure-Java lz4-java from [Maven Central](https://search.maven.org/search?q=g:org.lz4%20a:lz4-pure-java). These artifacts include the Safe and Unsafe Java versions but not JNI bindings. (Experimental)\n\n# Documentation\n\n - [lz4](https://lz4.github.io/lz4-java/1.8.0/docs/net/jpountz/lz4/package-summary.html)\n - [xxhash](https://lz4.github.io/lz4-java/1.8.0/docs/net/jpountz/xxhash/package-summary.html)\n - [changelog](https://github.com/lz4/lz4-java/blob/master/CHANGES.md)\n\n# Performance\n\nBoth lz4 and xxhash focus on speed. Although compression, decompression and\nhashing performance can depend a lot on the input (there are lies, damn lies\nand benchmarks), here are some benchmarks that try to give a sense of the\nspeed at which they compress/decompress/hash bytes.\n\n - [lz4 compression](https://lz4.github.io/lz4-java/1.8.0/lz4-compression-benchmark/)\n - [lz4 decompression](https://lz4.github.io/lz4-java/1.8.0/lz4-decompression-benchmark/)\n - [xxhash hashing](https://lz4.github.io/lz4-java/1.3.0/xxhash-benchmark/)\n\n# Build\n\n## Requirements\n\n - JDK version 7 or newer,\n - ant version 1.10.2 or newer,\n - ivy.\n\nIf ivy is not installed yet, ant can take care of it for you, just run\n`ant ivy-bootstrap`. The library will be installed under ${user.home}/.ant/lib.\n\nYou might hit an error like the following when the ivy in ${user.home}/.ant/lib is old. You can delete it and then run `ant ivy-bootstrap` again to install the latest version.\n```\n[ivy:resolve] \t\t::::::::::::::::::::::::::::::::::::::::::::::\n[ivy:resolve] \t\t::          UNRESOLVED DEPENDENCIES         ::\n[ivy:resolve] \t\t::::::::::::::::::::::::::::::::::::::::::::::\n```\n\n## Instructions\n\nFor lz4-java 1.5.0 or newer, first run `git submodule init` and then `git submodule update`\nto initialize the `lz4` submodule in `src/lz4`.\n\nThen run `ant`. It will:\n\n - generate some Java source files in `build/java` from the templates that are\n   located under `src/build`,\n - compile the lz4 and xxhash libraries and their JNI (Java Native Interface)\n   bindings,\n - compile Java sources in `src/java` (normal sources), `src/java-unsafe`\n   (sources that make use of `sun.misc.Unsafe`) and `build/java`\n   (auto-generated sources) to `build/classes`, `build/unsafe-classes` and\n   `build/generated-classes`,\n - generate a JAR file called lz4-${version}.jar under the `dist` directory.\n\nThe JAR file that is generated contains Java class files, the native library\nand the JNI bindings. If you add this JAR to your classpath, the native library\nwill be copied to a temporary directory and dynamically linked to your Java\napplication.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flz4%2Flz4-java","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flz4%2Flz4-java","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flz4%2Flz4-java/lists"}