View Javadoc

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   * *** Centre de Calcul de l'IN2P3 - Lyon (France) ***
10  * ***             http://cc.in2p3.fr/             ***
11  * ***************************************************
12  * File:   PostconnectedStdinOutputStream
13  * Author: Sylvain Reynaud (sreynaud@in2p3.fr)
14  * Date:   23 mai 2008
15  * ***************************************************
16  * Description:                                      */
17  /**
18   *
19   */
20  public class PostconnectedStdinOutputStream extends JobStdinOutputStream {
21      private InputStreamContainer m_in;
22  
23      /** constructor for StreamableJobInteractiveSet */
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      /////////////////////////////////// interface OutputStream ///////////////////////////////////
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      /////////////////////////////////////// private method ///////////////////////////////////////
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  }