1
2
3
4
5
6
7
8
9
10
11 package org.mule.impl.model.streaming;
12
13 import java.io.IOException;
14 import java.io.InputStream;
15
16 import edu.emory.mathcs.backport.java.util.concurrent.CountDownLatch;
17
18
19
20
21 public class CloseCountDownInputStream extends InputStream
22 {
23
24 private InputStream delegate;
25 private CountDownLatch latch;
26
27 public CloseCountDownInputStream(InputStream delegate, CountDownLatch latch)
28 {
29 this.delegate = delegate;
30 this.latch = latch;
31 }
32
33 public int read() throws IOException
34 {
35 return delegate.read();
36 }
37
38 public int read(byte b[]) throws IOException
39 {
40 return delegate.read(b);
41 }
42
43 public int read(byte b[], int off, int len) throws IOException
44 {
45 return delegate.read(b, off, len);
46 }
47
48 public void close() throws IOException
49 {
50 try
51 {
52 delegate.close();
53 }
54 finally
55 {
56 if (null != latch)
57 {
58 latch.countDown();
59 }
60 }
61 }
62
63 }