-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSplit.java
54 lines (48 loc) · 1.17 KB
/
Split.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package FInal;
import java.io.*;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.nio.channels.FileChannel;
import javax.swing.JProgressBar;
public class Split implements Runnable{
private int block;
private int size;
private InputStream is;
private byte[][] buffer;
private HttpURLConnection c;
private String url;
private Status s;
public Split(int start,int size,byte[][] buffer,String url){
this.block=start;
this.size=size;
this.buffer=buffer;
this.url=url;
URL u;
try {
u = new URL(url);
c=(HttpURLConnection) u.openConnection();
is=c.getInputStream();
} catch (MalformedURLException e) {
e.printStackTrace();
}
catch(IOException e1){
}
}
public void run(){
try {
int acc=0,tot=c.getContentLength();
is.skip(block*size);
byte[] r=new byte[1];
for(int i=0;i<size;i++){
System.out.println("Thread- "+block+" Byte number :"+(block*size+i));
is.read(r);
Downloader.count++;
int temp=(int)java.lang.Math.ceil((Downloader.count*100)/(8.0*size));
buffer[block][i]=r[0];
}
} catch (IOException e) {
e.printStackTrace();
}
}
}