-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwriteThread.java
More file actions
47 lines (35 loc) · 1.28 KB
/
Copy pathwriteThread.java
File metadata and controls
47 lines (35 loc) · 1.28 KB
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
import java.util.concurrent.locks.Lock;
import java.util.concurrent.ConcurrentHashMap;
public class writeThread extends Thread {
ConcurrentHashMap<Integer, byte[]> outQ;
int next;
Lock outQ_lock;
boolean[] compressionDone;
writeThread(ConcurrentHashMap<Integer, byte[]> outQ, Lock outQ_lock, boolean[] compressionDone) {
this.outQ = outQ;
this.next = 0;
this.outQ_lock = outQ_lock;
this.compressionDone = compressionDone;
}
public void run() {
boolean running = true;
while(running)
{
outQ_lock.lock();
byte[] nextOutput = this.outQ.get(this.next);
if (!(nextOutput == null))
{
System.out.write(nextOutput,0,nextOutput.length);
this.outQ.remove(next);
next++;
if (System.out.checkError()) {
System.err.println("Error: Write error on <stdout>");
System.exit(1);
}
}
if (this.outQ.isEmpty() && (this.compressionDone[0] == true))
running = false;
outQ_lock.unlock();
}
}
}