View Javadoc

1   package fr.in2p3.jsaga.impl.file.stream;
2   
3   import fr.in2p3.jsaga.adaptor.data.DataAdaptor;
4   import fr.in2p3.jsaga.adaptor.data.read.FileReaderGetter;
5   import fr.in2p3.jsaga.impl.url.URLHelper;
6   import org.ogf.saga.SagaObject;
7   import org.ogf.saga.error.*;
8   import org.ogf.saga.session.Session;
9   import org.ogf.saga.url.URL;
10  
11  import java.io.IOException;
12  
13  /* ***************************************************
14  * *** Centre de Calcul de l'IN2P3 - Lyon (France) ***
15  * ***             http://cc.in2p3.fr/             ***
16  * ***************************************************
17  * File:   FileInputStreamPipedImpl
18  * Author: Sylvain Reynaud (sreynaud@in2p3.fr)
19  * Date:   23 mars 2008
20  * ***************************************************
21  * Description:                                      */
22  /**
23   *
24   */
25  public class FileInputStreamPipedImpl extends AbstractAsyncFileInputStreamImpl {
26      private DataAdaptor m_connection;
27      private PipedInputStreamImpl m_inStream;
28  
29      /** constructor */
30      FileInputStreamPipedImpl(Session session, URL url, FileReaderGetter adaptor, boolean disconnectable) throws NotImplementedException, IncorrectURLException, AuthenticationFailedException, AuthorizationFailedException, PermissionDeniedException, BadParameterException, DoesNotExistException, TimeoutException, NoSuccessException {
31          super(session);
32  
33          // save connection
34          m_connection = (disconnectable ? adaptor : null);
35  
36          // open stream
37          URL fileUrl = URLHelper.toFileURL(url);
38          m_inStream = new PipedInputStreamImpl(
39                  adaptor,
40                  fileUrl.getPath(),
41                  fileUrl.getQuery());
42      }
43  
44      /** clone */
45      public SagaObject clone() throws CloneNotSupportedException {
46          FileInputStreamPipedImpl clone = (FileInputStreamPipedImpl) super.clone();
47          clone.m_connection = m_connection;
48          clone.m_inStream = m_inStream;
49          return clone;
50      }
51  
52      public void close() throws IOException {
53          // close stream
54          m_inStream.close();
55  
56          // close connection
57          if (m_connection != null) {
58              try {
59                  m_connection.disconnect();
60              } catch (NoSuccessException e) {
61                  throw new IOException(e.getMessage());
62              }
63          }
64      }
65  
66      /////////////////////////////////// interface InputStream ///////////////////////////////////
67  
68      public int read() throws IOException {return m_inStream.read();}
69      public int read(byte[] b) throws IOException {return m_inStream.read(b);}
70      public int read(byte[] b, int off, int len) throws IOException {return m_inStream.read(b, off, len);}
71      public long skip(long n) throws IOException {return m_inStream.skip(n);}
72      public int available() throws IOException {return m_inStream.available();}
73      public synchronized void mark(int readlimit) {m_inStream.mark(readlimit);}
74      public synchronized void reset() throws IOException {m_inStream.reset();}
75      public boolean markSupported() {return m_inStream.markSupported();}
76  }