1 | /* | |
2 | * Copyright 2006 - 2013 | |
3 | * Stefan Balev <stefan.balev@graphstream-project.org> | |
4 | * Julien Baudry <julien.baudry@graphstream-project.org> | |
5 | * Antoine Dutot <antoine.dutot@graphstream-project.org> | |
6 | * Yoann Pign�� <yoann.pigne@graphstream-project.org> | |
7 | * Guilhelm Savin <guilhelm.savin@graphstream-project.org> | |
8 | * | |
9 | * This file is part of GraphStream <http://graphstream-project.org>. | |
10 | * | |
11 | * GraphStream is a library whose purpose is to handle static or dynamic | |
12 | * graph, create them from scratch, file or any source and display them. | |
13 | * | |
14 | * This program is free software distributed under the terms of two licenses, the | |
15 | * CeCILL-C license that fits European law, and the GNU Lesser General Public | |
16 | * License. You can use, modify and/ or redistribute the software under the terms | |
17 | * of the CeCILL-C license as circulated by CEA, CNRS and INRIA at the following | |
18 | * URL <http://www.cecill.info> or under the terms of the GNU LGPL as published by | |
19 | * the Free Software Foundation, either version 3 of the License, or (at your | |
20 | * option) any later version. | |
21 | * | |
22 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY | |
23 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A | |
24 | * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. | |
25 | * | |
26 | * You should have received a copy of the GNU Lesser General Public License | |
27 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
28 | * | |
29 | * The fact that you are presently reading this means that you have had | |
30 | * knowledge of the CeCILL-C and LGPL licenses and that you accept their terms. | |
31 | */ | |
32 | package org.graphstream.stream.file; | |
33 | ||
34 | import java.io.FileReader; | |
35 | import java.io.IOException; | |
36 | import java.io.InputStream; | |
37 | import java.io.InputStreamReader; | |
38 | import java.io.Reader; | |
39 | import java.net.URL; | |
40 | ||
41 | import org.graphstream.stream.SourceBase; | |
42 | import org.graphstream.util.parser.ParseException; | |
43 | import org.graphstream.util.parser.Parser; | |
44 | import org.graphstream.util.parser.ParserFactory; | |
45 | ||
46 | /** | |
47 | * This defines source using a {@link org.graphstream.util.parser.Parser} object | |
48 | * to parse a stream and generate graph events. | |
49 | * | |
50 | */ | |
51 | public abstract class FileSourceParser extends SourceBase implements FileSource { | |
52 | /** | |
53 | * Factory used to create parser. | |
54 | */ | |
55 | protected ParserFactory factory; | |
56 | ||
57 | /** | |
58 | * Parser opened by a call to {@link #begin(Reader)}. | |
59 | */ | |
60 | protected Parser parser; | |
61 | ||
62 | /** | |
63 | * Get a new parser factory. | |
64 | * | |
65 | * @return a parser factory | |
66 | */ | |
67 | public abstract ParserFactory getNewParserFactory(); | |
68 | ||
69 | protected FileSourceParser() { | |
70 | factory = getNewParserFactory(); | |
71 | } | |
72 | ||
73 | /* | |
74 | * (non-Javadoc) | |
75 | * | |
76 | * @see org.graphstream.stream.file.FileSource#readAll(java.lang.String) | |
77 | */ | |
78 | public void readAll(String fileName) throws IOException { | |
79 | Parser parser = factory.newParser(createReaderForFile(fileName)); | |
80 | ||
81 | try { | |
82 |
1
1. readAll : removed call to org/graphstream/util/parser/Parser::all → NO_COVERAGE |
parser.all(); |
83 |
1
1. readAll : removed call to org/graphstream/util/parser/Parser::close → NO_COVERAGE |
parser.close(); |
84 | } catch (ParseException e) { | |
85 | throw new IOException(e); | |
86 | } | |
87 | } | |
88 | ||
89 | /* | |
90 | * (non-Javadoc) | |
91 | * | |
92 | * @see org.graphstream.stream.file.FileSource#readAll(java.net.URL) | |
93 | */ | |
94 | public void readAll(URL url) throws IOException { | |
95 | Parser parser = factory.newParser(new InputStreamReader(url | |
96 | .openStream())); | |
97 | ||
98 | try { | |
99 |
1
1. readAll : removed call to org/graphstream/util/parser/Parser::all → NO_COVERAGE |
parser.all(); |
100 |
1
1. readAll : removed call to org/graphstream/util/parser/Parser::close → NO_COVERAGE |
parser.close(); |
101 | } catch (ParseException e) { | |
102 | throw new IOException(e); | |
103 | } | |
104 | } | |
105 | ||
106 | /* | |
107 | * (non-Javadoc) | |
108 | * | |
109 | * @see org.graphstream.stream.file.FileSource#readAll(java.io.InputStream) | |
110 | */ | |
111 | public void readAll(InputStream stream) throws IOException { | |
112 | Parser parser = factory.newParser(new InputStreamReader(stream)); | |
113 | ||
114 | try { | |
115 |
1
1. readAll : removed call to org/graphstream/util/parser/Parser::all → NO_COVERAGE |
parser.all(); |
116 |
1
1. readAll : removed call to org/graphstream/util/parser/Parser::close → NO_COVERAGE |
parser.close(); |
117 | } catch (ParseException e) { | |
118 | throw new IOException(e); | |
119 | } | |
120 | } | |
121 | ||
122 | /* | |
123 | * (non-Javadoc) | |
124 | * | |
125 | * @see org.graphstream.stream.file.FileSource#readAll(java.io.Reader) | |
126 | */ | |
127 | public void readAll(Reader reader) throws IOException { | |
128 | Parser parser = factory.newParser(reader); | |
129 | ||
130 | try { | |
131 |
1
1. readAll : removed call to org/graphstream/util/parser/Parser::all → NO_COVERAGE |
parser.all(); |
132 |
1
1. readAll : removed call to org/graphstream/util/parser/Parser::close → NO_COVERAGE |
parser.close(); |
133 | } catch (ParseException e) { | |
134 | throw new IOException(e); | |
135 | } | |
136 | } | |
137 | ||
138 | /* | |
139 | * (non-Javadoc) | |
140 | * | |
141 | * @see org.graphstream.stream.file.FileSource#begin(java.lang.String) | |
142 | */ | |
143 | public void begin(String fileName) throws IOException { | |
144 |
1
1. begin : negated conditional → NO_COVERAGE |
if (parser != null) |
145 |
1
1. begin : removed call to org/graphstream/stream/file/FileSourceParser::end → NO_COVERAGE |
end(); |
146 | ||
147 | parser = factory.newParser(createReaderForFile(fileName)); | |
148 | ||
149 | try { | |
150 |
1
1. begin : removed call to org/graphstream/util/parser/Parser::open → NO_COVERAGE |
parser.open(); |
151 | } catch (ParseException e) { | |
152 | throw new IOException(e); | |
153 | } | |
154 | } | |
155 | ||
156 | /* | |
157 | * (non-Javadoc) | |
158 | * | |
159 | * @see org.graphstream.stream.file.FileSource#begin(java.net.URL) | |
160 | */ | |
161 | public void begin(URL url) throws IOException { | |
162 | parser = factory.newParser(new InputStreamReader(url.openStream())); | |
163 | ||
164 | try { | |
165 |
1
1. begin : removed call to org/graphstream/util/parser/Parser::open → NO_COVERAGE |
parser.open(); |
166 | } catch (ParseException e) { | |
167 | throw new IOException(e); | |
168 | } | |
169 | } | |
170 | ||
171 | /* | |
172 | * (non-Javadoc) | |
173 | * | |
174 | * @see org.graphstream.stream.file.FileSource#begin(java.io.InputStream) | |
175 | */ | |
176 | public void begin(InputStream stream) throws IOException { | |
177 | parser = factory.newParser(new InputStreamReader(stream)); | |
178 | ||
179 | try { | |
180 |
1
1. begin : removed call to org/graphstream/util/parser/Parser::open → NO_COVERAGE |
parser.open(); |
181 | } catch (ParseException e) { | |
182 | throw new IOException(e); | |
183 | } | |
184 | } | |
185 | ||
186 | /* | |
187 | * (non-Javadoc) | |
188 | * | |
189 | * @see org.graphstream.stream.file.FileSource#begin(java.io.Reader) | |
190 | */ | |
191 | public void begin(Reader reader) throws IOException { | |
192 | parser = factory.newParser(reader); | |
193 | ||
194 | try { | |
195 |
1
1. begin : removed call to org/graphstream/util/parser/Parser::open → NO_COVERAGE |
parser.open(); |
196 | } catch (ParseException e) { | |
197 | throw new IOException(e); | |
198 | } | |
199 | } | |
200 | ||
201 | /* | |
202 | * (non-Javadoc) | |
203 | * | |
204 | * @see org.graphstream.stream.file.FileSource#nextEvents() | |
205 | */ | |
206 | public boolean nextEvents() throws IOException { | |
207 | try { | |
208 |
1
1. nextEvents : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE |
return parser.next(); |
209 | } catch (ParseException e) { | |
210 | throw new IOException(e); | |
211 | } | |
212 | } | |
213 | ||
214 | /** | |
215 | * Since there is no step in DOT, this does the same action than | |
216 | * {@link #nextEvents()}. | |
217 | */ | |
218 | public boolean nextStep() throws IOException { | |
219 |
1
1. nextStep : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE |
return nextEvents(); |
220 | } | |
221 | ||
222 | /* | |
223 | * (non-Javadoc) | |
224 | * | |
225 | * @see org.graphstream.stream.file.FileSource#end() | |
226 | */ | |
227 | public void end() throws IOException { | |
228 |
1
1. end : removed call to org/graphstream/util/parser/Parser::close → NO_COVERAGE |
parser.close(); |
229 | parser = null; | |
230 | } | |
231 | ||
232 | protected Reader createReaderForFile(String filename) throws IOException { | |
233 |
1
1. createReaderForFile : mutated return of Object value for org/graphstream/stream/file/FileSourceParser::createReaderForFile to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return new FileReader(filename); |
234 | } | |
235 | } | |
Mutations | ||
82 |
1.1 |
|
83 |
1.1 |
|
99 |
1.1 |
|
100 |
1.1 |
|
115 |
1.1 |
|
116 |
1.1 |
|
131 |
1.1 |
|
132 |
1.1 |
|
144 |
1.1 |
|
145 |
1.1 |
|
150 |
1.1 |
|
165 |
1.1 |
|
180 |
1.1 |
|
195 |
1.1 |
|
208 |
1.1 |
|
219 |
1.1 |
|
228 |
1.1 |
|
233 |
1.1 |