Writing game-file-storage with GZip support?
<pre><code>    public static void loadModels() {
    try {
        DataInputStream indexFile = new DataInputStream(new FileInputStream("./cache/models.idx"));
        DataInputStream dataFile = new DataInputStream(new FileInputStream("./cache/models.dat"));
        int length = indexFile.readInt();
        for(int i = 0; i &lt; length; i++) {
            int id = indexFile.readInt();
            int invlength = indexFile.readInt();
            byte[] data = new byte[invlength];
            dataFile.readFully(data);
            //System.out.println("ID: "+ id +" Length: "+ invlength +" Data: "+ data);
            Class30_Sub2_Sub4_Sub6.method460(data, id);
        }
        indexFile.close();
        dataFile.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
</code></pre>

<p>That's my void for loading my models(theres 57056 of them by the way) Method460(data, id); refers to calling the models from the storage.</p>

<pre><code>package com.rs.modelcompressor.file;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.DataOutputStream;
import java.util.List;
import java.util.ArrayList;

import com.rs.modelcompressor.Main;

public class FileController {

private List&lt;Model&gt; modelList = new ArrayList&lt;Model&gt;();

public FileController() {   
}

private byte[] build() {
    byte[] returnValue;
    int i = 0;
    for(Model m : modelList) {
        i += m.getData().length;
    }
    returnValue = new byte[i];
    int offset = 0;
    for(Model model : modelList) {
        Main.getUserInterface().getTextArea().append("Copying Model Data: "+ model.getId()+"\n");
        System.arraycopy(model.getData(), 0, returnValue , offset, model.getData().length);
        offset += model.getData().length;
    }
    return returnValue;
}

public void compress() {
    int offset = 0;
    if(modelList.size() == 0) {
        Main.getUserInterface().getTextArea().append("No models loaded\n");
        return;
    }

    try {
        byte[] data = build();
        Main.getUserInterface().getTextArea().append("Creating data file\n");
        DataOutputStream dataFile = new DataOutputStream(new FileOutputStream("models.dat"));
        dataFile.write(data, 0, data.length);
        Main.getUserInterface().getTextArea().append("Length of written data: "+ data.length +"\n");
        dataFile.flush();
        dataFile.close();
    } catch (Exception e) {
        Main.getUserInterface().getTextArea().append("An error occured while writing data file\n");
    }
    try {
        Main.getUserInterface().getTextArea().append("Creating index file\n");
        DataOutputStream indexFile = new DataOutputStream(new FileOutputStream("models.idx"));
        indexFile.writeInt(modelList.size());
        for(Model m : modelList) {
            indexFile.writeInt(m.getId());
            indexFile.writeInt(m.getData().length);
        }
        indexFile.flush();
        indexFile.close();
    } catch (Exception e2) {
        Main.getUserInterface().getTextArea().append("An error occured while writing index file\n");
    }
    Main.getUserInterface().getTextArea().append("model.dat and model.idx created\n");
}           

public void loadModels() {
    modelList.clear();
    File[] file = new File("models/").listFiles();
    Main.getUserInterface().getTextArea().append("Found "+ file.length +" model files\n");
    for(File f : file) {
        byte[] data = new byte[(int)f.length()];
        try {
            FileInputStream in = new FileInputStream(f);
            in.read(data);
            in.close();
        } catch (Exception e) {
            Main.getUserInterface().getTextArea().append(e.getMessage()+"\n");
        }
        String s = f.getName();
        int id = Integer.parseInt(s.substring(0, s.indexOf(".")));
        Main.getUserInterface().getTextArea().append("ID: "+ id +" Data: "+ data +" Length: "+ (int)f.length()+"\n");   
        Model m = new Model();
        m.setData(data);
        m.setId(id);
        modelList.add(m);
    }       
}
</code></pre>

<p>Thats the compressor class, but I have no  idea on doing this.</p>

<p>Look, I want to GZip the model files to reduce file size... but then, if I compress the gzipped, files, it'll call them with the .idx which will lead to wrong sizes being used => errors... How am I supposed to work it out so, the files are GZipped inside the .dat, but the .idx has sizes/lengths/w.e of the ungzipped files and how to make the loader support gzip?</p>
