List of usage examples for java.io BufferedWriter flush
public void flush() throws IOException
From source file:edu.ucsd.crbs.cws.App.java
License:asdf
public static void uploadPreviewWorkflowFile(final String url, Workflow w) throws Exception { ObjectMapper om = new ObjectMapper(); File tmpFile = File.createTempFile("preview", ".json"); try {/*from w w w . j a va 2s. co m*/ BufferedWriter bw = new BufferedWriter(new FileWriter(tmpFile)); ObjectWriter ow = om.writer(); bw.write(ow.writeValueAsString(w)); bw.flush(); bw.close(); RunCommandLineProcess procRunner = new RunCommandLineProcessImpl(); System.out.println("TODO SWITCH THIS TO USE JERSEY CLIENT!!!\n" + "Attempting to run this command: curl -i -X POST --form '" + "_formexamplefile=@" + tmpFile.getAbsolutePath() + "' " + url); String res = procRunner.runCommandLineProcess("curl", "-i", "-X", "POST", "--form", "_formexamplefile=@" + tmpFile.getAbsolutePath(), url); System.out.println("\n"); System.out.println("--------------- URL to Preview ----------------"); System.out.println(res); System.out.println("-----------------------------------------------"); } finally { if (tmpFile != null) { tmpFile.delete(); } } }
From source file:gov.nih.nci.cabig.caaers.web.study.ExportStudyController.java
@Override protected ModelAndView handle(HttpServletRequest request, HttpServletResponse response, Object o, BindException e) throws Exception { Integer studyID = Integer.valueOf(request.getParameter("id")); Study study = studyDao.getById(studyID); studyDao.initialize(study);/*www. jav a2 s. c o m*/ // START study export pre-population study.setCoordinatingCenter(new CoordinatingCenter()); study.getCoordinatingCenter().setStudyCoordinatingCenter(study.getStudyCoordinatingCenter()); study.setFundingSponsor(new FundingSponsor()); study.getFundingSponsor().setStudyFundingSponsor(study.getStudyFundingSponsors().get(0)); for (OrganizationAssignedIdentifier id : study.getOrganizationAssignedIdentifiers()) { if (id.getOrganization().equals(study.getFundingSponsor().getStudyFundingSponsor().getOrganization())) { study.getFundingSponsor().setOrganizationAssignedIdentifier(id); study.getFundingSponsor().getOrganizationAssignedIdentifier().setPrimaryIndicator(true); break; } } for (OrganizationAssignedIdentifier id : study.getOrganizationAssignedIdentifiers()) { if (id.getOrganization() .equals(study.getCoordinatingCenter().getStudyCoordinatingCenter().getOrganization())) { study.getCoordinatingCenter().setOrganizationAssignedIdentifier(id); study.getCoordinatingCenter().getOrganizationAssignedIdentifier().setPrimaryIndicator(false); break; } } // END study export pre-population gov.nih.nci.cabig.caaers.integration.schema.study.Studies studies = converter .convertStudyDomainToStudyDto(study); //Marshall the Data Transfer Object according to Study.xsd schema, //and download it to the client machine. try { String tempDir = System.getProperty("java.io.tmpdir"); String fileName = "ExportedStudy_" + study.getPrimaryIdentifierValue(); fileName = RuleUtil.getStringWithoutSpaces(fileName); StringWriter sw = new StringWriter(); JAXBContext jaxbContext = JAXBContext.newInstance("gov.nih.nci.cabig.caaers.integration.schema.study"); Marshaller marshaller = jaxbContext.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); marshaller.marshal(studies, sw); BufferedWriter out = new BufferedWriter(new FileWriter(tempDir + fileName + ".xml")); out.write(sw.toString()); out.flush(); out.close(); response.setContentType("application/xml"); response.setHeader("Content-Disposition", "attachment; filename=" + fileName + ".xml"); response.setHeader("Content-length", String.valueOf(sw.toString().length())); response.setHeader("Pragma", "private"); response.setHeader("Cache-control", "private, must-revalidate"); OutputStream outputStream = response.getOutputStream(); File file = new File(tempDir + fileName + ".xml"); FileInputStream fileIn = new FileInputStream(file); byte[] buffer = new byte[2048]; int bytesRead = fileIn.read(buffer); while (bytesRead >= 0) { if (bytesRead > 0) outputStream.write(buffer, 0, bytesRead); bytesRead = fileIn.read(buffer); } outputStream.flush(); outputStream.close(); fileIn.close(); } catch (Exception ex) { log.error(ex); ex.printStackTrace(); } return null; }
From source file:vincent.DynamicDataDemo.java
/** * Constructs a new demonstration application. * /*from ww w .j ava 2 s . com*/ * @param title the frame title. */ public DynamicDataDemo(final String title) { super(title); this.series = new TimeSeries("Random Data"); final TimeSeriesCollection dataset = new TimeSeriesCollection(this.series); final JFreeChart chart = createChart(dataset); final ChartPanel chartPanel = new ChartPanel(chart); final JPanel content = new JPanel(new BorderLayout()); content.add(chartPanel); chartPanel.setPreferredSize(new java.awt.Dimension(500, 300)); setContentPane(content); // Zone de saisie de commande vers le port srie : TextField zoneSaisie = new TextField(10); chartPanel.add(zoneSaisie); zoneSaisie.setLocation(100, 300); zoneSaisie.validate(); zoneSaisie.addKeyListener(new KeyAdapter() { public void keyPressed(KeyEvent e) { int key = e.getKeyCode(); if (key == KeyEvent.VK_ENTER) { TextField textField = (TextField) e.getComponent(); try { BufferedWriter writer = tempSerialReader.getEcrivainPortSerie(); writer.write(textField.getText()); writer.write('\r'); writer.flush(); } catch (IOException l_ex) { LOG.error("erreur d'criture sur le port srie: ", l_ex); } } } }); temperatureCouranteLabel = new Label("XX.XC"); chartPanel.add(temperatureCouranteLabel); chartPanel.add(tempsDeChauffeEtRelicat); chartPanel.add(paramsPid); tempSerialReader = new TempSerialReader(this); }
From source file:azkaban.flow.ImmutableFlowManager.java
@Override public FlowExecutionHolder saveExecutableFlow(FlowExecutionHolder holder) { File storageFile = new File(storageDirectory, String.format("%s.json", holder.getFlow().getId())); JSONObject jsonObj = new JSONObject(serializer.apply(holder)); BufferedWriter out = null; try {/*ww w. j a va2 s . c o m*/ out = new BufferedWriter(new FileWriter(storageFile)); out.write(jsonObj.toString(2)); out.flush(); } catch (Exception e) { throw new RuntimeException(e); } finally { IOUtils.closeQuietly(out); } return holder; }
From source file:cc.redpen.formatter.JSONFormatter.java
@Override public String format(Document document, List<ValidationError> errors) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); BufferedWriter writer = new BufferedWriter(new PrintWriter(baos)); try {/*from ww w . ja v a 2 s. c om*/ writer.write(asJSON(document, errors).toString()); writer.flush(); } catch (IOException e) { throw new RuntimeException(e); } return new String(baos.toByteArray(), StandardCharsets.UTF_8); }
From source file:mamo.vanillaVotifier.JsonConfig.java
@Override public synchronized void save() throws IOException { JSONObject config = new JSONObject(); config.put("config-version", getConfigVersion()); config.put("log-file", getLogFile().getPath()); config.put("ip", getInetSocketAddress().getAddress().toString()); config.put("port", getInetSocketAddress().getPort()); config.put("key-pair-files", new JSONObject() { {// w ww . jav a 2 s . c o m put("public", getPublicKeyFile().getPath()); put("private", getPrivateKeyFile().getPath()); } }); config.put("rcon-list", new JSONArray() { { for (final RconConfig rconConfig : getRconConfigs()) { put(new JSONObject() { { put("ip", rconConfig.getInetSocketAddress().getAddress().toString()); put("port", rconConfig.getInetSocketAddress().getPort()); put("password", rconConfig.getPassword()); put("commands", rconConfig.getCommands()); } }); } } }); BufferedWriter out = new BufferedWriter(new FileWriter(configFile)); out.write(JsonUtils.jsonToPrettyString(config)); out.flush(); out.close(); PemWriter publicPemWriter = new PemWriter(new BufferedWriter(new FileWriter(getPublicKeyFile()))); publicPemWriter.writeObject(new PemObject("PUBLIC KEY", getKeyPair().getPublic().getEncoded())); publicPemWriter.flush(); publicPemWriter.close(); PemWriter privatePemWriter = new PemWriter(new BufferedWriter(new FileWriter(getPrivateKeyFile()))); privatePemWriter.writeObject(new PemObject("RSA PRIVATE KEY", getKeyPair().getPrivate().getEncoded())); privatePemWriter.flush(); privatePemWriter.close(); }
From source file:gwap.game.quiz.PlayNCommunicationResource.java
private void doWork(HttpServletRequest request, HttpServletResponse response) throws IOException { // HttpSession session = request.getSession(); this.request = request; this.response = response; ses = request.getSession();/*from w w w .j a v a2 s . c o m*/ SessionTracker.instance().add(ses); // } // give it ten trys to find a valid game configuration for (int ii = 0; ii < 10; ++ii) { JSONObject jsonObject = createJSONObjectForNewGame(); if (jsonObject != null) { jsonObject.put("SID", ses.getId()); InputStream instream = null; OutputStream outstream = null; try { instream = request.getInputStream(); response.setContentType("text/plain"); outstream = response.getOutputStream(); BufferedWriter out = new BufferedWriter(new OutputStreamWriter(outstream)); jsonObject.writeJSONString(out); out.flush(); outstream.flush(); outstream.close(); instream.close(); logger.info("Successfully initialized game"); break; } catch (IOException e) { e.printStackTrace(); } } else { logger.info("Couldn't initialize a game in try no." + ii); } } }
From source file:fr.calamus.common.tools.AbstractTxtFileAccess.java
/** * Saves data (obtained by getLines()) in the file. *//*w w w . j a v a 2s . c o m*/ public void save() { try { BufferedWriter bw = prepareBufferedWriter(); List<String> lines = getLines(); for (int i = 0; i < lines.size(); i++) { bw.write(lines.get(i)); bw.newLine(); } bw.flush(); bw.close(); } catch (IOException ex) { //log.error("", ex); ex.printStackTrace(); } }
From source file:fr.sanofi.fcl4transmart.controllers.listeners.geneExpression.LoadGeneExpressionDataListener.java
public void write(String text) { FileDialog fd = new FileDialog(new Shell()); fd.setText("Choose a log file"); String filePath = fd.open();/* w w w .j av a 2s . c o m*/ try { FileWriter fw = new FileWriter(filePath, true); BufferedWriter output = new BufferedWriter(fw); output.write(text); output.flush(); output.close(); } catch (IOException ioe) { loadDataUI.displayMessage("File error: " + ioe.getLocalizedMessage()); ioe.printStackTrace(); } }
From source file:hu.sztaki.lpds.submitter.service.jobstatus.JobStatusServlet.java
/** Write log into sys.log & stdout. *///from w w w. j av a2 s. co m private void sysLog(String jobID, String txt) { try { if (Conf.getP().getDebug() > 0) { // System.out.println(" JSS " + txt); if (!"".equals(jobID)) { File logfile = new File(Base.getI().getPath() + jobID + "/outputs/plugin.log"); if (logfile.exists()) { FileWriter tmp = new FileWriter(logfile, true); BufferedWriter out = new BufferedWriter(tmp); out.newLine(); out.write(" JSS " + txt); out.flush(); out.close(); } } } } catch (Exception e) { //e.printStackTrace(); } }