-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathThreads.java
39 lines (36 loc) · 863 Bytes
/
Threads.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
package FInal;
import java.io.*;
import java.net.HttpURLConnection;
import java.nio.channels.FileChannel;
public class Threads implements Runnable{
private int block;
private int size;
private InputStream is;
private byte[][] buffer;
private long check[];
private HttpURLConnection c;
private int downloaded;
public Threads(int start,int size,HttpURLConnection c,byte[][] buffer,long check[]){
this.block=start;
this.size=size;
this.c=c;
this.buffer=buffer;
this.check=check;
}
public void run(){
downloaded=block*size;
try {
byte[] r=new byte[1];
for(int i=0;i<size;i++){
is=c.getInputStream();
is.skip(downloaded);
is.read(r);
buffer[block][i]=r[0];
downloaded++;
System.out.println("Thread "+block+" Byte :"+downloaded);
}
} catch (IOException e) {
e.printStackTrace();
}
}
}