• This repository has been archived on 18/May/2019
  • Stars
    star
    72
  • Rank 438,337 (Top 9 %)
  • Language
    Java
  • License
    Apache License 2.0
  • Created over 15 years ago
  • Updated almost 6 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

[NOT MAINTAINED ANYMORE] LZMA library for Java

Important: this project is not maintained anymore.

You should look at the Apache Commons Compress project for a rich set of supported compression formats, including LZMA.

LZMA library for Java

Build Status

http://jponge.github.com/lzma-java

This library provides LZMA compression for applications that run on the Java platform.

Background

This library is based on the Java LZMA SDK by Igor Pavlov. It provides some deserved enhancements.

While the original code works just fine, it has some serious issues for Java developers:

  • this is a straight port of non-object, procedural code written in C to Java, and
  • the code does not follow Java conventions (e.g., methods names start by capital letters)
  • configuration of the LZMA encoder and decoders require passing around arrays and numbers for which no proper documentation or constants exists other than source code, and
  • ...there is no stream api to plug into java.io streams.

There is unfortunately no public description of the LZMA algorithms other than source code, so a rewrite was clearly a hard task. I decided to create this library using the following methodology.

  1. Import the Java LZMA SDK code.
  2. Convert methods and package names to Java conventions.
  3. Reformat the code and organize imports.
  4. Remove the useless (at least in a library) command-line interface classes.
  5. Run static code analysis to clean the code (unused variables, unusued parameters, unused methods, expressions simplifications and more).
  6. Do some profiling.
  7. Build a streaming api that would fit into java.io streams.
  8. Provide some higher-level abstractions to the LZMA encoder / decoders configuration.

Although not a derivate work, the streaming api classes were inspired from the work of Christopher League. I reused his technique of fake streams and working threads to pass the data around between encoders/decoders and "normal" Java streams.

Using from Maven

The releases are pushed to Maven Central. Add the dependency as follows:

<dependency>
    <groupId>com.github.jponge</groupId>
    <artifactId>lzma-java</artifactId>
    <version>1.2</version>
</dependency>

Usage

There are two main Java package hierarchies:

  • lzma.sdk is the (reworked) Java LZMA SDK code, and
  • lzma.streams contains the LzmaInputStream and LzmaInputStream classes.

You will probably only be interested in using the lzma.streams package. The two stream classes use the good practices of constructor dependency injection, and you will need to pass them the decorated streams and LZMA encoder / decoders from the SDK.

You can simply instanciate a Decoder and pass it to the constructor of LzmaInputStream without specifying further configuration: it will read it from the input stream.

The Encoder class that LzmaOutputStream depends on needs some configuration. You can either do it manually (checkout the Encoder class to guess what those integer values mean!), or you can use the LzmaOutputStream.Builder class which makes it much easier to configure.

The following code is from a unit test. It should make the basic usage of the library relatively obvious:

public void test_round_trip() throws IOException
{
    final File sourceFile = new File("LICENSE");
    final File compressed = File.createTempFile("lzma-java", "compressed");
    final File unCompressed = File.createTempFile("lzma-java", "uncompressed");
    
    final LzmaOutputStream compressedOut = new LzmaOutputStream.Builder(
            new BufferedOutputStream(new FileOutputStream(compressed)))
            .useMaximalDictionarySize()
            .useEndMarkerMode(true)
            .useBT4MatchFinder()
            .build();
    
    final InputStream sourceIn = new BufferedInputStream(new FileInputStream(sourceFile));
    
    copy(sourceIn, compressedOut);
    sourceIn.close();
    compressedOut.close();
    
    final LzmaInputStream compressedIn = new LzmaInputStream(
            new BufferedInputStream(new FileInputStream(compressed)),
            new Decoder());
            
    final OutputStream uncompressedOut = new BufferedOutputStream(
            new FileOutputStream(unCompressed));
            
    copy(compressedIn, uncompressedOut);
    compressedIn.close();
    uncompressedOut.close();
    
    assertTrue(contentEquals(sourceFile, unCompressed));
    assertFalse(contentEquals(sourceFile, compressed));
}

License

The LZMA SDK is in the public domain. I relicensed the whole under the liberal Apache License Version 2.0.

Contact

The code, downloads and issue trackers are made available from GitHub at http://github.com/jponge/lzma-java. Do not hesitate to contribute by forking and asking for pulls!

More Repositories

1

vertx-in-action

Examples for the Manning "Vert.x in Action" book
Java
254
star
2

vertx-gradle-plugin

An opinionated Gradle plugin for Vert.x projects
Kotlin
113
star
3

izpack

(I no longer maintain this repository, please go to 'izpack/izpack')
Java
56
star
4

vertx-boot

An Eclipse Vert.x verticle to boot an application from HOCON configuration.
Java
44
star
5

vertx-go-tcp-eventbus-bridge

A Go Client for the Eclipse Vert.x TCP EventBus Bridge
Go
28
star
6

dotfiles

My dotfiles and configuration scripts
Shell
25
star
7

demo-vertx-kotlin-rxjava2-kubernetes

Demonstration of Eclipse Vert.x, Kotlin, RxJava2 and Kubernetes
Kotlin
24
star
8

boiler-vroom

Fun is fun, powered by Vert.x.
JavaScript
20
star
9

mutiny-workshop-examples

Java
15
star
10

todoapp-javaee6-angularjs

A todo list sample app made with Java EE 6 and AngularJS
JavaScript
11
star
11

oracle-javamag-vertx-rxjava

Java
10
star
12

guice-aspectj-sample

An example of Guice / AspectJ interaction
Java
7
star
13

run-with-privileges-on-osx

Tiny tool for running other programs with elevated privileges on Mac OS X.
C
7
star
14

vertx-devoxxfr19-demos

Vert.x demos for our session at Devoxx France 2019
Java
6
star
15

blobstore

A simple blob store in Java.
Java
5
star
16

pyappenginetodolist

A stupid todo lists manager for Google AppEngine / Python
Python
4
star
17

vim-golo

Golo Vim syntax
Vim Script
3
star
18

manning-twitch-october-2020

Java
3
star
19

qa-via-examples

Java
3
star
20

izpack-utils

IzPack utilities
Python
3
star
21

dlstats

DLStats - A NodeJS Product Downloads Stats System
JavaScript
3
star
22

vertx-elasticsearch-client

Moved to https://github.com/reactiverse/elasticsearch-client
3
star
23

aggregate-pom-gen

A simple tool to generate an aggregate Maven POM file from independent projects in sub-folders.
Go
3
star
24

build-graal-jvm

Script to build a JDK 8 image with Graal as a default compiler
Shell
2
star
25

izpack-launcher

IzPack native launcher
2
star
26

dm-greeter

Spring DM Greeter stupid example
2
star
27

ingolstadt-jug-january-2021

Java
2
star
28

phd-thesis-ubp-unsw-2008

Sources of my PhD thesis circa 2008 at Universitรฉ Blaise Pascal (Clermont-Ferrand, France) and UNSW (Sydney, Australia)
TeX
2
star
29

time-to-boot-server

Measure the time to boot a server and make a first connection
Go
2
star
30

izpack-full-svn-history-copy

The complete set of revisions of the IzPack Subversion repository before we switched to Git. It does not contain tags and branches informations. This repository will never be updated again.
Java
2
star
31

tinyinjector

A tiny references injector for Java.
Java
2
star
32

todoapp-bosswatch

A sample Java EE 6 app that receives messages from jponge/todoapp-javaee6-angularjs
JavaScript
2
star
33

lavajug-19

Java
1
star
34

dynamic-reference

Dynamic references in Java
Java
1
star
35

vertx-poitoujug-june-2017-code

Vert.x live coding at the PoitouJUG 2017
Java
1
star
36

sample-minimal-spring-ioc

A sample minimal Spring/Core app.
Java
1
star
37

vertx-4-mutiny-sql-client

Java
1
star
38

dice-proxy

A simple transparent HTTP proxy that detects common search engine queries, and puts query data into a MongoDB database.
Scala
1
star
39

website

My personal website
SCSS
1
star
40

jponge.github.com

My profile page on GitHub.
JavaScript
1
star
41

vertx-elasticsearch-client-failed-experiment

This was an experimental work in progress of an Elasticsearch client for Eclipse Vert.x. Turned out that this was not the right way to do it...
Java
1
star
42

quarkus-extensions-playground

Java
1
star
43

java7-vagrant-box

A Java Vagrant Box
Vim Script
1
star
44

JavaEE-Examples

A few Java EE examples
Java
1
star
45

quarkus-hr-devservice

HTML
1
star
46

servicemosaic-protocols

Source code from the ServiceMosaic Protocols research project.
Java
1
star
47

rebls21-paper-benchmarks

Java
1
star
48

aop-samples

A bunch of AOP samples
Java
1
star