Home | History | Annotate | Download | only in system
      1 /*
      2  * Copyright (C) 2016 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 package dalvik.system;
     18 
     19 import java.nio.ByteBuffer;
     20 
     21 /**
     22  * A {@link ClassLoader} implementation that loads classes from a
     23  * buffer containing a DEX file. This can be used to execute code that
     24  * has not been written to the local file system.
     25  */
     26 public final class InMemoryDexClassLoader extends BaseDexClassLoader {
     27     /**
     28      * Create an in-memory DEX class loader with the given dex buffers.
     29      *
     30      * @param dexBuffers array of buffers containing DEX files between
     31      *                       <tt>buffer.position()</tt> and <tt>buffer.limit()</tt>.
     32      * @param parent the parent class loader for delegation.
     33      */
     34     public InMemoryDexClassLoader(ByteBuffer[] dexBuffers, ClassLoader parent) {
     35         super(dexBuffers, parent);
     36     }
     37 
     38     /**
     39      * Creates a new in-memory DEX class loader.
     40      *
     41      * @param dexBuffer buffer containing DEX file contents between
     42      *                       <tt>buffer.position()</tt> and <tt>buffer.limit()</tt>.
     43      * @param parent the parent class loader for delegation.
     44      */
     45     public InMemoryDexClassLoader(ByteBuffer dexBuffer, ClassLoader parent) {
     46         this(new ByteBuffer[] { dexBuffer }, parent);
     47     }
     48 }
     49