Skip to content

Commit

Permalink
Added utility method SAXUtil#createFilteredSource(InputStream, XMLFil…
Browse files Browse the repository at this point in the history
…ter...)
  • Loading branch information
vruusmann committed Jul 8, 2018
1 parent dcdb977 commit 0499a97
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import com.beust.jcommander.ParameterException;
import org.dmg.pmml.PMML;
import org.jpmml.model.filters.ImportFilter;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;

abstract
Expand Down Expand Up @@ -56,7 +55,7 @@ public PMML unmarshalPMML(File file) throws JAXBException, SAXException, IOExcep
Unmarshaller unmarshaller = createUnmarshaller();

try(InputStream is = new FileInputStream(file)){
Source source = SAXUtil.createFilteredSource(new InputSource(is), new ImportFilter());
Source source = SAXUtil.createFilteredSource(is, new ImportFilter());

return (PMML)unmarshaller.unmarshal(source);
}
Expand Down
3 changes: 1 addition & 2 deletions pmml-model/src/main/java/org/jpmml/model/PMMLUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

import org.dmg.pmml.PMML;
import org.jpmml.model.filters.ImportFilter;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;

public class PMMLUtil {
Expand All @@ -26,7 +25,7 @@ private PMMLUtil(){
*/
static
public PMML unmarshal(InputStream is) throws SAXException, JAXBException {
Source source = SAXUtil.createFilteredSource(new InputSource(is), new ImportFilter());
Source source = SAXUtil.createFilteredSource(is, new ImportFilter());

return JAXBUtil.unmarshalPMML(source);
}
Expand Down
6 changes: 4 additions & 2 deletions pmml-model/src/main/java/org/jpmml/model/SAXUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
*/
package org.jpmml.model;

import java.io.InputStream;

import javax.xml.transform.sax.SAXSource;

import org.jpmml.model.filters.ElementFilter;
Expand All @@ -27,7 +29,7 @@ private SAXUtil(){
* @see WhitespaceFilter
*/
static
public SAXSource createFilteredSource(InputSource source, XMLFilter... filters) throws SAXException {
public SAXSource createFilteredSource(InputStream is, XMLFilter... filters) throws SAXException {
XMLReader reader = XMLReaderFactory.createXMLReader();

for(XMLFilter filter : filters){
Expand All @@ -36,6 +38,6 @@ public SAXSource createFilteredSource(InputSource source, XMLFilter... filters)
reader = filter;
}

return new SAXSource(reader, source);
return new SAXSource(reader, new InputSource(is));
}
}
3 changes: 1 addition & 2 deletions pmml-model/src/test/java/org/jpmml/model/ResourceUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

import org.dmg.pmml.PMML;
import org.dmg.pmml.Version;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.XMLFilter;

Expand All @@ -26,7 +25,7 @@ private ResourceUtil(){
public PMML unmarshal(Class<?> clazz, XMLFilter... filters) throws IOException, SAXException, JAXBException {

try(InputStream is = getStream(clazz)){
Source source = SAXUtil.createFilteredSource(new InputSource(is), filters);
Source source = SAXUtil.createFilteredSource(is, filters);

return JAXBUtil.unmarshalPMML(source);
}
Expand Down

0 comments on commit 0499a97

Please sign in to comment.