mirror of
https://github.com/graphhopper/jsprit.git
synced 2020-01-24 07:45:05 +01:00
change algorithmReader to read inputStreams
This commit is contained in:
parent
69c3b631ba
commit
3ae0fd52ef
2 changed files with 26 additions and 2 deletions
|
|
@ -21,6 +21,7 @@
|
|||
package basics.io;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URL;
|
||||
|
||||
import org.apache.commons.configuration.ConfigurationException;
|
||||
|
|
@ -57,14 +58,14 @@ public class AlgorithmConfigXmlReader {
|
|||
algorithmConfig.getXMLConfiguration().setDelimiterParsingDisabled(true);
|
||||
|
||||
if(schemaValidation){
|
||||
final URL resource = Resource.getAsURL("algorithm_schema.xsd");
|
||||
final InputStream resource = Resource.getAsInputStream("algorithm_schema.xsd");
|
||||
if(resource != null) {
|
||||
EntityResolver resolver = new EntityResolver() {
|
||||
|
||||
@Override
|
||||
public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException {
|
||||
{
|
||||
InputSource is = new InputSource(resource.getFile());
|
||||
InputSource is = new InputSource(resource);
|
||||
return is;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,9 @@
|
|||
package util;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.InputStream;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
|
||||
|
|
@ -44,4 +47,24 @@ public class Resource {
|
|||
return url;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param filename relative path from within the resource directory to a file to be loaded
|
||||
* @return a Stream to the requested resource file, or <code>null</code> if no such file exists.
|
||||
*/
|
||||
public final static InputStream getAsInputStream(final String filename) {
|
||||
// look for the file locally
|
||||
try {
|
||||
return new FileInputStream("/" + filename);
|
||||
} catch (FileNotFoundException e) {
|
||||
log.info("Resource '" + filename + "' not found locally. May not be fatal.");
|
||||
// just continue, maybe we have more luck in the classpath
|
||||
}
|
||||
// maybe we find the file in the classpath, possibly inside a jar-file
|
||||
InputStream stream = Resource.class.getResourceAsStream("/" + filename);
|
||||
if (stream == null) {
|
||||
log.warn("Resource '" + filename + "' not found!");
|
||||
}
|
||||
return stream;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue