HashCompilerOutput.java :  » Scripting » InstantJ » instantj » compile » pizza » Java Open Source

Java Open Source » Scripting » InstantJ 
InstantJ » instantj » compile » pizza » HashCompilerOutput.java
/**
 * InstantJ
 * 
 * Copyright (C) 2002 Nils Meier
 * Additional changes (C) 2002 Andy Thomas 
 * 
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 * 
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 * 
 */
package instantj.compile.pizza;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;

import net.sf.pizzacompiler.compiler.CompilerOutput;
import net.sf.pizzacompiler.compiler.SourceReader;

/**
 * A compiler output that keeps bytecode in a hashmap
 */
/*package*/ class HashCompilerOutput implements CompilerOutput {

  /** contents */
  private Map name2bytearray = new HashMap(); 
    
  /**
   * @see instantj.compile.pizza.PizzaSourceCompiler#getClassOutputStream(java.lang.String, java.lang.String)
   */
  public OutputStream getClassOutputStream(String sourceFile, String classFullName) throws IOException {
    OutputStream result = new ByteArrayOutputStream(4096);
    name2bytearray.put(classFullName, result);
    return result;
  }
  
  /**
   * @see instantj.compile.pizza.PizzaSourceCompiler#getSourceOutputStream(java.lang.String, java.lang.String, net.sf.pizzacompiler.compiler.SourceReader, int)
   */
  public OutputStream getSourceOutputStream(String sourceFile, String classFullName, SourceReader reader, int pos) throws IOException {
    throw new IOException("Not supported");
  }
  
  /**
   * Classes we contain
   */
  /*package*/ Collection getNames() {
    return name2bytearray.keySet();
  }
  
  /**
   * Bytecode for a class
   */
  /*package*/ byte[] getBytecode(String name) {
    return ((ByteArrayOutputStream)name2bytearray.get(name)).toByteArray();
  }

} //HashCompilerOutput
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.