Commit f2e1254c authored by R.W.Majeed's avatar R.W.Majeed

file observation supplier factory interface refactored

parent cec35557
......@@ -136,12 +136,12 @@ public class RunConfiguration implements Closeable{
ObservationSupplier p = null;
// if only one file factory present, pass on exception
if( fileFactories.length == 1 ){
p = fileFactories[0].forFile(file, factory);
p = fileFactories[0].createSupplier(file, factory);
}else{
// multiple file factories, find one which doesn't give errors
for( int i=0; i<fileFactories.length; i++ ){
try {
p = fileFactories[i].forFile(file, factory);
p = fileFactories[i].createSupplier(file, factory);
break;
} catch (IOException e) {
// unable to process file
......
......@@ -45,10 +45,10 @@ public interface FileObservationSupplierFactory {
* @return observation supplier
* @throws IOException error (will automatically close the input stream)
*/
ObservationSupplier forInputStream(InputStream in, ObservationFactory factory)throws IOException;
ObservationSupplier createSupplier(InputStream in, ObservationFactory factory)throws IOException;
default ObservationSupplier forFile(File file, ObservationFactory factory) throws IOException {
return forInputStream(new FileInputStream(file), factory);
default ObservationSupplier createSupplier(File file, ObservationFactory factory) throws IOException {
return createSupplier(new FileInputStream(file), factory);
}
}
......@@ -39,7 +39,7 @@ public class FlatProviderFactory implements FileObservationSupplierFactory, Plug
}
@Override
public ObservationSupplier forInputStream(InputStream in, ObservationFactory factory) throws IOException {
public ObservationSupplier createSupplier(InputStream in, ObservationFactory factory) throws IOException {
return new FlatObservationSupplier(factory, in);
}
......
......@@ -43,7 +43,7 @@ public class GroupedXMLProvider implements FileObservationSupplierFactory, Plugi
}
@Override
public ObservationSupplier forInputStream(InputStream in, ObservationFactory factory) throws IOException {
public ObservationSupplier createSupplier(InputStream in, ObservationFactory factory) throws IOException {
try {
return new GroupedXMLReader(factory, in);
} catch (JAXBException | XMLStreamException | FactoryConfigurationError e) {
......
......@@ -44,7 +44,7 @@ public class XMLProviderFactory implements FileObservationSupplierFactory, Plugi
}
@Override
public ObservationSupplier forInputStream(InputStream in, ObservationFactory factory) throws IOException {
public ObservationSupplier createSupplier(InputStream in, ObservationFactory factory) throws IOException {
try {
return new XMLObservationSupplier(factory, in);
} catch (XMLStreamException | FactoryConfigurationError e) {
......
......@@ -25,7 +25,7 @@ public class TestFileObservationSuppliers {
@Test
public void verifyGroupedXmlSupplier() throws Exception{
GroupedXMLProvider p = new GroupedXMLProvider(null);
ObservationSupplier s = p.forFile(new File("examples/dwh-jaxb.xml"), factory);
ObservationSupplier s = p.createSupplier(getClass().getResourceAsStream("/dwh.xml"), factory);
Assert.assertTrue( s.stream().count() > 0 );
s.close();
p.close();
......@@ -33,7 +33,7 @@ public class TestFileObservationSuppliers {
@Test
public void verifyFlatSupplier() throws Exception{
FlatProviderFactory p = new FlatProviderFactory(null);
ObservationSupplier s = p.forFile(new File("examples/dwh-flat.txt"), factory);
ObservationSupplier s = p.createSupplier(new File("examples/dwh-flat.txt"), factory);
Assert.assertTrue( s.stream().count() > 0 );
s.close();
p.close();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment