本文整理匯總了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;
}
示例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;
}
}
示例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
}
示例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
}
示例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"));
}
示例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"));
}
示例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"));
}
示例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
}