1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.microemu.app.util;
21
22 import java.io.ByteArrayInputStream;
23 import java.io.IOException;
24 import java.io.InputStream;
25 import java.net.URL;
26 import java.net.URLConnection;
27 import java.util.Hashtable;
28
29 public class ResURLConnection extends URLConnection {
30
31 private static final String PREFIX = "res:";
32
33 private Hashtable entries;
34
35 protected ResURLConnection(URL url, Hashtable entries) {
36 super(url);
37
38 this.entries = entries;
39 }
40
41 public void connect() throws IOException {
42 }
43
44 public InputStream getInputStream() throws IOException {
45 String location = url.toString();
46 int idx = location.indexOf(PREFIX);
47 if (idx == -1) {
48 throw new IOException();
49 }
50 location = location.substring(idx + PREFIX.length());
51 byte[] data = (byte[]) entries.get(location);
52 if (data == null) {
53 throw new IOException();
54 }
55 return new ByteArrayInputStream(data);
56 }
57
58 }