1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.commons.compress.compressors.pack200;
21
22 import java.io.FilterOutputStream;
23 import java.io.IOException;
24 import java.io.InputStream;
25 import java.io.OutputStream;
26
27
28
29
30
31
32
33 abstract class AbstractStreamBridge extends FilterOutputStream {
34
35 private InputStream inputStream;
36 private final Object inputStreamLock = new Object();
37
38 protected AbstractStreamBridge() {
39 this(null);
40 }
41
42 protected AbstractStreamBridge(final OutputStream outputStream) {
43 super(outputStream);
44 }
45
46
47
48
49 abstract InputStream createInputStream() throws IOException;
50
51
52
53
54 InputStream getInputStream() throws IOException {
55 synchronized (inputStreamLock) {
56 if (inputStream == null) {
57 inputStream = createInputStream();
58 }
59 }
60 return inputStream;
61 }
62
63
64
65
66 void stop() throws IOException {
67 close();
68 synchronized (inputStreamLock) {
69 if (inputStream != null) {
70 inputStream.close();
71 inputStream = null;
72 }
73 }
74 }
75 }