class ExportControllerImpl implements ExportController {

    private final FileExporterBuilder[] fileExporterBuilders;
    private final ExporterUI[] uis;

    public ExportControllerImpl() {
        Lookup.getDefault().lookupAll(GraphFileExporterBuilder.class);
        Lookup.getDefault().lookupAll(VectorFileExporterBuilder.class);
        fileExporterBuilders =
            Lookup.getDefault().lookupAll(FileExporterBuilder.class).toArray(new FileExporterBuilder[0]);
        uis = Lookup.getDefault().lookupAll(ExporterUI.class).toArray(new ExporterUI[0]);
    }

    @Override
    public void exportFile(File file) throws IOException {
        Exporter fileExporter = getFileExporter(file);
        if (fileExporter == null) {
            throw new RuntimeException(
                NbBundle.getMessage(ExportControllerImpl.class, "ExportControllerImpl.error.nomatchingexporter"));
        }
        exportFile(file, fileExporter);
    }

    @Override
    public void exportFile(File file, Workspace workspace) throws IOException {
        Exporter fileExporter = getFileExporter(file);
        if (fileExporter == null) {
            throw new RuntimeException(
                NbBundle.getMessage(ExportControllerImpl.class, "ExportControllerImpl.error.nomatchingexporter"));
        }
        fileExporter.setWorkspace(workspace);
        exportFile(file, fileExporter);
    }

    @Override
    public void exportFile(File file, Exporter fileExporter) throws IOException {<FILL_FUNCTION_BODY>}

    @Override
    public void exportStream(OutputStream stream, ByteExporter byteExporter) {
        if (byteExporter.getWorkspace() == null) {
            ProjectController projectController = Lookup.getDefault().lookup(ProjectController.class);
            Workspace workspace = projectController.getCurrentWorkspace();
            byteExporter.setWorkspace(workspace);
        }
        byteExporter.setOutputStream(stream);
        try {
            byteExporter.execute();
        } catch (Exception ex) {
            try {
                stream.flush();
                stream.close();
            } catch (IOException exe) {
            }
            if (ex instanceof RuntimeException) {
                throw (RuntimeException) ex;
            }
            throw new RuntimeException(ex);
        }
        try {
            stream.flush();
            stream.close();
        } catch (IOException ex) {
        }
    }

    @Override
    public void exportWriter(Writer writer, CharacterExporter characterExporter) {
        if (characterExporter.getWorkspace() == null) {
            ProjectController projectController = Lookup.getDefault().lookup(ProjectController.class);
            Workspace workspace = projectController.getCurrentWorkspace();
            characterExporter.setWorkspace(workspace);
        }
        characterExporter.setWriter(writer);
        try {
            characterExporter.execute();
        } catch (Exception ex) {
            try {
                writer.flush();
                writer.close();
            } catch (IOException exe) {
            }
            if (ex instanceof RuntimeException) {
                throw (RuntimeException) ex;
            }
            throw new RuntimeException(ex);
        }
        try {
            writer.flush();
            writer.close();
        } catch (IOException ex) {
        }
    }

    @Override
    public Exporter getFileExporter(File file) {
        for (FileExporterBuilder im : fileExporterBuilders) {
            for (FileType ft : im.getFileTypes()) {
                for (String ex : ft.getExtensions()) {
                    if (hasExt(file, ex)) {
                        return im.buildExporter();
                    }
                }
            }
        }
        return null;
    }

    @Override
    public Exporter getExporter(String exporterName) {
        for (FileExporterBuilder im : fileExporterBuilders) {
            if (im.getName().equalsIgnoreCase(exporterName)) {
                return im.buildExporter();
            }
        }
        for (FileExporterBuilder im : fileExporterBuilders) {
            for (FileType ft : im.getFileTypes()) {
                for (String ex : ft.getExtensions()) {
                    if (ex.equalsIgnoreCase(exporterName)) {
                        return im.buildExporter();
                    }
                }
            }
        }
        return null;
    }

    @Override
    public ExporterUI getUI(Exporter exporter) {
        for (ExporterUI ui : uis) {
            if (ui.isUIForExporter(exporter)) {
                return ui;
            }
        }
        return null;
    }

    private boolean hasExt(File file, String ext) {
        if (ext == null || ext.isEmpty()) {
            return false;
        }

        /** period at first position is not considered as extension-separator */
        if ((file.getName().length() - ext.length()) <= 1) {
            return false;
        }

        boolean ret = file.getName().endsWith(ext);

        return ret;
    }
}

        if (fileExporter.getWorkspace() == null) {
            ProjectController projectController = Lookup.getDefault().lookup(ProjectController.class);
            Workspace workspace = projectController.getCurrentWorkspace();
            fileExporter.setWorkspace(workspace);
        }
        if (fileExporter instanceof ByteExporter) {
            OutputStream stream = new BufferedOutputStream(new FileOutputStream(file));
            ((ByteExporter) fileExporter).setOutputStream(stream);
            try {
                fileExporter.execute();
            } catch (Exception ex) {
                try {
                    stream.flush();
                    stream.close();
                } catch (IOException exe) {
                }
                if (ex instanceof RuntimeException) {
                    throw (RuntimeException) ex;
                }
                throw new RuntimeException(ex);
            }
            try {
                stream.flush();
                stream.close();
            } catch (IOException ex) {
            }
        } else if (fileExporter instanceof CharacterExporter) {
            Writer writer = new OutputStreamWriter(new FileOutputStream(file), StandardCharsets.UTF_8);
            ((CharacterExporter) fileExporter).setWriter(writer);
            try {
                fileExporter.execute();
            } catch (Exception ex) {
                try {
                    writer.flush();
                    writer.close();
                } catch (IOException exe) {
                }
                if (ex instanceof RuntimeException) {
                    throw (RuntimeException) ex;
                }
                throw new RuntimeException(ex);
            }
            try {
                writer.flush();
                writer.close();
            } catch (IOException ex) {
            }
        }
    
<no_super_class>