root / middleware / src / com / gonnatrak / middleware / util / ResourceHelper.java @ 1

View | Annotate | Download

1
/**
2
 * Created by Andrey Khalzov
3
 * 30.07.2008 23:22:29
4
 */
5
package com.gonnatrak.middleware.util;
6
7
import java.io.InputStreamReader;
8
import java.io.Reader;
9
import java.io.IOException;
10
11
public class ResourceHelper {
12
    public static String getResourceForClass(Class clazz, String path) throws IOException {
13
        Reader reader = null;
14
        try {
15
            final StringBuilder sb = new StringBuilder();
16
            reader = new InputStreamReader(clazz.getResourceAsStream(path), "utf-8");
17
18
            char[] buffer = new char[1024];
19
            int read = reader.read(buffer);
20
            while (read > 0) {
21
                sb.append(buffer, 0, read);
22
                read = reader.read(buffer);
23
            }
24
            return sb.toString();
25
        } finally {
26
            if (reader != null) {
27
                reader.close();
28
            }
29
        }
30
    }
31
}