diff options
author | Taeyoung Son <taeyoung2.son@samsung.com> | 2014-08-04 23:12:09 +0900 |
---|---|---|
committer | Taeyoung Son <taeyoung2.son@samsung.com> | 2014-08-04 07:14:03 -0700 |
commit | b550291f9f423a1910cc5014f272a75a0b51ecfe (patch) | |
tree | bc744370a8786fabb1e1580f2767bfbf83f6292f | |
parent | 3189f450016a7bb647555c76ac6b9ed9814e7dee (diff) | |
download | common-eplugin-b550291f9f423a1910cc5014f272a75a0b51ecfe.tar.gz common-eplugin-b550291f9f423a1910cc5014f272a75a0b51ecfe.tar.bz2 common-eplugin-b550291f9f423a1910cc5014f272a75a0b51ecfe.zip |
UTIL: Fixed bug in ImageUtil
Can't read png and relative path files.
Change-Id: I63be74eef733e17beb69e1b5d8c99b8ced3c18dd
Signed-off-by: Taeyoung Son <taeyoung2.son@samsung.com>
-rw-r--r-- | org.tizen.common/src/org/tizen/common/util/ImageUtil.java | 82 |
1 files changed, 54 insertions, 28 deletions
diff --git a/org.tizen.common/src/org/tizen/common/util/ImageUtil.java b/org.tizen.common/src/org/tizen/common/util/ImageUtil.java index 48dca764a..4557a38a3 100644 --- a/org.tizen.common/src/org/tizen/common/util/ImageUtil.java +++ b/org.tizen.common/src/org/tizen/common/util/ImageUtil.java @@ -32,6 +32,7 @@ import java.awt.image.ColorModel; import java.awt.image.DirectColorModel; import java.awt.image.IndexColorModel; import java.awt.image.WritableRaster; +import java.io.BufferedInputStream; import java.io.File; import java.io.FileInputStream; import java.io.IOException; @@ -256,15 +257,18 @@ public class ImageUtil { */ public static List<BufferedImage> getAWTImages(InputStream is, String iconFilePath) throws IOException { List<BufferedImage> images = new ArrayList<BufferedImage>(); - String formatName = getFormatName(iconFilePath); + BufferedInputStream bis = new BufferedInputStream(is); + bis.mark(Integer.MAX_VALUE); + String formatName = getFormatName(bis, iconFilePath); + bis.reset(); if ( !StringUtil.isEmpty(formatName) ) { if (formatName.equalsIgnoreCase(ICO)) { - images = ICODecoder.read(is); + images = ICODecoder.read(bis); } else if (formatName.equalsIgnoreCase(BMP)) { - images.add(BMPDecoder.read(is)); + images.add(BMPDecoder.read(bis)); } else if (formatName.equalsIgnoreCase(SVG)) { SVGUniverse svgUnverse = new SVGUniverse(); - URI iconUri = svgUnverse.loadSVG(is, formatName); + URI iconUri = svgUnverse.loadSVG(bis, formatName); if (iconUri == null) { return images; } @@ -285,7 +289,7 @@ public class ImageUtil { } } else { // CAUTION: numbers of source Raster bands and source color space components do not match" bug. - images.add(ImageIO.read(is)); + images.add(ImageIO.read(bis)); } } return images; @@ -610,37 +614,59 @@ public class ImageUtil { /** * Gets image file's format name. - * @param fullPath + * @param path * @return Returns format name. If the extension is ico, it returns ico. If null, it returns extension. * @throws IOException */ - public static String getFormatName(String fullPath) throws IOException { - String extension = FilenameUtil.getExtension(fullPath); + public static String getFormatName(InputStream is, String path) throws IOException { + if (is == null) { + return null; + } + + String extension = FilenameUtil.getExtension(path); if (ICO.equalsIgnoreCase(extension)) { return ICO; } - ImageInputStream iis = null; String result = null; + result = getRawFormatName(is); + if (result == null) { + result = extension; + } + return result; + } + + /** + * Gets image file's format name. + * @param fullPath + * @return Returns format name. If the extension is ico, it returns ico. If null, it returns extension. + * @throws IOException + */ + public static String getFormatName(String fullPath) throws IOException { + File file = new File(fullPath); + if (!file.exists()) { + return null; + } + + InputStream is = null; try { - iis = ImageIO.createImageInputStream(new File(fullPath)); - result = getRawFormatName(iis); - if (result == null) { - result = extension; - } + is = new FileInputStream(fullPath); + return getFormatName(is, fullPath); } finally { - IOUtil.tryClose(iis); + IOUtil.tryClose(is); } - return result; } /** * Gets image file's format name * @param is - * @return + * @return Returns format name. If <code>is</code> is null, it return null. * @throws IOException */ public static String getRawFormatName(InputStream is) throws IOException { + if (is == null) { + return null; + } ImageInputStream iis = null; String result = null; try { @@ -655,22 +681,22 @@ public class ImageUtil { /** * Gets image file's format name * @param iis - * @return + * @return Returns format name. If <code>iis</code> is null, it return null. * @throws IOException */ public static String getRawFormatName(ImageInputStream iis) throws IOException { + if (iis == null) { + return null; + } + String result = null; - try { - Iterator<ImageReader> readers = ImageIO.getImageReaders(iis); - while (readers.hasNext()) { - ImageReader read = readers.next(); - String formatName = read.getFormatName(); - if (formatName != null) { - return formatName; - } + Iterator<ImageReader> readers = ImageIO.getImageReaders(iis); + while (readers.hasNext()) { + ImageReader read = readers.next(); + String formatName = read.getFormatName(); + if (formatName != null) { + return formatName; } - } finally { - IOUtil.tryClose(iis); } return result; } |