Code example for JavaFileObject

Methods: openOutputStream

0
    @Override 
    public OutputStream openBinary(JPackage jPackage, String fileName) throws IOException {
        //generate a source file based on package and filename 
        JavaFileObject sourceFile = filer.createSourceFile(toQualifiedClassName(jPackage, fileName));
 
        OutputStream os = sourceFile.openOutputStream();
        openStreams.add(os);
 
        return os;
    } 
 
    private String toQualifiedClassName(JPackage pkg, String fileName) {
        return new PackageClass(pkg.name(), fileName).getFullyQualifiedName();
    } 
 
    @Override 
    public void close() throws IOException {
        for (OutputStream openStream : openStreams) {
            openStream.flush();
            openStream.close();