From fc09feb6680c06cc62b52227c065edc1ce585855 Mon Sep 17 00:00:00 2001 From: Heinrich Filter Date: Thu, 7 Jan 2016 10:20:25 +0200 Subject: [PATCH] Added method to read VrpXml from InputStream --- .../jsprit/core/problem/io/VrpXMLReader.java | 30 +++++++++++++++---- 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/jsprit-core/src/main/java/jsprit/core/problem/io/VrpXMLReader.java b/jsprit-core/src/main/java/jsprit/core/problem/io/VrpXMLReader.java index 89104e09..aad52d1f 100644 --- a/jsprit-core/src/main/java/jsprit/core/problem/io/VrpXMLReader.java +++ b/jsprit-core/src/main/java/jsprit/core/problem/io/VrpXMLReader.java @@ -136,8 +136,27 @@ public class VrpXMLReader { public void read(String filename) { logger.debug("read vrp: {}", filename); + XMLConfiguration xmlConfig = createXMLConfiguration(); + try { + xmlConfig.load(filename); + } catch (ConfigurationException e) { + throw new RuntimeException(e); + } + read(xmlConfig); + } + + public void read(InputStream fileContents) { + XMLConfiguration xmlConfig = createXMLConfiguration(); + try { + xmlConfig.load(fileContents); + } catch (ConfigurationException e) { + throw new RuntimeException(e); + } + read(xmlConfig); + } + + private XMLConfiguration createXMLConfiguration() { XMLConfiguration xmlConfig = new XMLConfiguration(); - xmlConfig.setFileName(filename); xmlConfig.setAttributeSplittingDisabled(true); xmlConfig.setDelimiterParsingDisabled(true); @@ -160,11 +179,10 @@ public class VrpXMLReader { logger.debug("cannot find schema-xsd file (vrp_xml_schema.xsd). try to read xml without xml-file-validation."); } } - try { - xmlConfig.load(); - } catch (ConfigurationException e) { - throw new RuntimeException(e); - } + return xmlConfig; + } + + private void read(XMLConfiguration xmlConfig) { readProblemType(xmlConfig); readVehiclesAndTheirTypes(xmlConfig);