use of org.gephi.io.exporter.spi.ByteExporter 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) {
}
}
}
Aggregations