forked from eclipse-platform/eclipse.platform.swt
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1efaf36
commit 5bbddf5
Showing
4 changed files
with
100 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/SVGUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package org.eclipse.swt.graphics; | ||
|
||
import java.io.*; | ||
import java.nio.charset.*; | ||
|
||
/** | ||
* Utility class for handling SVG-related operations. | ||
* | ||
* @since 3.129 | ||
*/ | ||
public class SVGUtil { | ||
|
||
/** | ||
* Determines whether the given {@link InputStream} contains a SVG file. | ||
* | ||
* @param data byte array 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. | ||
* @throws IllegalArgumentException if the input stream is {@code null}. | ||
*/ | ||
public static boolean isSVGFile(byte[] data) throws IOException { | ||
String content = new String(data, 0, Math.min(data.length, 512), StandardCharsets.UTF_8); | ||
return content.contains("<svg"); | ||
} | ||
|
||
/** | ||
* Determines whether the given {@link InputStream} contains a SVG file. | ||
* | ||
* @param inputStream 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. | ||
* @throws IllegalArgumentException if the input stream is {@code null}. | ||
*/ | ||
public static boolean isSVGFile(InputStream inputStream) throws IOException { | ||
if (inputStream == null) { | ||
throw new IllegalArgumentException("InputStream cannot be null"); | ||
} | ||
byte[] data = inputStream.readNBytes(512); | ||
return isSVGFile(data); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters