当前位置: 首页>>代码示例>>Java>>正文


Java CfTranslator类代码示例

本文整理汇总了Java中com.android.dx.dex.cf.CfTranslator的典型用法代码示例。如果您正苦于以下问题:Java CfTranslator类的具体用法?Java CfTranslator怎么用?Java CfTranslator使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


CfTranslator类属于com.android.dx.dex.cf包,在下文中一共展示了CfTranslator类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: defineClass

import com.android.dx.dex.cf.CfTranslator; //导入依赖的package包/类
/**
 * {@inheritDoc}
 */
@Override
public Class<?> defineClass(String name, byte[] data) {
    try {
        DexOptions dexOptions = new DexOptions();
        DexFile dexFile = new DexFile(dexOptions);
        DirectClassFile classFile = new DirectClassFile(data, name.replace('.', '/') + ".class", true);
        classFile.setAttributeFactory(StdAttributeFactory.THE_ONE);
        classFile.getMagic();
        dexFile.add(CfTranslator.translate(classFile, null, new CfOptions(), dexOptions, dexFile));
        Dex dex = new Dex(dexFile.toDex(null, false));
        Dex oldDex = getLastDex();
        if (oldDex != null) {
            dex = new DexMerger(new Dex[]{dex, oldDex}, CollisionPolicy.KEEP_FIRST).merge();
        }
        return loadClass(dex, name);
    } catch (IOException | ClassNotFoundException e) {
        throw new FatalLoadingException(e);
    }
}
 
开发者ID:F43nd1r,项目名称:rhino-android,代码行数:23,代码来源:BaseAndroidClassLoader.java

示例2: processClass

import com.android.dx.dex.cf.CfTranslator; //导入依赖的package包/类
/**
 * Processes one classfile.
 *
 * @param name {@code non-null;} name of the file, clipped such that it
 * <i>should</i> correspond to the name of the class it contains
 * @param bytes {@code non-null;} contents of the file
 * @return whether processing was successful
 */
private static boolean processClass(String name, byte[] bytes) {
    if (! args.coreLibrary) {
        checkClassName(name);
    }

    try {
        ClassDefItem clazz =
            CfTranslator.translate(name, bytes, args.cfOptions, args.dexOptions);
        synchronized (outputDex) {
            outputDex.add(clazz);
        }
        return true;
    } catch (ParseException ex) {
        DxConsole.err.println("\ntrouble processing:");
        if (args.debug) {
            ex.printStackTrace(DxConsole.err);
        } else {
            ex.printContext(DxConsole.err);
        }
    }

    warnings++;
    return false;
}
 
开发者ID:AndreJCL,项目名称:JCL,代码行数:33,代码来源:Main.java

示例3: dex

import com.android.dx.dex.cf.CfTranslator; //导入依赖的package包/类
private static final byte[] dex(String className, byte[] classData) throws ClassFormatError {
    try {
        DexOptions dexOptions = new DexOptions();
        DexFile dxFile = new DexFile(dexOptions);
        CfOptions cfOptions = new CfOptions();
        dxFile.add(CfTranslator.translate(className.replace('.', '/') + ".class", classData, cfOptions, dexOptions));
        StringWriter out = BridJ.debug ? new StringWriter() : null;
        byte[] dexData = dxFile.toDex(out, false);
        if (BridJ.debug) {
            BridJ.info("Dex output for class " + className + " : " + out);
        }
        return dexData;
    } catch (IOException ex) {
        throw new ClassFormatError("Unable to convert class data to Dalvik code using Dex : " + ex);
    }
}
 
开发者ID:nativelibs4java,项目名称:BridJ,代码行数:17,代码来源:AndroidClassDefiner.java

示例4: translateClass

import com.android.dx.dex.cf.CfTranslator; //导入依赖的package包/类
private ClassDefItem translateClass(byte[] bytes, DirectClassFile cf) {
    try {
        return CfTranslator.translate(cf, bytes, cfOptions, dexOptions, outputDex);
    } catch (ParseException e) {
        e.printStackTrace();
        errors.incrementAndGet();
        return null;
    }
}
 
开发者ID:imkiva,项目名称:Krine,代码行数:10,代码来源:DexConverter.java

示例5: translateClass

import com.android.dx.dex.cf.CfTranslator; //导入依赖的package包/类
private static ClassDefItem translateClass(byte[] bytes, DirectClassFile cf) {
    try {
        return CfTranslator.translate(cf, bytes, args.cfOptions,
                args.dexOptions, outputDex);
    } catch (ParseException ex) {
        System.err.println("\ntrouble processing:");
        if (args.debug) {
            ex.printStackTrace(System.err);
        } else {
            ex.printContext(System.err);
        }
    }
    errors.incrementAndGet();
    return null;
}
 
开发者ID:RunasSudo,项目名称:PyAndroid,代码行数:16,代码来源:Dexer.java

示例6: translateClass

import com.android.dx.dex.cf.CfTranslator; //导入依赖的package包/类
private static ClassDefItem translateClass(byte[] bytes, DirectClassFile cf) {
    try {
        return CfTranslator.translate(cf, bytes, args.cfOptions,
                args.dexOptions, outputDex);
    } catch (ParseException ex) {
        DxConsole.err.println("\ntrouble processing:");
        if (args.debug) {
            ex.printStackTrace(DxConsole.err);
        } else {
            ex.printContext(DxConsole.err);
        }
    }
    errors.incrementAndGet();
    return null;
}
 
开发者ID:johnlee175,项目名称:dex,代码行数:16,代码来源:Main.java

示例7: generateDexFile

import com.android.dx.dex.cf.CfTranslator; //导入依赖的package包/类
private OutputFile generateDexFile(OutputFile classFile) {
    if (!classFile.getFullPath().startsWith(arguments.option_out())) {
        Log.error("DexOutputProcess: Something is wrong with the class output path.");
        return null;
    }
    String relativePath = classFile.getFullPath()
            .substring(arguments.option_out().length() + 1);

    // Remove a starting slash or backslash.
    if (relativePath.startsWith("/") || relativePath.startsWith("\\")) {
        relativePath = relativePath.substring(1);
    }
    Log.debug("DExing:" + relativePath);

    CfOptions options = new CfOptions();
    options.strictNameCheck = false;
    ClassDefItem item = CfTranslator.translate(relativePath, classFile.getDataAsBytes(),
            options);
    DexFile dexFile = new DexFile();
    dexFile.add(item);
    try {
        byte[] rawDex = dexFile.toDex(null, false);
        OutputFile result = new OutputFile(rawDex);
        result.setLocation(classFile.getLocation());
        result.setFileName(classFile.getFileName().replace(ClassFile.CLASS_ENDING, DEX_ENDING));
        return result;
    } catch (IOException e) {
        e.printStackTrace();
        Log.error("Could not generate DEX file.");
    }
    return null;
}
 
开发者ID:shannah,项目名称:cn1,代码行数:33,代码来源:DexOutputProcess.java

示例8: addToDexFile

import com.android.dx.dex.cf.CfTranslator; //导入依赖的package包/类
public ClassDefItem addToDexFile(DexFile dest, DirectClassFile classFile) {
  ClassDefItem result = CfTranslator.translate(
      context,
      classFile,
      (byte[]) null /*ignored*/,
      cfOptions,
      dest.getDexOptions(),
      dest);
  dest.add(result);
  return result;
}
 
开发者ID:bazelbuild,项目名称:bazel,代码行数:12,代码来源:Dexing.java

示例9: register

import com.android.dx.dex.cf.CfTranslator; //导入依赖的package包/类
@Override
public void register(String name, byte[] binaryRepresentation) {
    DirectClassFile directClassFile = new DirectClassFile(binaryRepresentation, name.replace('.', '/') + CLASS_FILE_EXTENSION, NON_STRICT);
    directClassFile.setAttributeFactory(new StdAttributeFactory());
    dexFile.add(CfTranslator.translate(directClassFile,
            binaryRepresentation,
            dexCompilerOptions,
            dexFileOptions,
            new DexFile(dexFileOptions)));
}
 
开发者ID:raphw,项目名称:byte-buddy,代码行数:11,代码来源:AndroidClassLoadingStrategy.java

示例10: translateClass

import com.android.dx.dex.cf.CfTranslator; //导入依赖的package包/类
private ClassDefItem translateClass(byte[] bytes, DirectClassFile cf) {
    try {
        return CfTranslator.translate(context, cf, bytes, args.cfOptions,
            args.dexOptions, outputDex);
    } catch (ParseException ex) {
        context.err.println("\ntrouble processing:");
        if (args.debug) {
            ex.printStackTrace(context.err);
        } else {
            ex.printContext(context.err);
        }
    }
    errors.incrementAndGet();
    return null;
}
 
开发者ID:facebook,项目名称:buck,代码行数:16,代码来源:Main.java

示例11: addClass

import com.android.dx.dex.cf.CfTranslator; //导入依赖的package包/类
public void addClass(String nameClass, byte[] byteClass) {
    final CfOptions cf_options = new CfOptions();
    //System.out.println(nameClass);
    final ClassDefItem cdi = CfTranslator.translate(nameClass, byteClass, cf_options, dex_options);
    file.add(cdi);
}
 
开发者ID:AndreJCL,项目名称:JCL,代码行数:7,代码来源:DexFile.java

示例12: processClass

import com.android.dx.dex.cf.CfTranslator; //导入依赖的package包/类
/**
 * Processes one classfile.
 *
 * @param name {@code non-null;} name of the file, clipped such that it
 * <i>should</i> correspond to the name of the class it contains
 * @param bytes {@code non-null;} contents of the file
 * @return whether processing was successful
 */
private boolean processClass(String name, byte[] bytes) {
    if (! args.coreLibrary) {
        checkClassName(name);
    }

    DirectClassFile cf =
        new DirectClassFile(bytes, name, args.cfOptions.strictNameCheck);

    cf.setAttributeFactory(StdAttributeFactory.THE_ONE);
    cf.getMagic();

    int numMethodIds = outputDex.getMethodIds().items().size();
    int numFieldIds = outputDex.getFieldIds().items().size();
    int numTypeIds = outputDex.getTypeIds().items().size();
    int constantPoolSize = cf.getConstantPool().size();

    if (args.multiDex && ((numMethodIds + constantPoolSize > args.maxNumberOfIdxPerDex) ||
        (numFieldIds + constantPoolSize > args.maxNumberOfIdxPerDex) ||
        (numTypeIds + constantPoolSize
                /* annotation added by dx are not counted in numTypeIds */
                + AnnotationUtils.DALVIK_ANNOTATION_NUMBER
                > args.maxNumberOfIdxPerDex))) {
      createDexFile();
    }

    try {
        ClassDefItem clazz =
            CfTranslator.translate(cf, bytes, args.cfOptions, args.dexOptions, args.optimizerOptions, outputDex);
        synchronized (outputDex) {
            outputDex.add(clazz);
        }
        return true;

    } catch (ParseException ex) {
        dxConsole.err.println("\ntrouble processing:");
        if (args.debug) {
            ex.printStackTrace(dxConsole.err);
        } else {
            ex.printContext(dxConsole.err);
        }
    }
    errors++;
    return false;
}
 
开发者ID:saleehk,项目名称:buck-cutom,代码行数:53,代码来源:Main.java


注:本文中的com.android.dx.dex.cf.CfTranslator类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。