本文整理汇总了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());
}
}
}
}
示例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();
}
}
示例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());
}
}
示例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();
}
示例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));
}
}
示例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();
}
}
示例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);
}
}
示例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();
}
}
示例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;
}