Dateieintrag mit Downloaden

Luis Felger

Grünschnabel
Hallo,
ich habe ein kleines Problem mit Java. Ich habe einen Downloader entwickelt, der das Spiel mit den aktuellsten Jars versogen soll.
Leider hatte ich zu erst folgendes Problem:
Beim Downloaden einer .zip-Datei (in der die aktuellen Jar-Paks enthalten sind) wurde immer falsch gedownloadet. Die MD5-Summen unterschieden sich und die Zip konnte nicht geöffnet werden.

Dann habe ich zum Checken der Summe eine log-Datei erstellt mit dem Programm md5sums.
Dieses Programm lieferte mir die Summe, die ich dan in die log gespeichert habe. (Mehr Mals kontrolliert, dass keine Tippfehler drin sind!)
Dann hab' ich diese auch noch zu meiner Downloader-Klasse hinzugefügt. Jetzt downloaded das Programm mir die falsche .zip-Datei + eine log-Datei, in der der Inhalt der .zip-Datei auch drin ist. Ich verstehe es nicht mehr.

Hier der Code:

init.java
Code:
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package launcher;

import java.io.IOException;
import output.write;

/**
 *
 * @author Luis
 */
public class init {
    private downloader dw;
    private downloader dw2;
    private String     file = "update_1.zip";
    private write      writer;
    private write      writer2;
    
    public init(int version) throws IOException {
        dw  = new downloader("http://www.bspaddr.de/bsp/src/update/update_"+ version +".zip");
        writer = new write(file, dw.getText());
        
        dw2 = new downloader("http://www.bspaddr.de/bsp/src/update/log");
        writer2 = new write("log", dw2.getText());
        System.out.print(dw.getText());
    }
}

write.java
Code:
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package output;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

/**
 *
 * @author Luis
 */
public class write {
    private static FileOutputStream fos;
    
    public write(String filename, String ressource) throws FileNotFoundException, IOException
    {
        fos = new FileOutputStream(filename);
        
        for(int i = 0; i < ressource.length(); i++) {
            fos.write((byte)ressource.charAt(i));
        }
        
        fos.close();
    }
}

downloader.java
Code:
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package launcher;

import java.io.BufferedInputStream;
import java.io.DataInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;

/**
 *
 * @author Luis
 */
public class downloader {
    private static URL             u;
    private static InputStream     is = null;
    private static DataInputStream dis;
    private static String          s;
    private static String          data = "";
    
    public downloader(String internetURL) throws IOException {
        try {
            u = new URL(internetURL);
            is = u.openStream();
            dis = new DataInputStream(new BufferedInputStream(is));
            
            while((s = dis.readLine()) != null) {
                data += s;
            }
        } catch(MalformedURLException mue) {
            data = mue.toString();
        } finally {
            try {
                is.close();
            } catch(IOException ioe) {
            }
        }
    }
    
    public String getText() {
        return data;
    }
}

Wie manche warscheinlich schon vermutet haben: Ich benutze Netbeans.

Mein Verzeichnisbaum: (gamelib.jar)

Code:
| launcher
| |
| |--donwloader.java
| |
| |--init.java
|
| output
| |
| |--write.java

Das ganze wird folgendermaßen ausgeführt:

Code:
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package update.test;

import java.io.IOException;
import launcher.init;

/**
 *
 * @author Luis
 */
public class UpdateTest {
    private static init in;
    
    public UpdateTest() throws IOException {
        in = new init(1);
    }
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) throws IOException {
        // TODO code application logic here
        new UpdateTest();
    }
}
 
Zurück