From fbf87f78ec4cf4e1754bf47fdd9e9eb4de0967ff Mon Sep 17 00:00:00 2001 From: "changhyun1.lee" Date: Tue, 29 Oct 2013 21:24:32 +0900 Subject: [PATCH] [Title] Added imageUtil function [Desc.] [Issue] Change-Id: Iad296294ba5a8c77b569ba29fe3701fbeab758bf Signed-off-by: changhyun1.lee --- .../src/org/tizen/common/util/ImageUtil.java | 32 ++++++++++++++++++++++ 1 file changed, 32 insertions(+) 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 3349c61..eb30507 100644 --- a/org.tizen.common/src/org/tizen/common/util/ImageUtil.java +++ b/org.tizen.common/src/org/tizen/common/util/ImageUtil.java @@ -35,6 +35,7 @@ import java.io.File; import java.io.IOException; import java.io.InputStream; import java.net.URL; +import java.net.URLConnection; import javax.imageio.ImageIO; @@ -164,6 +165,37 @@ public class ImageUtil { g.dispose(); return bi; } + /** + * Returns a BufferedImage from URL + * + * @param url an URL + * + * @return a BufferedImage containing the decoded + * contents of the URL, or null. + */ + public static BufferedImage getBufferedImageFromURL(URL url) { + if (url == null) { + return null; + } + BufferedImage bImage = null; + InputStream input = null; + int contentLength = 0; + try { + URLConnection con = url.openConnection(); + con.setConnectTimeout(100); + contentLength = con.getContentLength(); + if ( contentLength == 0 || contentLength == -1 ) { + return null; + } + input = url.openStream(); + bImage = ImageIO.read( input ); + } catch (Exception e) { + logger.error(e.getMessage(), e); + } finally { + IOUtil.tryClose(input); + } + return bImage; + } /* * The original source is org.tizen.nativecpp.misc.utils.ImageUtil -- 2.7.4