|
37 | 37 | import com.github.weisj.jsvg.SVGDocument;
|
38 | 38 | import com.github.weisj.jsvg.geometry.size.FloatSize;
|
39 | 39 | import com.github.weisj.jsvg.parser.LoaderContext;
|
| 40 | +import com.github.weisj.jsvg.parser.ParsedDocument; |
40 | 41 | import com.github.weisj.jsvg.parser.ResourceLoader;
|
41 | 42 | import com.github.weisj.jsvg.parser.SVGLoader;
|
42 | 43 | import com.github.weisj.jsvg.renderer.awt.NullPlatformSupport;
|
@@ -128,14 +129,13 @@ private static SVGDocument loadSVGDocument(URL url, Dimension toSize) throws IOE
|
128 | 129 |
|
129 | 130 | final SVGDocument svgDocument;
|
130 | 131 | FloatSize documentSize;
|
131 |
| - InputStream is = url.openStream(); |
132 |
| - try { |
| 132 | + try (InputStream is = url.openStream()) { |
133 | 133 | // Explicitly deny loading of external URLs.
|
134 | 134 |
|
135 | 135 | /* Handle e.g. <image href="https://example.com/image.png"> elements. Tested in
|
136 | 136 | testLoadImageWithExternalImageHref. */
|
137 | 137 | List<IOException> externalResourceExceptions = new ArrayList<>();
|
138 |
| - ResourceLoader resourceLoader = (URI nnuri) -> { |
| 138 | + ResourceLoader resourceLoader = (ParsedDocument nnpd, URI nnuri) -> { |
139 | 139 | IOException e = new IOException("External resource loading from SVG file not permitted ("+
|
140 | 140 | nnuri + " from " + url + ")");
|
141 | 141 | externalResourceExceptions.add(e);
|
@@ -168,8 +168,6 @@ private static SVGDocument loadSVGDocument(URL url, Dimension toSize) throws IOE
|
168 | 168 | } catch (RuntimeException e) {
|
169 | 169 | /* Rethrow any uncaught exceptions that could be thrown when parsing invalid SVG files. */
|
170 | 170 | throw new IOException("Error parsing SVG file", e);
|
171 |
| - } finally { |
172 |
| - is.close(); |
173 | 171 | }
|
174 | 172 | if (toSize != null) {
|
175 | 173 | int width = (int) Math.ceil(documentSize.getWidth());
|
|
0 commit comments