JPz'log Coin Coin and Plop da Plop

26Aug/094

lzma-java version 1.0

I am pleased to announce the availability of a small library that I have been working on for a few days.

lzma-java is a LZMA compression library for Java, based on the Java LZMA SDK and that (mainly) brings an easier to use API.

The library is available under the terms of the liberal Apache License Version 2.0, and the resulting Jar eats only 45kb, with no extra dependency required.

You can download it from GitHub. You can also report issues there, and even fork it if you want to help developing it!

Usage is relatively straightforward. Here is how you can create an LZMA-compressing output stream using a convenience builder:

final LzmaOutputStream compressedOut = new LzmaOutputStream.Builder(
            new BufferedOutputStream(new FileOutputStream(compressed)))
            .useMaximalDictionarySize()
            .useEndMarkerMode(true)
            .useBT4MatchFinder()
            .build();

And here is how you get an LZMA decompression input stream:

final LzmaInputStream compressedIn = new LzmaInputStream(
            new BufferedInputStream(new FileInputStream(compressed)),
            new Decoder());

I hope you will find it useful for your own projects!

By the way I would be interested in pushing the project Maven POM to a central repository, but I have no clue how to do that. Any help will be appreciated :-)

Share this post:
  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • DZone
  • Live
  • Netvibes
  • StumbleUpon
  • Technorati
  • FriendFeed
  • Wikio
  • Twitter
  • Identi.ca
  • Reddit
  • RSS
  • Slashdot

Related posts:

  1. Sites moved successfuly! (and other stuff)
  2. Initialization blocks in Java
  3. Playing with Berkeley DB Java Edition and Guice
  4. Building Glassfish v3 from SVN
  5. IzPack and Java Web Start

Comments (4) Trackbacks (0)
  1. Hi

    Thanks for this useful library.

    I haven’t published a POM into a central repository either, but I found this description how to do it:
    http://maven.apache.org/guides/mini/guide-central-repository-upload.html
    Maybe this helps.

  2. seems to me that useMaxmalDictionarySize does not achieve highest compression ratio. The maxmalDictionarySize seems to be “1 << 28" instead of just 28.

    public Builder useMaximalDictionarySize()
    {
    dictionnarySize = 28;
    return this;
    }

  3. This doesn’t work:

    import java.io.*;
    import lzma.sdk.lzma.Decoder;
    import lzma.streams.LzmaInputStream;

    public class TestLzma {
    public static void main(String[] args) throws Exception {
    LzmaInputStream in = new LzmaInputStream(new BufferedInputStream(new FileInputStream(“C:\\Users\\leo\\Documents\\test.tar.lzma”)), new Decoder());
    BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(“C:\\Users\\leo\\Documents\\test.tar”));
    int n = 0;
    byte[] buffer = new byte[4096];
    while (-1 != (n = in.read(buffer))){
    out.write(buffer, 0, n);
    }
    in.close();
    out.close();
    }
    }

    I can open the .tar.lzma file with 7-zip. I created it with
    tar –lzma -cvf test.tar.lzma filesIAdded

    However, this writes an empty tar file. I opened the tar file with notepad, and there was no characters in it. The size said 0 bytes. Why is this not writing anything?

    The start lzma file was about 468 kB.

    I tried debugging it, and the read method of the lzmainputstream wasn’t reading anything. Just returning 0 once, then -1. Why?


Leave a comment


No trackbacks yet.

JPz'log is Digg proof thanks to caching by WP Super Cache