List of usage examples for java.io Writer flush
public abstract void flush() throws IOException;
From source file:business.services.PaNumberService.java
public HttpEntity<InputStreamResource> writeAllPaNumbers(List<LabRequestRepresentation> labRequests) throws IOException { ByteArrayOutputStream out = new ByteArrayOutputStream(); Writer writer = new OutputStreamWriter(out, PA_NUMBERS_DOWNLOAD_CHARACTER_ENCODING); CSVWriter csvwriter = new CSVWriter(writer, ',', '"'); csvwriter.writeNext(PA_NUMBERS_HEADER); for (LabRequestRepresentation labRequest : labRequests) { String labRequestCode = labRequest.getLabRequestCode(); String status = labRequest.getStatus().toString(); String labName = labRequest.getLab().getName(); String requesterName = labRequest.getRequesterName(); String requesterEmail = labRequest.getRequesterEmail(); String requesterTelephone = labRequest.getRequesterTelephone(); String labRequestSentDate = labRequest.getSendDate() == null ? "" : labRequest.getSendDate().toString(); for (PathologyRepresentation item : labRequest.getPathologyList()) { csvwriter.writeNext(new String[] { labRequestCode, status, item.getPaNumber(), labName, requesterName, requesterEmail, requesterTelephone, labRequestSentDate }); }/*from w ww. j a v a 2 s . c o m*/ } csvwriter.flush(); writer.flush(); out.flush(); InputStream in = new ByteArrayInputStream(out.toByteArray()); csvwriter.close(); writer.close(); out.close(); InputStreamResource resource = new InputStreamResource(in); HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.valueOf("text/csv;charset=" + PA_NUMBERS_DOWNLOAD_CHARACTER_ENCODING)); String filename = "pa_numbers.csv"; headers.set("Content-Disposition", "attachment; filename=" + filename); HttpEntity<InputStreamResource> response = new HttpEntity<InputStreamResource>(resource, headers); return response; }
From source file:net.cit.tetrad.resource.GraphResource.java
@RequestMapping("/pieGraphData.do") public void pieGraphData(HttpServletRequest request, HttpServletResponse response) { int deviceCode = Integer.parseInt(request.getParameter("deviceCode")); Query query = new Query(Criteria.where("deviceCode").is(deviceCode)); ServerStatus serverStatus = (ServerStatus) monadService.getFindOne(query, ServerStatus.class, ColumnConstent.COLL_DASHBOARD); try {/*ww w .j a v a2s . c o m*/ PersonJson result = new PersonJson(); List<Object> arrTotInfo = new ArrayList<Object>(); String[] lineColor = { "#d3ee36", "#a7ee70", "#58dccd", "#36abee", "#476cee", "#a244ea", "#e33fc7", "#ee4339", "#FF7F50", "#eed236" }; int colorCnt = 0; for (DbStatus dbStatus : serverStatus.getDbInfos()) { List<Object> arrInfo = new ArrayList<Object>(); Map hm = new HashMap(); hm.put("label", dbStatus.getDb()); hm.put("data", dbStatus.getDataSize()); hm.put("color", lineColor[colorCnt % 10]); arrTotInfo.add(hm); colorCnt++; } result.setAaData(arrTotInfo); JSONObject jsonObject = JSONObject.fromObject(result); response.setContentType("text/html;charset=utf-8"); response.setCharacterEncoding("UTF-8"); response.setContentType("text/html"); response.setHeader("Cache-Control", "no-cache"); Writer writer = response.getWriter(); writer.write(jsonObject.toString()); writer.flush(); } catch (Exception e) { log.error(e, e); } }
From source file:be.wimsymons.intellij.polopolyimport.PPImporter.java
private void postData(final String name, final Reader reader, final String contentType, final String extraParams) throws IOException { Writer writer = null; LOGGER.info("Doing HTTP POST for " + name); try {//from w w w . ja va 2 s .c o m URL httpURL = buildURL(target, extraParams); HttpURLConnection httpConnection = (HttpURLConnection) httpURL.openConnection(); httpConnection.setDoInput(true); httpConnection.setDoOutput(true); httpConnection.setUseCaches(false); httpConnection.setRequestMethod("PUT"); httpConnection.setRequestProperty("Content-Type", contentType); httpConnection.setConnectTimeout(2000); httpConnection.setReadTimeout(60000); httpConnection.connect(); if (contentType.contains("UTF-8")) { copyAndFlush(reader, httpConnection.getOutputStream()); } else { writer = new OutputStreamWriter(httpConnection.getOutputStream()); CharStreams.copy(reader, writer); writer.flush(); } int responseCode = httpConnection.getResponseCode(); String responseMessage = httpConnection.getResponseMessage(); if (responseCode < 200 || responseCode >= 300) { failureCount++; PPImportPlugin.doNotify("Import of " + name + " failed: " + responseCode + " - " + responseMessage + "\nCheck the server log for more details.", NotificationType.ERROR); } else { successCount++; } } catch (IOException e) { failureCount++; PPImportPlugin.doNotify("Import of " + name + " failed: " + e.getMessage(), NotificationType.ERROR); } finally { Closeables.close(reader, true); Closeables.close(writer, true); } }
From source file:com.epam.parso.impl.CSVDataWriterImpl.java
/** * The method to export a row from sas7bdat file (stored as an object of the {@link SasFileReaderImpl} class) * using {@link CSVDataWriterImpl#writer}. * * @param columns the {@link Column} class variables list that stores columns description from the sas7bdat file. * @param row the Objects arrays that stores data from the sas7bdat file. * @throws java.io.IOException appears if the output into writer is impossible. *///from www.j a va 2 s .c o m @Override public void writeRow(List<Column> columns, Object[] row) throws IOException { if (row == null) { return; } Writer writer = getWriter(); for (int currentColumnIndex = 0; currentColumnIndex < columns.size(); currentColumnIndex++) { if (row[currentColumnIndex] != null) { if (row[currentColumnIndex].getClass().getName() .compareTo((new byte[0]).getClass().getName()) == 0) { checkSurroundByQuotesAndWrite(writer, getDelimiter(), new String((byte[]) row[currentColumnIndex], ENCODING)); } else { processEntry(columns, row, currentColumnIndex); } } else { checkSurroundByQuotesAndWrite(writer, getDelimiter(), ""); } if (currentColumnIndex != columns.size() - 1) { writer.write(getDelimiter()); } } writer.write(getEndline()); writer.flush(); }
From source file:edu.ku.brc.af.ui.forms.ViewSetMgr.java
/** * Writes the viewset registry file./* www . j ava 2 s .co m*/ * @throws IOException on error */ public void save() throws IOException { Writer output = null; try { output = new BufferedWriter( new FileWriter(contextDir.getAbsoluteFile() + File.separator + REGISTRY_FILENAME)); output.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"); output.write("<files>\n"); for (Enumeration<ViewSetIFace> e = viewsHash.elements(); e.hasMoreElements();) { ViewSetIFace viewSet = e.nextElement(); output.write(" <file type=\"" + viewSet.getType().toString() + "\" name=\"" + viewSet.getName() + "\" title=\"" + viewSet.getTitle() + "\" file=\"" + viewSet.getFileName() + "\"/>\n"); } output.write("</files>\n"); } finally { // flush and close both "output" and its underlying FileWriter if (output != null) { output.flush(); output.close(); } } }
From source file:net.cit.tetrad.resource.GraphResource.java
@RequestMapping("/setDbLst.do") public void setDbLst(HttpServletRequest request, HttpServletResponse response) { int deviceCode = Integer.parseInt(request.getParameter("deviceCode")); try {/*from w ww . j av a 2 s. c o m*/ PersonJson result = new PersonJson(); List<DbStatus> dbStatus = subDao.dbLstNan(deviceCode); result.setsEcho(Integer.parseInt(Utility.isNullNumber(request.getParameter("sEcho")))); result.setAaData(dbStatus); JSONObject jsonObject = JSONObject.fromObject(result); Writer writer = setResponse(response).getWriter(); writer.write(jsonObject.toString()); log.debug(jsonObject.toString()); writer.flush(); } catch (Exception e) { log.error(e, e); } }
From source file:net.cit.tetrad.resource.GraphResource.java
@RequestMapping("/subDbGraph.do") public void subDbGraph(HttpServletRequest request, HttpServletResponse response, CommonDto dto) { log.debug("start - subDbGraph.do"); try {//from ww w . ja va 2 s . c o m PersonJson result = new PersonJson(); List<String> fileName = setDbGraphInfo(dto); result.setsEcho(Integer.parseInt(Utility.isNullNumber(request.getParameter("sEcho")))); result.setAaData(fileName); JSONObject jsonObject = JSONObject.fromObject(result); Writer writer = setResponse(response).getWriter(); writer.write(jsonObject.toString()); log.debug(jsonObject.toString()); writer.flush(); } catch (Exception e) { log.error(e, e); } log.debug("end - subDbGraph.do"); }
From source file:net.cit.tetrad.resource.GraphResource.java
@RequestMapping("/soloLockGraph.do") public void soloLockGraph(HttpServletRequest request, HttpServletResponse response, CommonDto dto) { log.debug("start - soloLockGraph"); try {//from w w w . j av a 2 s . com PersonJson result = new PersonJson(); List<String> fileName = new ArrayList<String>(); fileName = setSoloLockGraphInfo(dto); result.setsEcho(Integer.parseInt(Utility.isNullNumber(request.getParameter("sEcho")))); result.setAaData(fileName); JSONObject jsonObject = JSONObject.fromObject(result); Writer writer = setResponse(response).getWriter(); writer.write(jsonObject.toString()); log.debug(jsonObject.toString()); writer.flush(); } catch (Exception e) { log.error(e, e); } log.debug("end - soloLockGraph"); }
From source file:net.cit.tetrad.resource.GraphResource.java
@RequestMapping("/dbGraph.do") public void dbGraph(HttpServletRequest request, HttpServletResponse response, CommonDto dto) { log.debug("start - dbGraph"); try {/*from w ww . ja v a 2 s. c o m*/ PersonJson result = new PersonJson(); GraphDefInfo gdInfo = null; List<String> fileName = new ArrayList<String>(); gdInfo = subDao.getDbGraphDefInfoForSubGraph(dto); fileName.add(rrdService.detailedGraphPerRrdDb(gdInfo)); result.setsEcho(Integer.parseInt(Utility.isNullNumber(request.getParameter("sEcho")))); result.setAaData(fileName); JSONObject jsonObject = JSONObject.fromObject(result); Writer writer = setResponse(response).getWriter(); writer.write(jsonObject.toString()); log.debug(jsonObject.toString()); writer.flush(); } catch (Exception e) { log.error(e, e); } log.debug("end - dbGraph"); }
From source file:helma.servlet.AbstractServletClient.java
void sendError(HttpServletResponse response, int code, String message) throws IOException { if (response.isCommitted()) { return;/*from w ww.j a va 2s. c o m*/ } response.reset(); response.setStatus(code); response.setContentType("text/html"); if (!"true".equalsIgnoreCase(getApplication().getProperty("suppressErrorPage"))) { Writer writer = response.getWriter(); writer.write("<html><body><h3>"); writer.write("Error in application "); try { writer.write(getApplication().getName()); } catch (Exception besafe) { // ignore } writer.write("</h3>"); writer.write(message); writer.write("</body></html>"); writer.flush(); } }