13
13
import com .google .common .base .Suppliers ;
14
14
import com .google .gdata .util .io .base .UnicodeReader ;
15
15
import eu .itesla_project .commons .config .PlatformConfig ;
16
+ import eu .itesla_project .iidm .datasource .DataSourceUtil ;
16
17
import eu .itesla_project .iidm .datasource .ReadOnlyDataSource ;
17
18
import eu .itesla_project .iidm .import_ .Importer ;
18
19
import eu .itesla_project .iidm .import_ .Importers ;
38
39
import java .util .Properties ;
39
40
40
41
/**
41
- *
42
42
* @author Olivier Bretteville <olivier.bretteville at rte-france.com>
43
43
*/
44
44
@ AutoService (Importer .class )
@@ -99,10 +99,10 @@ public String getComment() {
99
99
}
100
100
101
101
private Packaging detectPackaging (ReadOnlyDataSource dataSource ) throws IOException {
102
- if (dataSource . exists ("_ME" , "xml" )) {
102
+ if (exists (dataSource , "_ME" , "xml" )) {
103
103
return Packaging .MERGED ;
104
104
}
105
- if (dataSource . exists ("_EQ" , "xml" ) && dataSource . exists ("_TP" , "xml" ) && dataSource . exists ("_SV" , "xml" )) {
105
+ if (exists (dataSource , "_EQ" , "xml" ) && exists (dataSource , "_TP" , "xml" ) && exists (dataSource , "_SV" , "xml" )) {
106
106
return Packaging .SPLIT ;
107
107
}
108
108
return null ;
@@ -158,11 +158,11 @@ public boolean exists(ReadOnlyDataSource dataSource) {
158
158
if (packaging != null ) {
159
159
switch (packaging ) {
160
160
case MERGED :
161
- try (InputStream is = dataSource . newInputStream ("_ME" , "xml" )) {
161
+ try (InputStream is = newInputStream (dataSource , "_ME" , "xml" )) {
162
162
return isCim14 (is );
163
163
}
164
164
case SPLIT :
165
- try (InputStream eqIs = dataSource . newInputStream ("_EQ" , "xml" )) { // just test eq file to save time
165
+ try (InputStream eqIs = newInputStream (dataSource , "_EQ" , "xml" )) { // just test eq file to save time
166
166
return isCim14 (eqIs );
167
167
}
168
168
default :
@@ -179,7 +179,7 @@ public boolean exists(ReadOnlyDataSource dataSource) {
179
179
180
180
private CIMModel loadMergedModel (ReadOnlyDataSource dataSource , Reader bseqr , Reader bstpr ) throws Exception {
181
181
CIMModel model = new CIMModel ();
182
- try (Reader mer = new UnicodeReader (dataSource . newInputStream ("_ME" , "xml" ), null )) {
182
+ try (Reader mer = new UnicodeReader (newInputStream (dataSource , "_ME" , "xml" ), null )) {
183
183
184
184
long startTime2 = System .currentTimeMillis ();
185
185
@@ -195,9 +195,9 @@ private CIMModel loadMergedModel(ReadOnlyDataSource dataSource, Reader bseqr, Re
195
195
196
196
private CIMModel loadSplitModel (ReadOnlyDataSource dataSource , Reader bseqr , Reader bstpr ) throws Exception {
197
197
CIMModel model = new CIMModel ();
198
- try (Reader eqr = new UnicodeReader (dataSource . newInputStream ("_EQ" , "xml" ), null );
199
- Reader tpr = new UnicodeReader (dataSource . newInputStream ("_TP" , "xml" ), null );
200
- Reader svr = new UnicodeReader (dataSource . newInputStream ("_SV" , "xml" ), null )) {
198
+ try (Reader eqr = new UnicodeReader (newInputStream (dataSource , "_EQ" , "xml" ), null );
199
+ Reader tpr = new UnicodeReader (newInputStream (dataSource , "_TP" , "xml" ), null );
200
+ Reader svr = new UnicodeReader (newInputStream (dataSource , "_SV" , "xml" ), null )) {
201
201
202
202
long startTime2 = System .currentTimeMillis ();
203
203
@@ -278,7 +278,7 @@ public Network import_(ReadOnlyDataSource dataSource, Properties parameters) {
278
278
}
279
279
280
280
CIM1NamingStrategyFactory namingStrategyFactory ;
281
- try (InputStream eqIs = dataSource . newInputStream ("_EQ" , "xml" )) { // just test eq file to save time
281
+ try (InputStream eqIs = newInputStream (dataSource , "_EQ" , "xml" )) { // just test eq file to save time
282
282
namingStrategyFactory = usePsseNamingStrategy && isPtiCim14 (eqIs ) ? new CIM1PSSENamingStrategyFactory ()
283
283
: new CIM1DefaultNamingStrategyFactory ();
284
284
}
@@ -301,4 +301,24 @@ public Network import_(ReadOnlyDataSource dataSource, Properties parameters) {
301
301
return network ;
302
302
}
303
303
304
+ private String getBaseName (ReadOnlyDataSource dataSource ) {
305
+ String basename = dataSource .getBaseName ();
306
+ if (basename .endsWith ("_ME" ) || basename .endsWith ("_EQ" ) || basename .endsWith ("_TP" ) || basename .endsWith ("_SV" )) {
307
+ basename = basename .substring (0 , basename .length () - 3 );
308
+ }
309
+
310
+ return basename ;
311
+ }
312
+
313
+ private InputStream newInputStream (ReadOnlyDataSource dataSource , String suffix , String ext ) throws IOException {
314
+ String baseName = getBaseName (dataSource );
315
+ String fileName = DataSourceUtil .getFileName (baseName , suffix , ext );
316
+ return dataSource .newInputStream (fileName );
317
+ }
318
+
319
+ private boolean exists (ReadOnlyDataSource dataSource , String suffix , String ext ) throws IOException {
320
+ String baseName = getBaseName (dataSource );
321
+ String fileName = DataSourceUtil .getFileName (baseName , suffix , ext );
322
+ return dataSource .exists (fileName );
323
+ }
304
324
}
0 commit comments