Commit a4880d99 authored by R.W.Majeed's avatar R.W.Majeed
Browse files

ObservationSupplier implements AutoClosable

parent 7c73e6a8
......@@ -36,7 +36,7 @@ import java.util.function.Supplier;
* @author Raphael
*
*/
public interface ObservationSupplier extends Supplier<Observation>{
public interface ObservationSupplier extends Supplier<Observation>, AutoCloseable{
/**
* Retrieve meta information for this supply of observations.
......@@ -46,4 +46,6 @@ public interface ObservationSupplier extends Supplier<Observation>{
* @return value for the meta key
*/
String getMeta(String key);
void close() throws Exception;
}
......@@ -424,4 +424,9 @@ public class FlatObservationSupplier extends AbstractObservationParser implement
fact = null; // clear local copy
return ret;
}
@Override
public void close() throws IOException {
reader.close();
}
}
......@@ -199,5 +199,9 @@ public class XMLObservationSupplier extends XMLObservationParser implements Obse
}
return o;
}
@Override
public void close() throws XMLStreamException{
reader.close();
}
}
......@@ -22,6 +22,8 @@ package de.sekmi.histream.io;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.time.temporal.ChronoField;
import java.time.temporal.ChronoUnit;
import java.util.Iterator;
......@@ -29,6 +31,9 @@ import java.util.function.Supplier;
import java.util.stream.StreamSupport;
import java.math.BigDecimal;
import javax.xml.stream.FactoryConfigurationError;
import javax.xml.stream.XMLStreamException;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
......@@ -59,11 +64,7 @@ public class FileObservationProviderTest {
factory.registerExtension(new SimplePatientExtension());
factory.registerExtension(new SimpleVisitExtension());
//factory.registerExtension(new ConceptExtension());
}
public ObservationFactory getFactory(){
return factory;
}
}
@Before
public void initializeHandler(){
......@@ -164,6 +165,18 @@ public class FileObservationProviderTest {
});
}
public ObservationFactory getFactory(){
return factory;
}
public ObservationSupplier getExampleSupplier() throws IOException{
try {
return new XMLObservationSupplier(factory, new FileInputStream("examples/dwh-eav.xml"));
} catch (XMLStreamException | FactoryConfigurationError e) {
throw new IOException(e);
}
}
public void validateExample(Supplier<Observation> supplier){
StreamSupport.stream(AbstractObservationParser.nonNullSpliterator(supplier), false).forEach(handler);
}
......@@ -174,15 +187,17 @@ public class FileObservationProviderTest {
}
@Test
public void testStAXReader() throws Exception {
ObservationSupplier xos = new XMLObservationSupplier(factory, new FileInputStream("examples/dwh-eav.xml"));
public void testStAXReader() throws FileNotFoundException, XMLStreamException, FactoryConfigurationError {
XMLObservationSupplier xos = new XMLObservationSupplier(factory, new FileInputStream("examples/dwh-eav.xml"));
validateExample(xos);
xos.close();
}
@Test
public void testFlatReader() throws Exception {
ObservationSupplier s = new FlatObservationSupplier(factory, new FileInputStream("examples/dwh-flat.txt"));
public void testFlatReader() throws FileNotFoundException, IOException {
FlatObservationSupplier s = new FlatObservationSupplier(factory, new FileInputStream("examples/dwh-flat.txt"));
validateExample(s);
s.close();
}
}
Supports Markdown
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