1 package fr.in2p3.jsaga.impl.job.instance.stream;
2
3 import java.io.*;
4
5
6
7
8
9
10
11
12
13
14
15
16
17 public class InputStreamContainer extends InputStream {
18 private ByteArrayOutputStream m_out;
19
20 public InputStreamContainer() {
21 m_out = new ByteArrayOutputStream();
22 }
23
24 public OutputStream getOutputStream() {
25 return m_out;
26 }
27
28 public void finishWriting() throws IOException {
29 m_out.close();
30 m_buffer = new ByteArrayInputStream(m_out.toByteArray());
31 }
32
33
34
35 public int read() throws IOException {return this.stream().read();}
36 public int read(byte[] b) throws IOException {return this.stream().read(b);}
37 public int read(byte[] b, int off, int len) throws IOException {return this.stream().read(b, off, len);}
38 public long skip(long n) throws IOException {return this.stream().skip(n);}
39 public void close() throws IOException {this.stream().close();}
40
41
42
43 private ByteArrayInputStream m_buffer;
44 private InputStream stream() throws IOException {
45 if (m_buffer != null) {
46 return m_buffer;
47 } else {
48 return new ByteArrayInputStream(new byte[]{});
49 }
50 }
51 }