Menu

Preset dictionary in Java

Chad
2012-01-22
2013-05-30
  • Chad

    Chad - 2012-01-22

    First of all, thank you for this excellent library.

    I am trying to use XZ for Java 1.0 (from http://tukaani.org/xz/xz-java-1.0.zip) with a preset dictionary. The JRE is 1.6u30 When I use a preset dictionary, the program enters an infinite loop. I stepped through it in the debugger and found that the "while" loop in LZMA2OutputStream.writeEndMarker() never terminates, apparently because uncompressedSize in writeChunk() is always zero and therefore pendingSize never decreases.

    I do not know if I am making a mistake in calling the library or if this is a bug in the library.

    When I remove the line "opt.setPresetDict(oldBytes);" it works fine. Here is the code I am testing (disclaimer: I know it's messy; it's just for a quick test):

    package local;
    import java.io.*;
    import org.tukaani.xz.*;
    public class Main {
        public static void main(String[] args) {
            try {
                RandomAccessFile raf = new RandomAccessFile("initDict", "r");
                byte[] oldBytes = new byte[(int)raf.length()];
                raf.readFully(oldBytes);
                raf.close();
    
                LZMA2Options opt = new LZMA2Options(7);
                opt.setPresetDict(oldBytes);
    
                FileOutputStream out = new FileOutputStream("output");
                FinishableWrapperOutputStream fout = new FinishableWrapperOutputStream(out);            
                FinishableOutputStream lzmaOut = opt.getOutputStream(fout);
    
                raf = new RandomAccessFile("input", "r");
                byte[] newBytes = new byte[(int)raf.length()];
                raf.readFully(newBytes);
                raf.close();
    
                lzmaOut.write(newBytes);
                lzmaOut.close();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
    
     
  • Lasse Collin

    Lasse Collin - 2012-01-27

    Looks like a bug in the library. Thanks for the bug report. I don't immediately see what's wrong, but I try to fix it in a few days.

     
  • Lasse Collin

    Lasse Collin - 2012-01-28

    I have hopefully fixed it now. See today's commits in the git repository.

     

Log in to post a comment.