List of usage examples for java.io Writer close
public abstract void close() throws IOException;
From source file:com.palantir.stash.stashbot.servlet.BuildStatusReportingServlet.java
private void printOutput(JSONObject output, HttpServletRequest req, HttpServletResponse res) throws IOException { res.reset();//from www .j a v a2 s.co m res.setStatus(200); res.setContentType("application/json;charset=UTF-8"); Writer w = res.getWriter(); try { w.append(output.toString(4)); } catch (JSONException e) { w.append(output.toString()); } w.close(); }
From source file:org.joy.generator.engine.FreeMarkerImpl.java
@Override public void processToFile(Map<String, Object> model, TemplateElement templateElement) throws TemplateEngineException { try {//from w w w. j av a 2 s. c o m Template template = config.getTemplate(templateElement.getTemplateFile(), templateElement.getEncoding()); // String targetPath = StringUtil .packagePathToFilePath(processToString(model, templateElement.getTargetPath())); // String targetFileName = processToString(model, templateElement.getTargetFileName()); File file = new File(targetPath + File.separator + targetFileName); File directory = new File(targetPath); if (!directory.exists()) { directory.mkdirs(); } Writer out = new BufferedWriter( new OutputStreamWriter(new FileOutputStream(file), templateElement.getEncoding())); template.process(model, out); out.flush(); out.close(); } catch (Exception e) { throw new TemplateEngineException(e.getMessage(), e); } }
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 {/*w ww . j a v a2s. c o 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.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 va 2 s . co m*/ 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:br.gov.frameworkdemoiselle.behave.runner.webdriver.WebDriverRunner.java
private void writeHtmlFile(String path) { try {/* www . j a v a 2 s. c o m*/ File file = new File(path + ".html"); OutputStreamWriter osw = new OutputStreamWriter(new FileOutputStream(file)); Writer w = new BufferedWriter(osw); w.write(this.driver.getPageSource()); w.close(); } catch (Exception e) { throw new BehaveException(message.getString("exception-save-screenshot"), e); } }
From source file:com.gc.iotools.stream.writer.TeeWriter.java
/** {@inheritDoc} */ @Override/*from w w w . j a v a 2 s . c o m*/ public void close() throws IOException { if (!this.closeCalled) { this.closeCalled = true; for (int i = 0; i < this.destinations.length; i++) { final Writer stream = this.destinations[i]; final long start = System.currentTimeMillis(); stream.close(); this.writeTime[i] += System.currentTimeMillis() - start; } } }
From source file:com.betel.flowers.pdf.util.XMLtoHtml.java
public boolean writeHTML(String htmlString, String direccionDestino) throws UnsupportedEncodingException, FileNotFoundException, IOException { Boolean exito = false;/*from w w w . j av a 2 s . com*/ FileOutputStream fos = new FileOutputStream(direccionDestino); Writer out = new BufferedWriter(new OutputStreamWriter(fos, "UTF-8")); try { out.write(htmlString); exito = true; } catch (Exception ex) { } finally { out.close(); fos.close(); } return exito; }
From source file:org.tec.security.spring.AuthenticationFailure.java
/** * {@inheritDoc}/* w w w . jav a2 s .c o m*/ */ @Override() public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response, AuthenticationException exception) throws IOException, ServletException { if (mLogger.isDebugEnabled()) { mLogger.debug("failed login for " + request.getParameter("j_username")); } Writer out = response.getWriter(); try { out.write("{success:false}"); } catch (IOException e) { mLogger.error("failed to write to response", e); response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "processing failed"); } finally { out.close(); } }
From source file:com.streamsets.pipeline.stage.origin.spooldir.TestSpoolDirSourceOnErrorHandling.java
private SpoolDirSource createSource() throws Exception { String dir = createTestDir(); File file1 = new File(dir, "file-0.csv").getAbsoluteFile(); Writer writer = new FileWriter(file1); IOUtils.write("a,b\ncccc,dddd\ne,f\n", writer); writer.close(); File file2 = new File(dir, "file-1.csv").getAbsoluteFile(); writer = new FileWriter(file2); IOUtils.write("x,y", writer); writer.close();//ww w.j a v a 2s. c o m SpoolDirConfigBean conf = new SpoolDirConfigBean(); conf.dataFormat = DataFormat.DELIMITED; conf.spoolDir = dir; conf.batchSize = 10; conf.overrunLimit = 100; conf.poolingTimeoutSecs = 1; conf.filePattern = "file-[0-9].csv"; conf.maxSpoolFiles = 10; conf.initialFileToProcess = null; conf.dataFormatConfig.compression = Compression.NONE; conf.dataFormatConfig.filePatternInArchive = "*"; conf.errorArchiveDir = null; conf.postProcessing = PostProcessingOptions.ARCHIVE; conf.archiveDir = dir; conf.retentionTimeMins = 10; conf.dataFormatConfig.csvFileFormat = CsvMode.RFC4180; conf.dataFormatConfig.csvHeader = CsvHeader.NO_HEADER; conf.dataFormatConfig.csvMaxObjectLen = 5; conf.dataFormatConfig.csvCustomDelimiter = '^'; conf.dataFormatConfig.csvCustomEscape = '^'; conf.dataFormatConfig.csvCustomQuote = '^'; conf.dataFormatConfig.csvRecordType = CsvRecordType.LIST; conf.dataFormatConfig.onParseError = OnParseError.ERROR; conf.dataFormatConfig.maxStackTraceLines = -1; return new SpoolDirSource(conf); }
From source file:org.tec.security.spring.AuthenticationSuccess.java
/** * {@inheritDoc}/*w ww . j ava 2s.c o m*/ */ @Override() public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException { ControllerUtils.clearCurrentUser(request.getSession()); if (mLogger.isDebugEnabled()) { mLogger.debug("succeful login for " + request.getParameter("j_username")); } Writer out = response.getWriter(); try { out.write("{success:true}"); } catch (IOException e) { mLogger.error("failed to write to response", e); response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "processing failed"); } finally { out.close(); } }