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


Java FileObject.openOutputStream方法代码示例

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


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

示例1: writeServices

import javax.tools.FileObject; //导入方法依赖的package包/类
private void writeServices() {
    for (Map.Entry<Filer,Map<String,SortedSet<ServiceLoaderLine>>> outputFiles : outputFilesByProcessor.entrySet()) {
        Filer filer = outputFiles.getKey();
        for (Map.Entry<String,SortedSet<ServiceLoaderLine>> entry : outputFiles.getValue().entrySet()) {
            try {
                FileObject out = filer.createResource(StandardLocation.CLASS_OUTPUT, "", entry.getKey(),
                        originatingElementsByProcessor.get(filer).get(entry.getKey()).toArray(new Element[0]));
                OutputStream os = out.openOutputStream();
                try {
                    PrintWriter w = new PrintWriter(new OutputStreamWriter(os, "UTF-8"));
                    for (ServiceLoaderLine line : entry.getValue()) {
                        line.write(w);
                    }
                    w.flush();
                    w.close();
                } finally {
                    os.close();
                }
            } catch (IOException x) {
                processingEnv.getMessager().printMessage(Kind.ERROR, "Failed to write to " + entry.getKey() + ": " + x.toString());
            }
        }
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:25,代码来源:AbstractServiceProviderProcessor.java

示例2: generateConverterDoc

import javax.tools.FileObject; //导入方法依赖的package包/类
private static void generateConverterDoc(ModelContext ctx, ConverterModel converter) throws TransformerFactoryConfigurationError, IOException {
	String bundleName = converter.getBundleName();
	int dot = bundleName.lastIndexOf('.');
	String packageName = bundleName.substring(0, dot);
	String fileName = bundleName.substring(dot + 1) + ".xml";
	FileObject fo;
	try {
		fo = ctx.getFiler().getResource(StandardLocation.SOURCE_PATH, packageName, fileName);
	} catch (IOException ioe) {
		fo = ctx.getFiler().createResource(StandardLocation.SOURCE_OUTPUT, packageName, fileName);
		ctx.note("generating " + fo.getName());
		PrintWriter out = new PrintWriter(fo.openOutputStream());
		XMLUtils.writeDOMToFile(converter.generateDoc(), null, out);
		out.close();
	}
}
 
开发者ID:Bibliome,项目名称:alvisnlp,代码行数:17,代码来源:ConverterFactoryModel.java

示例3: doWithOriAndPrintWriter

import javax.tools.FileObject; //导入方法依赖的package包/类
public static void doWithOriAndPrintWriter(Filer filer, JavaFileManager.Location location, String relativePath, String filename, BiConsumer<String, PrintWriter> consumer){
    try {
        FileObject resource = filer.getResource(location, relativePath, filename);
        String data;
        try{
            CharSequence cs = resource.getCharContent(false);
            data = cs.toString();
            resource.delete();
        }catch (FileNotFoundException ignored){
            data = "";
        }
        resource = filer.createResource(location, relativePath, filename);

        try(OutputStream outputStream = resource.openOutputStream()){
            consumer.accept(data,new PrintWriter(outputStream));
        }
    } catch (IOException e) {
        note("do with resource file failed"+relativePath+filename+" Exception: " + e.toString());
    }
}
 
开发者ID:frankelau,项目名称:pndao,代码行数:21,代码来源:ResourceHelper.java

示例4: store

import javax.tools.FileObject; //导入方法依赖的package包/类
@Override
public OutputStream store(DefinitionModel model) throws IOException {
  FileObject output = filer
      .createSourceFile(model.getSourcePackage() + "." +  model.getSourceClass() + "_" + FileStore.STANDARD.getPath(),
          model.getSourceElement().get());
  return output.openOutputStream();
}
 
开发者ID:salesforce,项目名称:AptSpring,代码行数:8,代码来源:AptFilerStore.java

示例5: writeItems

import javax.tools.FileObject; //导入方法依赖的package包/类
public void writeItems() {
    try {
        FileObject resource = processingEnv.getFiler()
                .createResource(StandardLocation.CLASS_OUTPUT, "", "META-INF/domino/"+fileName);
        PrintWriter out = new PrintWriter(new OutputStreamWriter(resource.openOutputStream()));
        items.forEach(out::println);
        out.close();
    } catch (IOException ex) {
        messager.printMessage(Diagnostic.Kind.ERROR, ExceptionUtils.getFullStackTrace(ex));
    }
}
 
开发者ID:GwtDomino,项目名称:domino,代码行数:12,代码来源:Register.java

示例6: writeIfChanged

import javax.tools.FileObject; //导入方法依赖的package包/类
private void writeIfChanged(byte[] b, FileObject file) throws IOException {
    boolean mustWrite = false;
    String event = "[No need to update file ";

    if (force) {
        mustWrite = true;
        event = "[Forcefully writing file ";
    } else {
        InputStream in;
        byte[] a;
        try {
            // regrettably, there's no API to get the length in bytes
            // for a FileObject, so we can't short-circuit reading the
            // file here
            in = file.openInputStream();
            a = readBytes(in);
            if (!Arrays.equals(a, b)) {
                mustWrite = true;
                event = "[Overwriting file ";

            }
        } catch (FileNotFoundException e) {
            mustWrite = true;
            event = "[Creating file ";
        }
    }

    if (util.verbose)
        util.log(event + file + "]");

    if (mustWrite) {
        OutputStream out = file.openOutputStream();
        out.write(b); /* No buffering, just one big write! */
        out.close();
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:37,代码来源:Gen.java

示例7: writeProviderFile

import javax.tools.FileObject; //导入方法依赖的package包/类
private void writeProviderFile(TypeElement serviceProvider, String interfaceName) {
    String filename = "META-INF/providers/" + serviceProvider.getQualifiedName();
    try {
        FileObject file = processingEnv.getFiler().createResource(StandardLocation.CLASS_OUTPUT, "", filename, serviceProvider);
        PrintWriter writer = new PrintWriter(new OutputStreamWriter(file.openOutputStream(), "UTF-8"));
        writer.println(interfaceName);
        writer.close();
    } catch (IOException e) {
        processingEnv.getMessager().printMessage(isBug367599(e) ? Kind.NOTE : Kind.ERROR, e.getMessage(), serviceProvider);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:12,代码来源:ServiceProviderProcessor.java

示例8: writeIfChanged

import javax.tools.FileObject; //导入方法依赖的package包/类
private void writeIfChanged(byte[] b, FileObject file) throws IOException {
    boolean mustWrite = false;
    String event = "[No need to update file ";

    if (force) {
        mustWrite = true;
        event = "[Forcefully writing file ";
    } else {
        InputStream in;
        byte[] a;
        try {
            // regrettably, there's no API to get the length in bytes
            // for a FileObject, so we can't short-circuit reading the
            // file here
            in = file.openInputStream();
            a = readBytes(in);
            if (!Arrays.equals(a, b)) {
                mustWrite = true;
                event = "[Overwriting file ";

            }
        } catch (FileNotFoundException | NoSuchFileException e) {
            mustWrite = true;
            event = "[Creating file ";
        }
    }

    if (util.verbose)
        util.log(event + file + "]");

    if (mustWrite) {
        OutputStream out = file.openOutputStream();
        out.write(b); /* No buffering, just one big write! */
        out.close();
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:37,代码来源:Gen.java

示例9: FilerOutputStream

import javax.tools.FileObject; //导入方法依赖的package包/类
/**
 * @param typeName name of class or {@code null} if just a
 * binary file
 */
FilerOutputStream(String typeName, FileObject fileObject) throws IOException {
    super(fileObject.openOutputStream());
    this.typeName = typeName;
    this.fileObject = fileObject;
}
 
开发者ID:tranleduy2000,项目名称:javaide,代码行数:10,代码来源:JavacFiler.java


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