-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDataPipeThread.java
More file actions
38 lines (37 loc) · 859 Bytes
/
DataPipeThread.java
File metadata and controls
38 lines (37 loc) · 859 Bytes
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
package map_reduce_demo;
import java.io.*;
import java.net.*;
public class DataPipeThread{
DataInputStream Dis;
DataOutputStream Dos;
long size;
public DataPipeThread(File file,DataOutputStream dos) throws IOException{
size = file.length();
Dis = new DataInputStream(new BufferedInputStream(new FileInputStream(file)));
Dos = dos;
}
public void run(){
try{
final int buffersize = 4086*5;
Dos.writeLong(size);
byte[] buf = new byte[buffersize];
while(true){
int read = 0;
if( (read = Dis.read(buf, 0, min(size,buffersize)) ) == -1 ){
break;
}
Dos.write(buf,0,read);
Dos.flush();
}
Dis.close();
} catch (IOException e) {
e.printStackTrace();
}
}
private int min(long size,int y) {
if(size<y)
return (int) size;
else
return y;
}
}