UIB : Add error handling 05/18605/1
authorjeonghwan kim <jeonghwan0613.kim@samsung.com>
Thu, 27 Mar 2014 06:12:11 +0000 (15:12 +0900)
committerjeonghwan kim <jeonghwan0613.kim@samsung.com>
Thu, 27 Mar 2014 06:12:11 +0000 (15:12 +0900)
Change-Id: I016f26f5b129e7fbeb90ec7bd9938fcbfd191e3d
Signed-off-by: jeonghwan kim <jeonghwan0613.kim@samsung.com>
org.tizen.webuibuilder/src/org/tizen/webuibuilder/utility/ResourceManager.java

index 1d0ff90..9b6d40d 100644 (file)
@@ -35,20 +35,17 @@ import org.eclipse.jface.resource.ImageDescriptor;
 import org.eclipse.jface.resource.ImageRegistry;
 import org.eclipse.swt.graphics.Image;
 import org.eclipse.ui.plugin.AbstractUIPlugin;
-import org.tizen.common.util.Assert;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.tizen.common.util.IOUtil;
 import org.tizen.webuibuilder.BuilderConstants;
 import org.tizen.webuibuilder.BuilderPlugin;
 
 
-/**
- * ResourceManager
- * 
- * @author hwani
- * 
- */
 public class ResourceManager {
     private static final String ID = BuilderPlugin.PLUGIN_ID;
     private static ImageRegistry imageRegistry = BuilderPlugin.getDefault().getImageRegistry();
+    protected static final Logger logger = LoggerFactory.getLogger(ResourceManager.class);
 
     private ResourceManager() {
     }
@@ -110,7 +107,6 @@ public class ResourceManager {
      * @return URL of resource file
      */
     public static URL getResource(String name) {
-        Assert.notNull(name);
         return BuilderPlugin.getDefault().getBundle().getResource(name);
     }
 
@@ -128,16 +124,27 @@ public class ResourceManager {
     /**
      * 
      * @param name
-     *            resource name
-     * @return String of resource file
-     * @throws IOException
+     *            resource name (bundle relative path)
+     * @return String of resource file (or null)
      */
-    public static String getString(String name) throws IOException {
-        InputStream stream = openStream(name);
-        int length = stream.available();
-        byte[] buffer = new byte[length];
-        stream.read(buffer);
-        return new String(buffer);
+    public static String getString(String name) {
+        InputStream stream = null;
+        try {
+            stream = openStream(name);
+            int length = stream.available();
+            if (length > 4096) {
+                logger.warn("Resource file is too large");
+            }
+            byte[] buffer = new byte[length];
+            int readLength = stream.read(buffer);
+            if (readLength == -1) {
+                logger.warn("End of file");
+            }
+            return new String(buffer);
+        } catch (IOException e) {
+            IOUtil.tryClose(stream);
+            return null;
+        }
     }
 
     /**