private File convertNWBtoGraphML(File nwbFile, ValidateNWBFile validator) { try { File graphml = getTempFile(); PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(graphml))); BufferedReader reader = new BufferedReader(new FileReader(nwbFile)); writeGraphMLHeader(out); writeAttributes(out, validator); printGraph(out, validator, reader); out.println("</graph>"); out.println("</graphml>"); reader.close(); out.close(); return graphml; } catch (FileNotFoundException e) { guiBuilder.showError("File Not Found Exception", "Got an File Not Found Exception", e); return null; } catch (IOException ioe) { guiBuilder.showError("IOException", "Got an IOException", ioe); return null; } }
public Data[] execute() { File inData, outData; Data[] dm = null; ValidateNWBFile validator; guiBuilder = (GUIBuilderService) ciContext.getService(GUIBuilderService.class.getName()); logger = (LogService) ciContext.getService(LogService.class.getName()); Object inFile = data[0].getData(); String format = data[0].getFormat(); if (inFile instanceof File && format.equalsIgnoreCase(NWBFileProperty.NWB_MIME_TYPE)) { inData = (File) inFile; validator = new ValidateNWBFile(); try { validator.validateNWBFormat(inData); if (validator.getValidationResult()) { outData = convertNWBtoGraphML(inData, validator); if (outData != null) { dm = new Data[] {new BasicData(outData, "file:text/graphml+xml")}; return dm; } else { guiBuilder.showError( "Unable to Make a File Conversion", "Fail to convert a file from NWB file format to GraphML file format.", ""); return null; } } else { guiBuilder.showError( "Unable to Make a File Conversion", "The input file has a bad NWB format. \n" + "Please review the latest NWB File Formate Specification at \n" + "http://nwb.slis.indiana.edu/software.html, and update your file.", ""); return null; } } catch (FileNotFoundException e) { guiBuilder.showError("File Not Found Exception", "Got an File Not Found Exception", e); return null; } catch (IOException ioe) { guiBuilder.showError("IOException", "Got an IOException", ioe); return null; } } else { if (!(inFile instanceof File)) { guiBuilder.showError( "Unable to Make a File Conversion", "Fail to convert a file from NWB format to GraphML format, because the input is not a file.", ""); } else if (!(format.equalsIgnoreCase(NWBFileProperty.NWB_MIME_TYPE))) { guiBuilder.showError( "Unable to Make a File Conversion", "Wrong input file type. Expecting " + NWBFileProperty.NWB_MIME_TYPE + ", but the input file type is " + format + ".", ""); } return null; } }