summaryrefslogtreecommitdiffstats
path: root/dozentenmodul/src/main/java
diff options
context:
space:
mode:
authorSimon Rettberg2015-10-27 16:09:13 +0100
committerSimon Rettberg2015-10-27 16:09:13 +0100
commitf6699559593562cbad82443bb6a7a5bbdf51dd31 (patch)
tree01bbd189521eba2ad2ab5e11a2fb2a72a514f951 /dozentenmodul/src/main/java
parent[client] Refactoring: Use TextChangeListener instead of DocumentListener (diff)
downloadtutor-module-f6699559593562cbad82443bb6a7a5bbdf51dd31.tar.gz
tutor-module-f6699559593562cbad82443bb6a7a5bbdf51dd31.tar.xz
tutor-module-f6699559593562cbad82443bb6a7a5bbdf51dd31.zip
[client] ResourceLoader: Fix leak, add getStream()
Diffstat (limited to 'dozentenmodul/src/main/java')
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/util/ResourceLoader.java18
1 files changed, 13 insertions, 5 deletions
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/util/ResourceLoader.java b/dozentenmodul/src/main/java/org/openslx/dozmod/util/ResourceLoader.java
index f22f5282..daa67790 100644
--- a/dozentenmodul/src/main/java/org/openslx/dozmod/util/ResourceLoader.java
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/util/ResourceLoader.java
@@ -6,6 +6,7 @@ import java.awt.Graphics2D;
import java.awt.font.FontRenderContext;
import java.awt.geom.Rectangle2D;
import java.awt.image.BufferedImage;
+import java.io.InputStream;
import java.net.URL;
import javax.swing.ImageIcon;
@@ -31,6 +32,7 @@ public class ResourceLoader {
* an ImageIcon. If the requested resource could not be loaded,
* an icon is generated, containing an error message. If even that
* fails, an empty icon is returned.
+ *
* @param path Resource path to load
* @param description Icon description
* @return ImageIcon instance
@@ -54,13 +56,14 @@ public class ResourceLoader {
return new ImageIcon();
}
}
-
+
/**
* Load the given resource as an ImageIcon.
* This is guaranteed to never throw an Exception and always return
* an ImageIcon. If the requested resource could not be loaded,
* an icon is generated, containing an error message. If even that
* fails, an empty icon is returned.
+ *
* @param path Resource path to load
* @return ImageIcon instance
*/
@@ -70,6 +73,7 @@ public class ResourceLoader {
/**
* Helper that will create an icon with given text.
+ *
* @param errorText Text to render to icon
* @return the icon
*/
@@ -83,8 +87,7 @@ public class ResourceLoader {
int h = (int) bounds.getHeight();
// create a BufferedImage object
- BufferedImage image = new BufferedImage(w, h,
- BufferedImage.TYPE_INT_RGB);
+ BufferedImage image = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
Graphics2D g = image.createGraphics();
// set color and other parameters
@@ -101,13 +104,14 @@ public class ResourceLoader {
/**
* Tries to load the given resource treating it as a text file
+ *
* @param path Resource path to load
* @return content of the loaded resource as String
*/
public static String getTextFile(String path) {
String fileContent = null;
- try {
- fileContent = IOUtils.toString(ResourceLoader.class.getResourceAsStream(path));
+ try (InputStream stream = ResourceLoader.class.getResourceAsStream(path)) {
+ fileContent = IOUtils.toString(stream);
} catch (Exception e) {
LOGGER.error("IO error while trying to load resource '" + path + "'. See trace: ", e);
}
@@ -118,4 +122,8 @@ public class ResourceLoader {
return "Resource '" + path + "' not found.";
}
}
+
+ public static InputStream getStream(String path) {
+ return ResourceLoader.class.getResourceAsStream(path);
+ }
} \ No newline at end of file