Clover coverage report - brownies library - 1.0-beta-1 Coverage timestamp: 月 8 16 2004 17:14:42 GMT+09:00 FRAMES NO FRAMES |
file stats: | LOC: | 205 |  | Methods: | 20
| NCLOC: | 114 |  | Classes: | 1
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover
Source file | Conditionals | Statements | Methods | TOTAL
StreamFactoryFacade.java | 21.4% | 33.3% | 30% | 30.5% |

1 |  |
     /*
2 |  |
      * Joey and its relative products are published under the terms
3 |  |
      * of the Apache Software License.
4 |  |
      */
5 |  |
     /*
6 |  |
      * Created on 2003/12/15
7 |  |
      */
8 |  |
     package org.asyrinx.brownie.core.io.sf;
9 |  |
10 |  |
     import java.io.File;
11 |  |
     import java.io.IOException;
12 |  |
     import java.io.InputStream;
13 |  |
     import java.io.OutputStream;
14 |  |
     import java.util.ArrayList;
15 |  |
     import java.util.Collection;
16 |  |
     import java.util.Iterator;
17 |  |
     import java.util.List;
18 |  |
19 |  |
     import org.apache.commons.collections.IteratorUtils;
20 |  |
     import org.apache.commons.logging.Log;
21 |  |
     import org.apache.commons.logging.LogFactory;
22 |  |
     import org.asyrinx.brownie.core.io.FileNameUtils;
23 |  |
24 |  |
     /**
25 |  |
      * @author akima
26 |  |
      */
27 |  |
     public class StreamFactoryFacade implements StreamFactory {
28 |  |
29 |  |
         /**
30 |  |
          *
31 |  |
          */
32 | 3 |
         public StreamFactoryFacade() {
33 | 3 |
             super();
34 |  |
         }
35 |  |
36 |  |
         /**
37 |  |
          * @see java.lang.Object#clone()
38 |  |
          * @return
39 |  |
          */
40 | 0 |
         public StreamFactoryFacade copy() {
41 | 0 |
             final StreamFactoryFacade result = new StreamFactoryFacade();
42 | 0 |
             result.factories.addAll(this.factories);
43 | 0 |
             return result;
44 |  |
         }
45 |  |
46 |  |
         private final List factories = new ArrayList();
47 |  |
48 |  |
         /**
49 |  |
          * @see org.asyrinx.io.sf.StreamFactory#newInput(java.lang.Object)
50 |  |
          */
51 | 3 |
         public InputStream newInput(Object key) throws IOException {
52 | 3 |
             final Iterator iterator = this.iterator();
53 | 3 |
             while (iterator.hasNext()) {
54 | 3 |
                 final StreamFactory factory = (StreamFactory) iterator.next();
55 | 3 |
                 try {
56 | 3 |
                     final InputStream result = factory.newInput(key);
57 | 3 |
                     if (result != null)
58 | 3 |
                         return result;
59 |  |
                 } catch (IOException e) {
60 |  |
                     //ignore exception
61 |  |
                 }
62 |  |
             }
63 | 0 |
             throw new IOException("no StreamFactory for \"" + key + "\"");
64 |  |
         }
65 |  |
66 |  |
         /**
67 |  |
          * @see org.asyrinx.io.sf.StreamFactory#newOutput(java.lang.Object)
68 |  |
          */
69 | 0 |
         public OutputStream newOutput(Object key) throws IOException {
70 | 0 |
             final Iterator iterator = this.iterator();
71 | 0 |
             while (iterator.hasNext()) {
72 | 0 |
                 final StreamFactory factory = (StreamFactory) iterator.next();
73 | 0 |
                 try {
74 | 0 |
                     final OutputStream result = factory.newOutput(key);
75 | 0 |
                     if (result != null)
76 | 0 |
                         return result;
77 |  |
                 } catch (IOException e) {
78 |  |
                     //ignore exception
79 |  |
                 }
80 |  |
             }
81 | 0 |
             throw new IOException("no StreamFactory for \"" + key + "\"");
82 |  |
         }
83 |  |
84 | 3 |
         public static StreamFactoryFacade newFacade() {
85 | 3 |
             return newFacade(IteratorUtils.EMPTY_ITERATOR);
86 |  |
         }
87 |  |
88 | 0 |
         public static StreamFactoryFacade newFacade(String filenames) {
89 | 0 |
             return newFacade(FileNameUtils.parseFileNames(filenames));
90 |  |
         }
91 |  |
92 | 0 |
         public static StreamFactoryFacade newFacade(Collection filenames) {
93 | 0 |
             return newFacade(filenames.iterator());
94 |  |
         }
95 |  |
96 | 3 |
         public static StreamFactoryFacade newFacade(Iterator filenameIterator) {
97 | 3 |
             final StreamFactoryFacade result = new StreamFactoryFacade();
98 | 3 |
             result.add(new ClassResourceStreamFactory());
99 | 3 |
             result.add(new SimpleFileStreamFactory());
100 | 3 |
             while (filenameIterator.hasNext()) {
101 | 0 |
                 final File path = FileNameUtils.toFile(filenameIterator.next());
102 | 0 |
                 if (path.isDirectory()) {
103 | 0 |
                     result.add(new DirectoryBaseFileStreamFactory(path
104 |  |
                             .getAbsolutePath()));
105 | 0 |
                 } else if (FileNameUtils.hasZipExtension(path.getPath())) {
106 | 0 |
                     result.add(new ZipEntryFileStreamFactory(path.getPath()));
107 |  |
                 } else {
108 | 0 |
                     final Log log = LogFactory.getLog(StreamFactoryFacade.class);
109 | 0 |
                     log.warn("path\"" + path.getPath() + "\" was not found.");
110 |  |
                 }
111 |  |
             }
112 | 3 |
             return result;
113 |  |
         }
114 |  |
115 | 0 |
         public StreamFactoryFacade addRelativeClassResourceSF() {
116 | 0 |
             this.add(new RelativeClassResourceStreamFactory(
117 |  |
                     StreamFactoryFacade.class.getName()));
118 | 0 |
             return this;
119 |  |
         }
120 |  |
121 |  |
         /**
122 |  |
          * @param index
123 |  |
          * @param element
124 |  |
          */
125 | 0 |
         public void add(int index, StreamFactory element) {
126 | 0 |
             factories.add(index, element);
127 |  |
         }
128 |  |
129 |  |
         /**
130 |  |
          * @param o
131 |  |
          * @return
132 |  |
          */
133 | 6 |
         public boolean add(StreamFactory o) {
134 | 6 |
             return factories.add(o);
135 |  |
         }
136 |  |
137 |  |
         /**
138 |  |
          *
139 |  |
          */
140 | 0 |
         public void clear() {
141 | 0 |
             factories.clear();
142 |  |
         }
143 |  |
144 |  |
         /**
145 |  |
          * @param o
146 |  |
          * @return
147 |  |
          */
148 | 0 |
         public boolean contains(StreamFactory o) {
149 | 0 |
             return factories.contains(o);
150 |  |
         }
151 |  |
152 |  |
         /**
153 |  |
          * @param index
154 |  |
          * @return
155 |  |
          */
156 | 0 |
         public StreamFactory get(int index) {
157 | 0 |
             return (StreamFactory) factories.get(index);
158 |  |
         }
159 |  |
160 |  |
         /**
161 |  |
          * @param o
162 |  |
          * @return
163 |  |
          */
164 | 0 |
         public int indexOf(StreamFactory o) {
165 | 0 |
             return factories.indexOf(o);
166 |  |
         }
167 |  |
168 |  |
         /**
169 |  |
          * @return
170 |  |
          */
171 | 0 |
         public boolean isEmpty() {
172 | 0 |
             return factories.isEmpty();
173 |  |
         }
174 |  |
175 |  |
         /**
176 |  |
          * @return
177 |  |
          */
178 | 3 |
         public Iterator iterator() {
179 | 3 |
             return factories.iterator();
180 |  |
         }
181 |  |
182 |  |
         /**
183 |  |
          * @param index
184 |  |
          * @return
185 |  |
          */
186 | 0 |
         public StreamFactory remove(int index) {
187 | 0 |
             return (StreamFactory) factories.remove(index);
188 |  |
         }
189 |  |
190 |  |
         /**
191 |  |
          * @param o
192 |  |
          * @return
193 |  |
          */
194 | 0 |
         public boolean remove(StreamFactory o) {
195 | 0 |
             return factories.remove(o);
196 |  |
         }
197 |  |
198 |  |
         /**
199 |  |
          * @return
200 |  |
          */
201 | 0 |
         public int size() {
202 | 0 |
             return factories.size();
203 |  |
         }
204 |  |
205 |  |
     }