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() {
}
* @return URL of resource file
*/
public static URL getResource(String name) {
- Assert.notNull(name);
return BuilderPlugin.getDefault().getBundle().getResource(name);
}
/**
*
* @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;
+ }
}
/**