1 /*
2 * MicroEmulator
3 * Copyright (C) 2001-2006 Bartek Teodorczyk <barteo@barteo.net>
4 *
5 * It is licensed under the following two licenses as alternatives:
6 * 1. GNU Lesser General Public License (the "LGPL") version 2.1 or any newer version
7 * 2. Apache License (the "AL") Version 2.0
8 *
9 * You may not use this file except in compliance with at least one of
10 * the above two licenses.
11 *
12 * You may obtain a copy of the LGPL at
13 * http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt
14 *
15 * You may obtain a copy of the AL at
16 * http://www.apache.org/licenses/LICENSE-2.0
17 *
18 * Unless required by applicable law or agreed to in writing, software
19 * distributed under the License is distributed on an "AS IS" BASIS,
20 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21 * See the LGPL or the AL for the specific language governing permissions and
22 * limitations.
23 */
24
25 package org.microemu.app.util;
26
27 import java.io.ByteArrayInputStream;
28 import java.io.IOException;
29 import java.io.InputStream;
30 import java.net.URL;
31 import java.net.URLConnection;
32 import java.util.Hashtable;
33
34 public class ResURLConnection extends URLConnection {
35
36 private static final String PREFIX = "res:";
37
38 private Hashtable entries;
39
40 protected ResURLConnection(URL url, Hashtable entries) {
41 super(url);
42
43 this.entries = entries;
44 }
45
46 public void connect() throws IOException {
47 }
48
49 public InputStream getInputStream() throws IOException {
50 String location = url.toString();
51 int idx = location.indexOf(PREFIX);
52 if (idx == -1) {
53 throw new IOException();
54 }
55 location = location.substring(idx + PREFIX.length());
56 byte[] data = (byte[]) entries.get(location);
57 if (data == null) {
58 throw new IOException();
59 }
60 return new ByteArrayInputStream(data);
61 }
62
63 }