Soda, mein Downloadmanager ist im Prinzip schon fertig programmiert, nur funktioniert er leider nicht wie er sollte.
Ich teile die Datei in drei gleichgroße Teile und lade sie separat in temporäre Dateien um sie anschließend zu einer zusammenzufügen. Allerdings werden bei jedem der 3 Pakete um einiges weniger Daten vom Server gesendet als angefordert!
Ich hab mir von allen 3 Teildownloads die Header-Fields ausgeben lassen:
+++ CONNECTION 0 +++
null:
HTTP/1.1 206 Partial Content
ETag:
"394b-4e5566-46d1db8197d40"
Date:
Mon, 06 Jul 2009 11:52:03 GMT
Content-Length:
1711223
Last-Modified:
Wed, 24 Jun 2009 20:11:57 GMT
Keep-Alive:
timeout=5, max=100
Accept-Ranges:
bytes
Connection:
Keep-Alive
Content-Type:
text/plain
Server:
Apache/2.2.11 (Unix) DAV/2 mod_ssl/2.2.11 OpenSSL/0.9.8i PHP/5.2.8 mod_apreq2-20051231/2.6.0 mod_perl/2.0.4 Perl/v5.10.0
Content-Range:
bytes 0-1711222/5133670
+++ CONNECTION 1 +++
null:
HTTP/1.1 206 Partial Content
ETag:
"394b-4e5566-46d1db8197d40"
Date:
Mon, 06 Jul 2009 11:52:03 GMT
Content-Length:
1711223
Last-Modified:
Wed, 24 Jun 2009 20:11:57 GMT
Keep-Alive:
timeout=5, max=100
Accept-Ranges:
bytes
Connection:
Keep-Alive
Content-Type:
text/plain
Server:
Apache/2.2.11 (Unix) DAV/2 mod_ssl/2.2.11 OpenSSL/0.9.8i PHP/5.2.8 mod_apreq2-20051231/2.6.0 mod_perl/2.0.4 Perl/v5.10.0
Content-Range:
bytes 1711223-3422445/5133670
+++ CONNECTION 2 +++
null:
HTTP/1.1 206 Partial Content
ETag:
"394b-4e5566-46d1db8197d40"
Date:
Mon, 06 Jul 2009 11:52:03 GMT
Content-Length:
1711224
Last-Modified:
Wed, 24 Jun 2009 20:11:57 GMT
Keep-Alive:
timeout=5, max=100
Accept-Ranges:
bytes
Connection:
Keep-Alive
Content-Type:
text/plain
Server:
Apache/2.2.11 (Unix) DAV/2 mod_ssl/2.2.11 OpenSSL/0.9.8i PHP/5.2.8 mod_apreq2-20051231/2.6.0 mod_perl/2.0.4 Perl/v5.10.0
Content-Range:
bytes 3422446-5133669/5133670
Das ist die Methode für den Downloadvorgang: ```/**
* Download a file over a network stream via special HTTP-technique.
*
* @param videoURL URL of target online file
* @throws IOException
*/
private void multipartDownload( URL videoURL, int contentLength, int parts ) throws IOException {
String mbFileSize = Double.toString( getMegaByte(contentLength) );
int loadedBytes = 0;
int partLength = contentLength/parts;
int[] bufLen = new int[parts];
byte[] buf = new byte[BUFFER_SIZE];
File[] partFiles = new File[parts];
URLConnection[] partConnections = new URLConnection[parts];
BufferedOutputStream[] partOutputStreams = new BufferedOutputStream[parts];
BufferedInputStream[] partInputStreams = new BufferedInputStream[parts];
System.out.println( "Content-Length: " + contentLength );
System.out.println( "Part-Length: " + partLength + " (" + parts + ")");
// activate progress bar
if ( this.progressBar != null ) {
this.progressBar.setMaximum( contentLength+1 );
}
for ( int i=0; i < parts; i++ ) {
partFiles** = File.createTempFile( this.output.getName(), ".part"+i );
partOutputStreams** = new BufferedOutputStream( new FileOutputStream(partFiles**) );
partConnections** = this.getURLConnection( videoURL );
if ( i+1 == parts ) {
partConnections**.setRequestProperty( "Range", "bytes=" + (partLength*i) + "-" + (contentLength-1) ); // last index != content length!!!
} else {
partConnections**.setRequestProperty( "Range", "bytes=" + (partLength*i) + "-" + (partLength*i+partLength-1) );
}
System.out.println( "
+++ CONNECTION " + i + " +++" );
listHeaderFields( partConnections** );
partInputStreams** = new BufferedInputStream( partConnections**.getInputStream() );
}
while ( loadedBytes < contentLength ) {
for ( int i=0; i < parts; i++ ) {
if ( bufLen** != -1 ) {
if ( (bufLen**=partInputStreams**.read(buf)) != -1 ) {
// write bytes to harddisk
partOutputStreams**.write( buf, 0, bufLen** );
loadedBytes += bufLen**;
} else {
partInputStreams**.close();
partOutputStreams**.close();
}
}
}
// update progress bar
if ( this.progressBar != null ) {
this.progressBar.setValue( loadedBytes );
this.progressBar.setString( getMegaByte(loadedBytes) + " von " + mbFileSize + " MB geladen" );
}
}
if ( this.progressBar != null )
this.progressBar.setString( "Downloadsegmente werden zusammengefuegt ..." );
// merge part files
this.mergeParts( partFiles );
if ( this.progressBar != null ) {
this.progressBar.setString( "Download komplett!" );
this.progressBar.setValue( contentLength+1 );
}
}```
Hat jemand eine Ahnung was hier falsch läuft?
In diesem Fall sind die Teildateien immer um 7.287 Bytes zu klein.