1 package rydeen.io;
2
3 import rydeen.Destination;
4 import rydeen.ProcessTarget;
5 import rydeen.TargetSource;
6
7 import java.io.ByteArrayOutputStream;
8 import java.io.IOException;
9 import java.io.OutputStream;
10
11
12
13
14
15
16
17
18
19
20
21 public class GlueDestination implements Destination{
22 private MemoryTargetSource source = new MemoryTargetSource();
23 private boolean closed = false;
24
25
26
27
28
29
30
31
32
33
34
35 public TargetSource getTargetSource(){
36 return source;
37 }
38
39
40
41
42
43
44
45
46
47 @Override
48 public OutputStream getOutput(final String name) throws IOException{
49 return new ByteArrayOutputStream(){
50 @Override
51 public void close() throws IOException{
52 super.close();
53
54 byte[] data = toByteArray();
55 source.addTarget(new ByteArrayProcessTarget(source, name, data));
56 }
57 };
58 }
59
60
61
62
63
64
65
66
67
68 @Override
69 public OutputStream getOutput(ProcessTarget target) throws IOException{
70 return getOutput(target.getName());
71 }
72
73
74
75
76 @Override
77 public void output(ProcessTarget target) throws IOException{
78 source.addTarget(target);
79 }
80
81
82
83
84 @Override
85 public synchronized void close(){
86 closed = true;
87 }
88
89 @Override
90 public boolean isClosed(){
91 return closed;
92 }
93 }