1
2
3
4
5
6
7
8
9
10
11 package org.astrogrid.applications.parameter.protocol;
12
13 import org.astrogrid.component.descriptor.ComponentDescriptor;
14
15 import java.io.File;
16 import java.io.FileInputStream;
17 import java.io.FileOutputStream;
18 import java.io.IOException;
19 import java.io.InputStream;
20 import java.io.OutputStream;
21 import java.net.URI;
22
23 import junit.framework.Test;
24
25 /*** Protocol implementation for file:/
26 * @author Noel Winstanley nw@jb.man.ac.uk 16-Jun-2004
27 *
28 */
29 public class FileProtocol implements Protocol, ComponentDescriptor {
30
31 /***
32 * @see org.astrogrid.applications.parameter.protocol.Protocol#getProtocolName()
33 */
34 public String getProtocolName() {
35 return "file";
36 }
37
38 /***
39 * @see org.astrogrid.applications.parameter.protocol.Protocol#createIndirectValue(java.net.URI)
40 */
41 public ExternalValue createIndirectValue(final URI reference) throws InaccessibleExternalValueException {
42 final File f = new File(reference);
43 return new ExternalValue() {
44
45 public InputStream read() throws InaccessibleExternalValueException {
46 try {
47 return new FileInputStream(f);
48 } catch (IOException e) {
49 throw new InaccessibleExternalValueException(reference.toString(),e );
50 }
51 }
52
53 public OutputStream write() throws InaccessibleExternalValueException {
54 try {
55 return new FileOutputStream(f);
56 } catch (IOException e) {
57 throw new InaccessibleExternalValueException(reference.toString(),e );
58 }
59 }
60 };
61 }
62
63 /***
64 * @see org.astrogrid.component.descriptor.ComponentDescriptor#getName()
65 */
66 public String getName() {
67 return "FileProtocol";
68 }
69
70 /***
71 * @see org.astrogrid.component.descriptor.ComponentDescriptor#getDescription()
72 */
73 public String getDescription() {
74 return "Protocol adapter for file:/ protocol";
75 }
76
77 /***
78 * @see org.astrogrid.component.descriptor.ComponentDescriptor#getInstallationTest()
79 */
80 public Test getInstallationTest() {
81 return null;
82 }
83
84 }
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104