1 package sk.stuba.fiit.foo07.genex.common;
2
3 import java.io.BufferedReader;
4 import java.io.FileReader;
5 import java.io.IOException;
6 import java.io.InputStream;
7
8 public class ResourceHelper {
9 public byte[] getResourceBytes(String resPath) {
10 byte imgbytes[] = null;
11 try {
12 InputStream is = getClass().getResourceAsStream(resPath);
13 imgbytes = new byte[is.available()];
14 is.read(imgbytes);
15 } catch (IOException ex) {
16
17
18 }
19 return imgbytes;
20 }
21
22
23
24
25
26
27
28
29 public String getMacros(String filename) {
30 StringBuffer data = null;
31 try {
32 BufferedReader input = new BufferedReader(new FileReader("macros/"
33 + filename));
34 data = new StringBuffer();
35 String line = null;
36 try {
37 while ((line = input.readLine()) != null) {
38 data.append(line);
39 data.append(System.getProperty("line.separator"));
40 }
41 } finally {
42 input.close();
43 }
44
45 } catch (IOException e) {
46 e.printStackTrace();
47 return null;
48 }
49
50 return data.toString();
51 }
52
53 public String getMacros() {
54 return getMacros("default.ltx");
55 }
56 }