1   /*
2    * Copyright (C) The MetaClass Group. All rights reserved.
3    *
4    * This software is published under the terms of the Spice
5    * Software License version 1.1, a copy of which has been included
6    * with this distribution in the LICENSE.txt file.
7    */
8   package org.codehaus.metaclass.io;
9   
10  import java.io.ByteArrayInputStream;
11  import java.io.DataInputStream;
12  import java.io.InputStream;
13  import java.util.HashMap;
14  import java.util.Map;
15  
16  /***
17   * @author Peter Donald
18   * @version $Revision: 1.4 $ $Date: 2004/01/16 00:56:55 $
19   */
20  public class MockClassLoader
21      extends ClassLoader
22  {
23      private final Map m_resources = new HashMap();
24  
25      public void bindResource( final String name, final byte[] data )
26      {
27          m_resources.put( name, data );
28      }
29  
30      public InputStream getResourceAsStream( final String name )
31      {
32          final byte[] bytes = (byte[])m_resources.get( name );
33          if( null == bytes )
34          {
35              return null;
36          }
37          return new DataInputStream( new ByteArrayInputStream( bytes ) );
38      }
39  }