Mam problem, z którym nie daję już sobie rady.
Program wyciąga z "input.zip" plik xml'owy "rozpakowany.xml" i zapisuje jego zawartość do "plik1". Jednak w tym "plik1" pojawiają się jakieś NULLe przez co najwyraźniej nie zapisuje całego "rozpakowany.hml".
Czy moglibyście mi coś poradzić?
Proszę o podpowiedź.

Klasa Unzip:


package decompressing;

import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.zip.*;

public class Unzip {

    private InputStream source = null;
    private InputStream manifest = null;

    public void setSource(InputStream source){
        this.source = source;
    }

    public InputStream getManifest(){
        return this.manifest;
    }

    public void extractManifest() throws IOException{
        ZipInputStream zis = new ZipInputStream(this.source);
        ZipEntry entry = null;

        while ((entry = zis.getNextEntry()) != null){
            if(entry.getName().equals("rozpakowany.xml")){
                byte[] bytes = new byte[(int)entry.getSize()];

                int x = 0;                                 //problem jest raczej gdzieś tu w while'u w read'ach
                while(1024<entry.getSize()-x){
                    zis.read(bytes, x, 1024);
                    x = x + 1024;
                }
                zis.read(bytes, x, (int)entry.getSize()-x);

                ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
                this.manifest = bais;
                test(bais, "plik1");

            }
        }
    }

    private void test(InputStream is, String name){
        OutputStream out = null;
        try {
            File f = new File(name);
            out = new FileOutputStream(f);
            byte[] buf = new byte[512];
            int len;
            while ((len = is.read(buf)) > 0) {
                out.write(buf, 0, len);
            }
            out.close();
            is.close();
        } catch (IOException ex) {
            Logger.getLogger(Unzip.class.getName()).log(Level.SEVERE, null, ex);
        } finally {
            try {
                out.close();
            } catch (IOException ex) {
                Logger.getLogger(Unzip.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }
}

Klasa Main:


package decompressing;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;

public class Main {
    public static void main(String[] args) throws FileNotFoundException, IOException {
        Unzip u = new Unzip();
        File f = new File("input.zip");
        FileInputStream is = new FileInputStream(f);
        u.setSource(is);
        u.extractManifest();
    }

}