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.DoesNotExistException;
5   import org.ogf.saga.error.NoSuccessException;
6   
7   import java.io.*;
8   
9   /* ***************************************************
10  * *** Centre de Calcul de l'IN2P3 - Lyon (France) ***
11  * ***             http://cc.in2p3.fr/             ***
12  * ***************************************************
13  * File:   PreconnectedStderrInputStream
14  * Author: Sylvain Reynaud (sreynaud@in2p3.fr)
15  * Date:   23 mai 2008
16  * ***************************************************
17  * Description:                                      */
18  /**
19   *
20   */
21  public class PreconnectedStderrInputStream extends JobStderrInputStream {
22      private OutputStreamContainer m_out;
23  
24      /** constructor for StreamableJobInteractiveSet */
25      public PreconnectedStderrInputStream(AbstractSyncJobImpl job) {
26          super(job);
27          m_out = new OutputStreamContainer();
28      }
29  
30      public OutputStream getOutputStreamContainer() {
31          return m_out;
32      }
33  
34      /////////////////////////////////// interface InputStream ///////////////////////////////////
35  
36      public int read() throws IOException {return this.stream().read();}
37      public int read(byte[] b) throws IOException {return this.stream().read(b);}
38      public int read(byte[] b, int off, int len) throws IOException {return this.stream().read(b, off, len);}
39      public long skip(long n) throws IOException {return this.stream().skip(n);}
40      public void close() throws IOException {this.stream().close();}
41  
42      /////////////////////////////////////// private method ///////////////////////////////////////
43  
44      private InputStream stream() throws IOException {
45          try {
46              switch(m_job.getState()) {
47                  case DONE:
48                  case CANCELED:
49                  case FAILED:
50                      return m_out.getInputStream();
51                  case RUNNING:
52                      throw new NoSuccessException("Not supported yet...");
53                  default:
54                      throw new DoesNotExistException("Stderr is not available because job is neither finished nor running");
55              }
56          } catch (Exception e) {
57              throw new IOException(e.getMessage());
58          }
59      }
60  }