From 6c16f6564994a3ea70da88c62cc16bb6e18231fd Mon Sep 17 00:00:00 2001 From: Michael Bangas Date: Thu, 12 Dec 2024 11:20:16 +0100 Subject: [PATCH] Utilize mark and reset for stream handling --- .../src/org/eclipse/swt/svg/JSVGRasterizer.java | 9 +++++++-- .../common/org/eclipse/swt/graphics/SVGRasterizer.java | 2 +- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/bundles/org.eclipse.swt.svg/src/org/eclipse/swt/svg/JSVGRasterizer.java b/bundles/org.eclipse.swt.svg/src/org/eclipse/swt/svg/JSVGRasterizer.java index 6141c4aabfe..6042a8d4d48 100644 --- a/bundles/org.eclipse.swt.svg/src/org/eclipse/swt/svg/JSVGRasterizer.java +++ b/bundles/org.eclipse.swt.svg/src/org/eclipse/swt/svg/JSVGRasterizer.java @@ -165,7 +165,12 @@ public boolean isSVGFile(InputStream stream) throws IOException { if (stream == null) { throw new IllegalArgumentException("InputStream cannot be null"); } - int firstByte = inputStream.read(); - return firstByte == '<'; + stream.mark(Integer.MAX_VALUE); + try { + int firstByte = stream.read(); + return firstByte == '<'; + } finally { + stream.reset(); + } } } diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/SVGRasterizer.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/SVGRasterizer.java index 5342d168e86..46140bffe5f 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/SVGRasterizer.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/SVGRasterizer.java @@ -37,7 +37,7 @@ public interface SVGRasterizer { /** * Determines whether the given {@link InputStream} contains a SVG file. * - * @param inputStream the input stream to check. + * @param stream the input stream to check. * @return {@code true} if the input stream contains SVG content; {@code false} * otherwise. * @throws IOException if an error occurs while reading the stream.