@Override public void run() { JFileChooser fileChooser = MainFrame.getFileChooser(); fileChooser.setFileFilter(fileChooser.getAcceptAllFileFilter()); fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY); fileChooser.setMultiSelectionEnabled(false); if(fileChooser.showSaveDialog(null) == JFileChooser.APPROVE_OPTION) { File file = fileChooser.getSelectedFile(); try (ObjectOutputStream s = new ObjectOutputStream(new FileOutputStream(file));) { MainFrame.lockGUI("Serializing JAPE Transducer..."); serialize(s); } catch(IOException ioe) { JOptionPane.showMessageDialog(MainFrame.getInstance(), "Error!\n" + ioe.toString(), "GATE", JOptionPane.ERROR_MESSAGE); ioe.printStackTrace(Err.getPrintWriter()); } finally { MainFrame.unlockGUI(); } } } };
/** * Loads the specified JAPE grammar into GATE and then serializes it * into the specified file. This file can then be used to create * a new transducer instance via the <code>binaryGrammarURL</code> * init time parameter. */ public static void compile(URL jape, File ser) throws Exception { Transducer transducer = new Transducer(); transducer.setGrammarURL(new ResourceReference(jape)); transducer.setEncoding(defaultEncoding); transducer.init(); FileOutputStream out = new FileOutputStream(ser); ObjectOutputStream s = new ObjectOutputStream(out); transducer.serialize(s); s.flush(); s.close(); out.close(); }