|
|
|
@ -1,5 +1,7 @@ |
|
|
|
|
package me.bearns.fias.service; |
|
|
|
|
|
|
|
|
|
import me.bearns.fias.exceptions.CommonException; |
|
|
|
|
import me.bearns.fias.exceptions.UnmarshallingException; |
|
|
|
|
import me.bearns.fias.util.UnmarshallerParameters; |
|
|
|
|
import org.springframework.stereotype.Component; |
|
|
|
|
|
|
|
|
@ -17,7 +19,7 @@ import java.util.function.Predicate; |
|
|
|
|
@Component |
|
|
|
|
public class StreamSaverImpl implements StreamSaver{ |
|
|
|
|
@Override |
|
|
|
|
public void process(InputStream is, UnmarshallerParameters conf, Predicate filter) { |
|
|
|
|
public void process(InputStream is, UnmarshallerParameters conf, Predicate filter) throws CommonException { |
|
|
|
|
|
|
|
|
|
try { |
|
|
|
|
// create xml event reader for input stream
|
|
|
|
@ -34,9 +36,7 @@ public class StreamSaverImpl implements StreamSaver{ |
|
|
|
|
long countRead=0, countWrite=0, countErrors=0; |
|
|
|
|
|
|
|
|
|
// loop though the xml stream
|
|
|
|
|
while (true) { |
|
|
|
|
|
|
|
|
|
if (!((e = xmlEventReader.peek()) != null)) break; |
|
|
|
|
while ((e = xmlEventReader.peek()) != null) { |
|
|
|
|
|
|
|
|
|
countRead++; |
|
|
|
|
|
|
|
|
@ -78,9 +78,11 @@ public class StreamSaverImpl implements StreamSaver{ |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} catch (XMLStreamException ex) { |
|
|
|
|
ex.printStackTrace(); //createXMLEventReader & peak
|
|
|
|
|
//todo log
|
|
|
|
|
throw new UnmarshallingException(ex); //createXMLEventReader & peak
|
|
|
|
|
} catch (JAXBException ex) { |
|
|
|
|
ex.printStackTrace(); //createUnmarshaller();
|
|
|
|
|
//todo log
|
|
|
|
|
throw new UnmarshallingException(ex); //createUnmarshaller();
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//write to DB from cache
|
|
|
|
|