1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package ch.twiddlefinger.inet.rewinder.resource;
19
20 import java.awt.image.BufferedImage;
21
22 import java.io.File;
23 import java.io.FileNotFoundException;
24 import java.io.FileOutputStream;
25 import java.io.IOException;
26
27 import java.net.URL;
28
29 import javax.imageio.ImageIO;
30
31 import javax.swing.ImageIcon;
32
33
34 /***
35 * @author matthias.vonrohr To change the template for this generated type
36 * comment go to Window>Preferences>Java>Code
37 * Generation>Code and Comments
38 */
39 public class Resource {
40 public static URL getURL(String name) {
41 return (Resource.class).getResource(name);
42 }
43
44 public static URL getReplay(String name) {
45 return getURL("replay/" + name);
46 }
47
48 public static BufferedImage getImage(String name) {
49 try {
50 return ImageIO.read(Resource.getURL("image/" + name));
51 } catch (IOException e) {
52 return null;
53 }
54 }
55
56 public static ImageIcon getIcon(String name) {
57 return new ImageIcon(Resource.getURL("image/" + name));
58 }
59
60 public static FileOutputStream getDumpFile(String name)
61 throws FileNotFoundException {
62 File file = new File(getURL("dump/" + name).getPath());
63
64 return new FileOutputStream(file);
65 }
66
67 /***
68 * @param bs
69 * @param string
70 */
71 public static void saveData(byte[] bs, String filename) {
72 try {
73 FileOutputStream out = getDumpFile(filename);
74 out.write(bs);
75 } catch (Exception e) {
76 e.printStackTrace();
77 }
78 }
79 }