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
15
16
17
18
19
20
21
22
23
24
25 public class FileInputStreamPipedImpl extends AbstractAsyncFileInputStreamImpl {
26 private DataAdaptor m_connection;
27 private PipedInputStreamImpl m_inStream;
28
29
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
34 m_connection = (disconnectable ? adaptor : null);
35
36
37 URL fileUrl = URLHelper.toFileURL(url);
38 m_inStream = new PipedInputStreamImpl(
39 adaptor,
40 fileUrl.getPath(),
41 fileUrl.getQuery());
42 }
43
44
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
54 m_inStream.close();
55
56
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
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 }