當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。