Search in sources :

Example 1 with CharacterExporter

use of org.gephi.io.exporter.spi.CharacterExporter in project gephi by gephi.

the class ExportControllerImpl method exportFile.

@Override
public void exportFile(File file, Exporter fileExporter) throws IOException {
    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), "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) {
        }
    }
}
Also used : ByteExporter(org.gephi.io.exporter.spi.ByteExporter) CharacterExporter(org.gephi.io.exporter.spi.CharacterExporter) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) BufferedOutputStream(java.io.BufferedOutputStream) FileOutputStream(java.io.FileOutputStream) OutputStreamWriter(java.io.OutputStreamWriter) IOException(java.io.IOException) ProjectController(org.gephi.project.api.ProjectController) BufferedOutputStream(java.io.BufferedOutputStream) IOException(java.io.IOException) Writer(java.io.Writer) OutputStreamWriter(java.io.OutputStreamWriter) Workspace(org.gephi.project.api.Workspace)

Aggregations

BufferedOutputStream (java.io.BufferedOutputStream)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 OutputStream (java.io.OutputStream)1 OutputStreamWriter (java.io.OutputStreamWriter)1 Writer (java.io.Writer)1 ByteExporter (org.gephi.io.exporter.spi.ByteExporter)1 CharacterExporter (org.gephi.io.exporter.spi.CharacterExporter)1 ProjectController (org.gephi.project.api.ProjectController)1 Workspace (org.gephi.project.api.Workspace)1