/**
   * Converts the code to a list of instructions.
   *
   * @param code the code as an array of bytes from which to read the instructions
   * @param prependInstructions an array of instructions that is prepended, may be <tt>null</tt>
   * @return the <tt>java.util.List</tt> with the instructions
   * @throws IOException if an exception occurs with the code
   */
  public static ArrayList readByteCode(byte[] code, AbstractInstruction[] prependInstructions)
      throws IOException {

    ByteCodeInputStream bcis = new ByteCodeInputStream(new ByteArrayInputStream(code));

    ArrayList instructions = new ArrayList();
    if (prependInstructions != null) {
      for (int i = 0; i < prependInstructions.length; i++) {
        instructions.add(prependInstructions[i]);
      }
    }

    boolean wide = false;
    AbstractInstruction currentInstruction;
    while (bcis.getBytesRead() < code.length) {
      currentInstruction = readNextInstruction(bcis, wide);
      wide = (currentInstruction.getOpcode() == OPCODE_WIDE);
      instructions.add(currentInstruction);
    }

    return instructions;
  }