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


Java JavaFileObject.openOutputStream方法代码示例

本文整理汇总了Java中javax.tools.JavaFileObject.openOutputStream方法的典型用法代码示例。如果您正苦于以下问题:Java JavaFileObject.openOutputStream方法的具体用法?Java JavaFileObject.openOutputStream怎么用?Java JavaFileObject.openOutputStream使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.tools.JavaFileObject的用法示例。


在下文中一共展示了JavaFileObject.openOutputStream方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: listModuleContent

import javax.tools.JavaFileObject; //导入方法依赖的package包/类
@NonNull
private Iterable<JavaFileObject> listModuleContent(
        @NonNull final ModLoc modLoc,
        @NonNull final String packageName,
        @NonNull final Set<JavaFileObject.Kind> kinds) throws IOException {
    final CachingArchiveProvider cap = CachingArchiveProvider.getDefault();
    final Collection<JavaFileObject> res = new ArrayList<>();
    if (javaBaseModInfo != null && "java.base".equals(modLoc.getModuleName()) && packageName.isEmpty()) {
        final JavaFileObject jfo = new MemJFO("module-info");
        try(OutputStream out = jfo.openOutputStream()) {
            final byte[] data = javaBaseModInfo.get();
            out.write(data, 0, data.length);
        }
        res.add(jfo);
    }
    for (URL url : modLoc.getRoots()) {
        final Archive ca = cap.getArchive(url, false);
        if (ca != null) {
            StreamSupport.stream(
                    ca.getFiles(FileObjects.convertPackage2Folder(packageName), null, kinds, null, false).spliterator(),
                    false)
                    .forEach(res::add);
        }
    }
    return res;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:27,代码来源:ModuleNamesTest.java

示例2: openBinary

import javax.tools.JavaFileObject; //导入方法依赖的package包/类
@Override
public OutputStream openBinary(JPackage pkg, String fileName) throws IOException {
    String qualifiedClassName = toQualifiedClassName(pkg, fileName);

    try {
        JavaFileObject sourceFile;

        sourceFile = filer.createSourceFile(qualifiedClassName, mElements);

        return sourceFile.openOutputStream();
    } catch (FilerException e) {
        /*
* This exception is expected, when some files are created twice. We
* cannot delete existing files, unless using a dirty hack. Files a
* created twice when the same file is created from different
* annotation rounds. Happens when renaming classes, and for
* Background executor. It also probably means I didn't fully
* understand how annotation processing works. If anyone can point
* me out...
*/
        return VOID_OUTPUT_STREAM;
    }
}
 
开发者ID:Kaufland,项目名称:andcouchbaseentity,代码行数:24,代码来源:SourceCodeWriter.java

示例3: writeClass

import javax.tools.JavaFileObject; //导入方法依赖的package包/类
/**
 * Emit a class file for a given class.
 *
 * @param c The class from which a class file is generated.
 */
public JavaFileObject writeClass(ClassSymbol c)
        throws IOException, PoolOverflow, StringOverflow {
    JavaFileObject outFile
            = fileManager.getJavaFileForOutput(CLASS_OUTPUT,
            c.flatname.toString(),
            JavaFileObject.Kind.CLASS,
            c.sourcefile);
    OutputStream out = outFile.openOutputStream();
    try {
        writeClassFile(out, c);
        if (verbose)
            log.printVerbose("wrote.file", outFile);
        out.close();
        out = null;
    } finally {
        if (out != null) {
            // if we are propogating an exception, delete the file
            out.close();
            outFile.delete();
            outFile = null;
        }
    }
    return outFile; // may be null if write failed
}
 
开发者ID:tranleduy2000,项目名称:javaide,代码行数:30,代码来源:ClassWriter.java

示例4: writeClass

import javax.tools.JavaFileObject; //导入方法依赖的package包/类
/** Emit a class file for a given class.
 *  @param c      The class from which a class file is generated.
 */
public JavaFileObject writeClass(ClassSymbol c)
    throws IOException, PoolOverflow, StringOverflow
{
    JavaFileObject outFile
        = fileManager.getJavaFileForOutput(CLASS_OUTPUT,
                                           c.flatname.toString(),
                                           JavaFileObject.Kind.CLASS,
                                           c.sourcefile);
    OutputStream out = outFile.openOutputStream();
    try {
        writeClassFile(out, c);
        if (verbose)
            log.printVerbose("wrote.file", outFile);
        out.close();
        out = null;
    } finally {
        if (out != null) {
            // if we are propagating an exception, delete the file
            out.close();
            outFile.delete();
            outFile = null;
        }
    }
    return outFile; // may be null if write failed
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:29,代码来源:ClassWriter.java

示例5: testValidClassName

import javax.tools.JavaFileObject; //导入方法依赖的package包/类
public void testValidClassName() throws IOException {
    assertNotNull(fm);
    final JavaFileObject fobj = fm.getJavaFileForOutput(StandardLocation.CLASS_OUTPUT, "org.netbeans.java.Test", JavaFileObject.Kind.CLASS, null);
    assertNotNull(fobj);
    try (OutputStream out = fobj.openOutputStream()) {
        out.write(new byte[]{(byte)0xca,(byte)0xfe,(byte)0xba, (byte) 0xbe});
    }
    wbTx.commit();
    FileUtil.refreshFor(FileUtil.toFile(outCp.getRoots()[0]));
    assertNotNull(outCp.findResource("org/netbeans/java/Test.sig"));
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:12,代码来源:OutputFileManagerTest.java

示例6: testInvalidClassName

import javax.tools.JavaFileObject; //导入方法依赖的package包/类
public void testInvalidClassName() throws IOException {
    assertNotNull(fm);
    final JavaFileObject fobj = fm.getJavaFileForOutput(StandardLocation.CLASS_OUTPUT, "org.netbeans.java.<any>", JavaFileObject.Kind.CLASS, null);
    assertNotNull(fobj);
    try (OutputStream out = fobj.openOutputStream()) {
        out.write(new byte[]{(byte)0xca,(byte)0xfe,(byte)0xba, (byte) 0xbe});
    }
    wbTx.commit();
    FileUtil.refreshFor(FileUtil.toFile(outCp.getRoots()[0]));
    assertNull(outCp.findResource("org/netbeans/java/<any>.sig"));
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:12,代码来源:OutputFileManagerTest.java

示例7: testInvalidPackage

import javax.tools.JavaFileObject; //导入方法依赖的package包/类
public void testInvalidPackage() throws IOException {
    assertNotNull(fm);
    final JavaFileObject fobj = fm.getJavaFileForOutput(StandardLocation.CLASS_OUTPUT, "org.netbeans.<error>.Test", JavaFileObject.Kind.CLASS, null);
    assertNotNull(fobj);
    try (OutputStream out = fobj.openOutputStream()) {
        out.write(new byte[]{(byte)0xca,(byte)0xfe,(byte)0xba, (byte) 0xbe});
    }
    wbTx.commit();
    FileUtil.refreshFor(FileUtil.toFile(outCp.getRoots()[0]));
    assertNull(outCp.findResource("org/netbeans/<error>/Test.sig"));
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:12,代码来源:OutputFileManagerTest.java

示例8: writeClass

import javax.tools.JavaFileObject; //导入方法依赖的package包/类
/** Emit a class file for a given class.
 *  @param c      The class from which a class file is generated.
 */
public JavaFileObject writeClass(ClassSymbol c)
    throws IOException, PoolOverflow, StringOverflow
{
    String name = (c.owner.kind == MDL ? c.name : c.flatname).toString();
    Location outLocn;
    if (multiModuleMode) {
        ModuleSymbol msym = c.owner.kind == MDL ? (ModuleSymbol) c.owner : c.packge().modle;
        outLocn = fileManager.getLocationForModule(CLASS_OUTPUT, msym.name.toString());
    } else {
        outLocn = CLASS_OUTPUT;
    }
    JavaFileObject outFile
        = fileManager.getJavaFileForOutput(outLocn,
                                           name,
                                           JavaFileObject.Kind.CLASS,
                                           c.sourcefile);
    OutputStream out = outFile.openOutputStream();
    try {
        writeClassFile(out, c);
        if (verbose)
            log.printVerbose("wrote.file", outFile);
        out.close();
        out = null;
    } finally {
        if (out != null) {
            // if we are propagating an exception, delete the file
            out.close();
            outFile.delete();
            outFile = null;
        }
    }
    return outFile; // may be null if write failed
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:37,代码来源:ClassWriter.java


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