1 package fr.in2p3.jsaga.impl.job.instance.stream;
2
3 import fr.in2p3.jsaga.impl.job.instance.AbstractSyncJobImpl;
4 import org.ogf.saga.error.*;
5
6 import java.io.*;
7
8
9
10
11
12
13
14
15
16
17
18
19
20 public class PostconnectedStdinOutputStream extends JobStdinOutputStream {
21 private InputStreamContainer m_in;
22
23
24 public PostconnectedStdinOutputStream(AbstractSyncJobImpl job) throws TimeoutException, DoesNotExistException, NoSuccessException, NotImplementedException {
25 super(job);
26 m_in = new InputStreamContainer();
27 }
28
29 public InputStream getInputStreamContainer() {
30 return m_in;
31 }
32
33
34
35 public void write(int b) throws IOException {this.stream().write(b);}
36 public void write(byte[] b) throws IOException {this.stream().write(b);}
37 public void write(byte[] b, int off, int len) throws IOException {this.stream().write(b, off, len);}
38 public void flush() throws IOException {this.stream().flush();}
39 public void close() throws IOException {this.stream().close(); m_in.finishWriting();}
40
41
42
43 private OutputStream stream() throws IOException {
44 try {
45 switch(m_job.getState()) {
46 case NEW:
47 return m_in.getOutputStream();
48 case RUNNING:
49 throw new NoSuccessException("Not supported yet...");
50 default:
51 throw new DoesNotExistException("Stdin is not available because job is finished or suspended");
52 }
53 } catch (Exception e) {
54 throw new IOException(e.getMessage());
55 }
56 }
57 }