01: /**
02: * InstantJ
03: *
04: * Copyright (C) 2002 Nils Meier
05: * Additional changes (C) 2002 Andy Thomas
06: *
07: * This library is free software; you can redistribute it and/or
08: * modify it under the terms of the GNU Lesser General Public
09: * License as published by the Free Software Foundation; either
10: * version 2.1 of the License, or (at your option) any later version.
11: *
12: * This library is distributed in the hope that it will be useful,
13: * but WITHOUT ANY WARRANTY; without even the implied warranty of
14: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15: * Lesser General Public License for more details.
16: *
17: */package instantj.compile.pizza;
18:
19: import java.io.ByteArrayOutputStream;
20: import java.io.IOException;
21: import java.io.OutputStream;
22: import java.util.Collection;
23: import java.util.HashMap;
24: import java.util.Map;
25:
26: import net.sf.pizzacompiler.compiler.CompilerOutput;
27: import net.sf.pizzacompiler.compiler.SourceReader;
28:
29: /**
30: * A compiler output that keeps bytecode in a hashmap
31: */
32: /*package*/class HashCompilerOutput implements CompilerOutput {
33:
34: /** contents */
35: private Map name2bytearray = new HashMap();
36:
37: /**
38: * @see instantj.compile.pizza.PizzaSourceCompiler#getClassOutputStream(java.lang.String, java.lang.String)
39: */
40: public OutputStream getClassOutputStream(String sourceFile,
41: String classFullName) throws IOException {
42: OutputStream result = new ByteArrayOutputStream(4096);
43: name2bytearray.put(classFullName, result);
44: return result;
45: }
46:
47: /**
48: * @see instantj.compile.pizza.PizzaSourceCompiler#getSourceOutputStream(java.lang.String, java.lang.String, net.sf.pizzacompiler.compiler.SourceReader, int)
49: */
50: public OutputStream getSourceOutputStream(String sourceFile,
51: String classFullName, SourceReader reader, int pos)
52: throws IOException {
53: throw new IOException("Not supported");
54: }
55:
56: /**
57: * Classes we contain
58: */
59: /*package*/Collection getNames() {
60: return name2bytearray.keySet();
61: }
62:
63: /**
64: * Bytecode for a class
65: */
66: /*package*/byte[] getBytecode(String name) {
67: return ((ByteArrayOutputStream) name2bytearray.get(name))
68: .toByteArray();
69: }
70:
71: } //HashCompilerOutput
|