List of usage examples for java.io Writer flush
public abstract void flush() throws IOException;
From source file:com.netxforge.oss2.config.ThreshdConfigFactory.java
/** {@inheritDoc} */ protected void saveXML(String xmlString) throws IOException { File cfgFile = ConfigFileConstants.getFile(ConfigFileConstants.THRESHD_CONFIG_FILE_NAME); Writer fileWriter = new OutputStreamWriter(new FileOutputStream(cfgFile), "UTF-8"); fileWriter.write(xmlString);/*from w w w . ja v a 2s. co m*/ fileWriter.flush(); fileWriter.close(); }
From source file:com.intel.cosbench.controller.repository.RAMWorkloadRepository.java
private void appendToStops(WorkloadContext workload) throws IOException { String id = workload.getId(); Writer writer = new BufferedWriter(new FileWriter(stops, true)); try {//from w w w. j av a 2 s. co m writer.write(id); writer.write('\n'); writer.flush(); } finally { writer.close(); } String path = stops.getAbsolutePath(); LOGGER.debug("workload {} has been appened to {}", id, path); }
From source file:com.netxforge.oss2.config.NotifdConfigFactory.java
/** {@inheritDoc} */ @Override//from w ww. j a v a 2 s.co m protected void saveXml(String xml) throws IOException { if (xml != null) { Writer fileWriter = new OutputStreamWriter(new FileOutputStream(m_notifdConfFile), "UTF-8"); fileWriter.write(xml); fileWriter.flush(); fileWriter.close(); } }
From source file:de.fenvariel.mavenfreemarker.FreemarkerPlugin.java
private void generate(Template template, File file, Map<String, Object> data, Map<String, Pattern> keepPatterns) throws MojoExecutionException { try {/*from ww w. j a v a 2 s. c om*/ file.getParentFile().mkdirs(); includeKeepSections(file, keepPatterns, data); Writer writer = new FileWriter(file); try { template.process(data, writer); writer.flush(); System.out.println("Written " + file.getCanonicalPath()); } finally { writer.close(); } } catch (Exception ex) { throw new MojoExecutionException("error generating file: " + file.getAbsolutePath() + " from template " + template.getName() + " and source " + data, ex); } }
From source file:com.eufar.asmm.server.DownloadFunction.java
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { System.out.println("DownloadFunction - the function started"); ServletContext context = getServletConfig().getServletContext(); request.setCharacterEncoding("UTF-8"); String dir = context.getRealPath("/tmp"); ;// www.ja v a 2s . c om String filename = ""; File fileDir = new File(dir); try { System.out.println("DownloadFunction - create the file on server"); filename = request.getParameterValues("filename")[0]; String xmltree = request.getParameterValues("xmltree")[0]; // format xml code to pretty xml code Document doc = DocumentHelper.parseText(xmltree); StringWriter sw = new StringWriter(); OutputFormat format = OutputFormat.createPrettyPrint(); format.setIndent(true); format.setIndentSize(4); XMLWriter xw = new XMLWriter(sw, format); xw.write(doc); Writer out = new BufferedWriter( new OutputStreamWriter(new FileOutputStream(dir + "/" + filename), "UTF-8")); out.append(sw.toString()); out.flush(); out.close(); } catch (Exception ex) { System.out.println("ERROR during rendering: " + ex); } try { System.out.println("DownloadFunction - send file to user"); ServletOutputStream out = response.getOutputStream(); File file = new File(dir + "/" + filename); String mimetype = context.getMimeType(filename); response.setContentType((mimetype != null) ? mimetype : "application/octet-stream"); response.setContentLength((int) file.length()); response.setHeader("Content-Disposition", "attachment; filename=\"" + filename + "\""); response.setHeader("Pragma", "private"); response.setHeader("Cache-Control", "private, must-revalidate"); DataInputStream in = new DataInputStream(new FileInputStream(file)); int length; while ((in != null) && ((length = in.read(bbuf)) != -1)) { out.write(bbuf, 0, length); } in.close(); out.flush(); out.close(); FileUtils.cleanDirectory(fileDir); } catch (Exception ex) { System.out.println("ERROR during downloading: " + ex); } System.out.println("DownloadFunction - file ready to be donwloaded"); }
From source file:com.intel.cosbench.controller.repository.RAMWorkloadRepository.java
private void appendToStarts(WorkloadContext workload) throws IOException { String id = workload.getId(); Writer writer = new BufferedWriter(new FileWriter(starts, true)); try {/*from w ww . j a v a 2s .c om*/ writer.write(id); writer.write('\n'); writer.flush(); } finally { writer.close(); } String path = starts.getAbsolutePath(); LOGGER.debug("workload {} has been appened to {}", id, path); }
From source file:com.joshdrummond.webpasswordsafe.android.GetCurrentPassword.java
private void doSubmit() { TextView status = (TextView) findViewById(R.id.status); String url = ((EditText) findViewById(R.id.url)).getText().toString(); String authnUsername = ((EditText) findViewById(R.id.authnUsername)).getText().toString(); String authnPassword = ((EditText) findViewById(R.id.authnPassword)).getText().toString(); String passwordName = ((EditText) findViewById(R.id.passwordName)).getText().toString(); final String requestSOAP = new StringBuffer().append( "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:wps=\"http://www.joshdrummond.com/webpasswordsafe/schemas\">") .append("<soapenv:Header/>").append("<soapenv:Body>").append("<wps:GetCurrentPasswordRequest>") .append("<wps:authnUsername>").append(authnUsername).append("</wps:authnUsername>") .append("<wps:authnPassword>").append(authnPassword).append("</wps:authnPassword>") .append("<wps:passwordName>").append(passwordName).append("</wps:passwordName>") .append("</wps:GetCurrentPasswordRequest>").append("</soapenv:Body>").append("</soapenv:Envelope>") .toString();//from w w w . ja v a 2s . c om try { HttpClient httpClient = new DefaultHttpClient(); HttpContext localContext = new BasicHttpContext(); ContentProducer cp = new ContentProducer() { public void writeTo(OutputStream outstream) throws IOException { Writer writer = new OutputStreamWriter(outstream, "UTF-8"); writer.write(requestSOAP); writer.flush(); } }; HttpEntity entity = new EntityTemplate(cp); HttpPost httpPost = new HttpPost(url); httpPost.setEntity(entity); HttpResponse httpResponse = httpClient.execute(httpPost, localContext); BufferedReader reader = new BufferedReader( new InputStreamReader(httpResponse.getEntity().getContent())); StringBuffer responseSOAP = new StringBuffer(); String line = reader.readLine(); while (line != null) { responseSOAP.append(line); line = reader.readLine(); } status.setText(parseResponse(responseSOAP.toString())); } catch (Exception e) { e.printStackTrace(); status.setText("ERROR: " + e.getMessage()); } }
From source file:edu.unc.lib.dl.fedora.ClientUtils.java
/** * Serializes the FOXML 1.1 JDOM document to a UTF-8 byte array. This method is responsible for assuring that the * FOXML output contains "standalone" datastreams with locally declared namespaces as required by Fedora ingest. * * @param doc//from ww w. j a va 2 s .c o m * a FOXML 1.1 JDOM document * @return a byte array serialization of the Document */ public static byte[] serializeXML(Document doc) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); Writer pw; try { pw = new OutputStreamWriter(baos, "UTF-8"); } catch (UnsupportedEncodingException e) { throw new ServiceException("UTF-8 character encoding support is required", e); } try { // Filtering SAX Events before serializing. // This ensures that any XML datastreams have locally // declared namespaces, which is a Fedora ingest // requirement. OutputFormat format = new OutputFormat("XML", "UTF-8", true); format.setIndent(2); format.setIndenting(true); format.setPreserveSpace(false); format.setLineWidth(200); XMLSerializer serializer = new XMLSerializer(pw, format); ContentHandler chs = serializer.asContentHandler(); StandaloneDatastreamOutputFilter filter = new StandaloneDatastreamOutputFilter(); filter.setContentHandler(chs); SAXOutputter sax = new SAXOutputter(); sax.setContentHandler(filter); sax.output(doc); pw.flush(); } catch (JDOMException e) { throw new ServiceException("Could not generate SAX events from JDOM.", e); } catch (IOException e) { throw new ServiceException("Could not obtain a content handler for the appropriate format and writer.", e); } byte[] result = baos.toByteArray(); if (log.isDebugEnabled()) { try (StringWriter sw = new StringWriter(); ByteArrayInputStream is = new ByteArrayInputStream(result);) { for (int f = is.read(); f != -1; f = is.read()) { sw.write(f); } log.debug(sw.toString()); } catch (IOException e) { throw new ServiceException(e); } } return result; }
From source file:au.org.ala.biocache.dao.TaxonDAOImpl.java
void outputNestedMappableLayerStart(String rank, String taxon, Writer out) throws Exception { out.write("<Layer queryable=\"1\"><Name>" + rank + ":" + taxon + "</Name><Title>" + taxon + "</Title>"); out.flush(); }
From source file:com.ikon.util.impexp.JcrRepositoryChecker.java
/** * Read document contents.//w ww. ja v a2 s. c o m */ private static ImpExpStats readDocument(String token, String docPath, boolean versions, Writer out, InfoDecorator deco) throws PathNotFoundException, AccessDeniedException, RepositoryException, DatabaseException, IOException { log.debug("readDocument({})", docPath); DocumentModule dm = ModuleManager.getDocumentModule(); File fsPath = new File(Config.NULL_DEVICE); ImpExpStats stats = new ImpExpStats(); Document doc = dm.getProperties(token, docPath); try { FileOutputStream fos = new FileOutputStream(fsPath); InputStream is = dm.getContent(token, docPath, false); IOUtils.copy(is, fos); is.close(); if (versions) { // Check version history for (Version ver : dm.getVersionHistory(token, docPath)) { is = dm.getContentByVersion(token, docPath, ver.getName()); IOUtils.copy(is, fos); IOUtils.closeQuietly(is); } } fos.close(); out.write(deco.print(docPath, doc.getActualVersion().getSize(), null)); out.flush(); // Stats stats.setSize(stats.getSize() + doc.getActualVersion().getSize()); stats.setDocuments(stats.getDocuments() + 1); } catch (RepositoryException e) { log.error(e.getMessage()); stats.setOk(false); out.write(deco.print(docPath, doc.getActualVersion().getSize(), e.getMessage())); out.flush(); } return stats; }