/** * Parses the given stream. * * @param stream the stream to parse * @throws IOException if parsing the XML fails either due to an IO error or due to an SAXException (when * processing a malformed XML). */ public void parse(InputStream stream) throws IOException { parse(stream, null); }
XMLReader reader = new XMLReader(); reader.addHandler("Part", part -> { int number = part.queryValue("PartNumber").asInt(0); parts.put(number, new File(getUploadDir(uploadId), String.valueOf(number))); }); try { reader.parse(in); } catch (IOException e) { Exceptions.handle(e);
private InputSource tryResolveEntity(String systemId, Function<String, InputStream> resourceLocator) throws IOException { URL url = new URL(systemId); if (!"file".equals(url.getProtocol())) { return emptyResource(); } File file = new File(url.getFile()); if (file.exists()) { return new InputSource(new FileInputStream(file)); } if (resourceLocator == null) { return emptyResource(); } InputStream stream = resourceLocator.apply(file.getName()); if (stream != null) { return new InputSource(stream); } return emptyResource(); }