List of usage examples for java.io Writer append
public Writer append(char c) throws IOException
From source file:org.lieuofs.extraction.commune.mutation.ExtracteurMutation.java
public void extraireMutation(Date depuis, Date jusqua, Writer writer) throws IOException { MutationCommuneCritere critere = new MutationCommuneCritere(); if (null != depuis) { critere.setDateDebut(depuis);// w ww . j a va2 s.co m } if (null != jusqua) { critere.setDateFin(jusqua); } List<IMutationCommune> mutations = gestionnaire.rechercherMutation(critere); for (IMutationCommune mut : mutations) { String mutStr = mutWriter.ecrireMutation(mut); if (null != mutStr) { writer.append(mutStr); } } writer.close(); }
From source file:com.dasasian.chok.testutil.loadtest.LoadTestMasterOperation.java
@Override public void nodeOperationsComplete(MasterContext context, List<OperationResult> nodeResults) throws Exception { try {// w w w .j a va 2 s.c o m final int queryRate = calculateCurrentQueryRate(); LOG.info("collecting results for iteration " + currentIteration + " and query rate " + queryRate + " after " + (System.currentTimeMillis() - currentIterationStartTime) + " ms ..."); List<LoadTestQueryResult> queryResults = new ArrayList<>(); for (OperationResult operationResult : nodeResults) { if (operationResult == null || operationResult.getUnhandledError() != null) { Exception rootException = null; if (operationResult != null) { //rootException = operationResult.getUnhandledError(); } throw new IllegalStateException( "at least one node operation did not completed properly: " + nodeResults, rootException); } LoadTestNodeOperationResult nodeOperationResult = (LoadTestNodeOperationResult) operationResult; queryResults.addAll(nodeOperationResult.getQueryResults()); } LOG.info("Received " + queryResults.size() + " queries, expected " + queryRate * runTime / 1000); File statisticsFile = new File(resultDir, "load-test-log-" + startTime + ".log"); File resultsFile = new File(resultDir, "load-test-results-" + startTime + ".log"); Writer statisticsWriter = new OutputStreamWriter(new FileOutputStream(statisticsFile, true)); Writer resultWriter = new OutputStreamWriter(new FileOutputStream(resultsFile, true)); if (currentIteration == 0) { // print headers statisticsWriter.append("#queryRate \tnode \tstartTime \tendTime \telapseTime \tquery \n"); resultWriter.append( "#requestedQueryRate \tachievedQueryRate \tfiredQueries \tqueryErrors \tavarageQueryDuration \tstandardDeviation \n"); } try { StorelessUnivariateStatistic timeStandardDeviation = new StandardDeviation(); StorelessUnivariateStatistic timeMean = new Mean(); int errors = 0; for (LoadTestQueryResult result : queryResults) { long elapsedTime = result.getEndTime() > 0 ? result.getEndTime() - result.getStartTime() : -1; statisticsWriter.write(queryRate + "\t" + result.getNodeId() + "\t" + result.getStartTime() + "\t" + result.getEndTime() + "\t" + elapsedTime + "\t" + result.getQuery() + "\n"); if (elapsedTime != -1) { timeStandardDeviation.increment(elapsedTime); timeMean.increment(elapsedTime); } else { ++errors; } } resultWriter.write(queryRate + "\t" + ((double) queryResults.size() / (runTime / 1000)) + "\t" + queryResults.size() + "\t" + errors + "\t" + (int) timeMean.getResult() + "\t" + (int) timeStandardDeviation.getResult() + "\n"); } catch (IOException e) { throw new IllegalStateException("Failed to write statistics data.", e); } try { LOG.info("results written to " + resultsFile.getAbsolutePath()); LOG.info("statistics written to " + statisticsFile.getAbsolutePath()); statisticsWriter.close(); resultWriter.close(); } catch (IOException e) { LOG.warn("Failed to close statistics file."); } if (queryRate + step <= endRate) { currentIteration++; LOG.info("triggering next iteration " + currentIteration); context.getMasterQueue().add(this); } else { LOG.info("finish load test in iteration " + currentIteration + " after " + (System.currentTimeMillis() - startTime) + " ms"); context.getProtocol().removeFlag(getName()); } } catch (Exception e) { context.getProtocol().removeFlag(getName()); } }
From source file:com.github.rvesse.airline.help.html.HtmlCommandUsageGenerator.java
/** * Outputs the style sheet declarations/*ww w . j av a 2 s .c o m*/ * * @param writer * Writer * @throws IOException */ protected void outputStylesheets(Writer writer) throws IOException { for (String stylesheet : this.stylesheetUrls) { writer.append("<link href=\"").append(stylesheet).append("\" rel=\"stylesheet\">\n"); } }
From source file:org.openhab.binding.samsungtv.internal.protocol.RemoteController.java
private void writeString(Writer writer, String str) throws IOException { int len = str.length(); byte low = (byte) (len & 0xFF); byte high = (byte) ((len >> 8) & 0xFF); writer.append((char) (low)); writer.append((char) (high)); writer.append(str);/* w w w . j a v a 2 s . c o m*/ }
From source file:net.sf.katta.tool.loadtest.LoadTestMasterOperation.java
@Override public void nodeOperationsComplete(MasterContext context, List<OperationResult> nodeResults) throws Exception { try {/* ww w.jav a 2 s.c o m*/ final int queryRate = calculateCurrentQueryRate(); LOG.info("collecting results for iteration " + _currentIteration + " and query rate " + queryRate + " after " + (System.currentTimeMillis() - _currentIterationStartTime) + " ms ..."); List<LoadTestQueryResult> queryResults = new ArrayList<LoadTestQueryResult>(); for (OperationResult operationResult : nodeResults) { if (operationResult == null || operationResult.getUnhandledException() != null) { Exception rootException = null; if (operationResult != null) { rootException = operationResult.getUnhandledException(); } throw new IllegalStateException( "at least one node operation did not completed properly: " + nodeResults, rootException); } LoadTestNodeOperationResult nodeOperationResult = (LoadTestNodeOperationResult) operationResult; queryResults.addAll(nodeOperationResult.getQueryResults()); } LOG.info("Received " + queryResults.size() + " queries, expected " + queryRate * _runTime / 1000); File statisticsFile = new File(_resultDir, "load-test-log-" + _startTime + ".log"); File resultsFile = new File(_resultDir, "load-test-results-" + _startTime + ".log"); Writer statisticsWriter = new OutputStreamWriter(new FileOutputStream(statisticsFile, true)); Writer resultWriter = new OutputStreamWriter(new FileOutputStream(resultsFile, true)); if (_currentIteration == 0) { // print headers statisticsWriter.append("#queryRate \tnode \tstartTime \tendTime \telapseTime \tquery \n"); resultWriter.append( "#requestedQueryRate \tachievedQueryRate \tfiredQueries \tqueryErrors \tavarageQueryDuration \tstandardDeviation \n"); } try { StorelessUnivariateStatistic timeStandardDeviation = new StandardDeviation(); StorelessUnivariateStatistic timeMean = new Mean(); int errors = 0; for (LoadTestQueryResult result : queryResults) { long elapsedTime = result.getEndTime() > 0 ? result.getEndTime() - result.getStartTime() : -1; statisticsWriter.write(queryRate + "\t" + result.getNodeId() + "\t" + result.getStartTime() + "\t" + result.getEndTime() + "\t" + elapsedTime + "\t" + result.getQuery() + "\n"); if (elapsedTime != -1) { timeStandardDeviation.increment(elapsedTime); timeMean.increment(elapsedTime); } else { ++errors; } } resultWriter.write(queryRate + "\t" + ((double) queryResults.size() / (_runTime / 1000)) + "\t" + queryResults.size() + "\t" + errors + "\t" + (int) timeMean.getResult() + "\t" + (int) timeStandardDeviation.getResult() + "\n"); } catch (IOException e) { throw new IllegalStateException("Failed to write statistics data.", e); } try { LOG.info("results written to " + resultsFile.getAbsolutePath()); LOG.info("statistics written to " + statisticsFile.getAbsolutePath()); statisticsWriter.close(); resultWriter.close(); } catch (IOException e) { LOG.warn("Failed to close statistics file."); } if (queryRate + _step <= _endRate) { _currentIteration++; LOG.info("triggering next iteration " + _currentIteration); context.getMasterQueue().add(this); } else { LOG.info("finish load test in iteration " + _currentIteration + " after " + (System.currentTimeMillis() - _startTime) + " ms"); context.getProtocol().removeFlag(getName()); } } catch (Exception e) { context.getProtocol().removeFlag(getName()); } }
From source file:org.drools.planner.benchmark.SolverBenchmarkSuite.java
private void writeHtmlOverview(CharSequence htmlFragment) { File htmlOverviewFile = new File(solverStatisticFilesDirectory, "index.html"); Writer writer = null; try {// ww w .ja v a 2 s. com writer = new OutputStreamWriter(new FileOutputStream(htmlOverviewFile), "utf-8"); writer.append("<html>\n"); writer.append("<head>\n"); writer.append(" <title>Statistic</title>\n"); writer.append("</head>\n"); writer.append("<body>\n"); writer.append(htmlFragment); writer.append("</body>\n"); writer.append("</html>\n"); } catch (IOException e) { throw new IllegalArgumentException("Problem writing htmlOverviewFile: " + htmlOverviewFile, e); } finally { IOUtils.closeQuietly(writer); } }
From source file:com.palantir.stash.disapprove.servlet.DisapprovalServlet.java
@Override protected void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { final String user = authenticateUser(req, res); if (user == null) { // not logged in, redirect res.sendRedirect(lup.getLoginUri(getUri(req)).toASCIIString()); return;//from ww w. j av a 2 s . c o m } final String REQ_PARAMS = "repoId(int), prId(long), disapproved(true|false)"; final Integer repoId; final Long prId; try { repoId = Integer.valueOf(req.getParameter("repoId")); prId = Long.valueOf(req.getParameter("prId")); } catch (NumberFormatException e) { throw new IllegalArgumentException("The required paramaters are: " + REQ_PARAMS, e); } final PullRequest pr = pullRequestService.getById(repoId, prId); final Repository repo = pr.getToRef().getRepository(); PullRequestDisapproval prd; DisapprovalConfiguration dc; try { prd = pm.getPullRequestDisapproval(pr); dc = pm.getDisapprovalConfiguration(repo); } catch (SQLException e) { throw new ServletException(e); } boolean oldDisapproval = prd.isDisapproved(); boolean disapproval; String disapproved = req.getParameter("disapproved"); if (disapproved != null && disapproved.equalsIgnoreCase("true")) { disapproval = true; } else if (disapproved != null && disapproved.equalsIgnoreCase("false")) { disapproval = false; } else { throw new IllegalArgumentException("The required parameters are: " + REQ_PARAMS); } Writer w = res.getWriter(); res.setContentType("application/json;charset=UTF-8"); try { processDisapprovalChange(repo, user, prd, oldDisapproval, disapproval); //res.setContentType("text/html;charset=UTF-8"); w.append(new JSONObject(ImmutableMap.of("disapproval", prd.isDisapproved(), "disapprovedBy", prd.getDisapprovedBy(), "enabledForRepo", dc.isEnabled())).toString()); } catch (IllegalStateException e) { w.append(new JSONObject(ImmutableMap.of("error", e.getMessage())).toString()); res.setStatus(401); } finally { w.close(); } }
From source file:org.sonar.plugins.php.codesniffer.PhpCodeSnifferProfileExporter.java
/** * Perform export: Materialize the current active rule set for the profile. The convert it to XML. * //from w w w. jav a2 s . com * @see org.sonar.api.profiles.ProfileExporter#exportProfile(org.sonar.api.profiles.RulesProfile, java.io.Writer) */ @Override public void exportProfile(RulesProfile profile, Writer writer) { try { List<ActiveRule> activeRulesByRepository = profile .getActiveRulesByRepository(PhpCodeSnifferRuleRepository.PHPCS_REPOSITORY_KEY); PmdRuleset ruleset = createRuleset(activeRulesByRepository, profile.getName()); String xmlModules = exportRulesetToXml(ruleset); writer.append(xmlModules); writer.flush(); } catch (IOException e) { throw new SonarException("Fail to export the profile " + profile, e); } }
From source file:com.github.rvesse.airline.help.html.HtmlCommandUsageGenerator.java
/** * Outputs a page header/* w w w. j ava2 s . co m*/ * * @param writer * Writer * @param programName * Program name * @param groupNames * Group name(s) * @param command * Command meta-data * @throws IOException */ protected void outputPageHeader(Writer writer, String programName, String[] groupNames, CommandMetadata command) throws IOException { writer.append("<hr/>\n"); writer.append("<h1 class=\"text-info\">").append(htmlize(programName)).append(" "); if (groupNames != null) { for (int i = 0; i < groupNames.length; i++) { writer.append(htmlize(groupNames[i])).append(" "); } } writer.append(htmlize(command.getName())).append(" Manual Page\n"); writer.append("<hr/>\n"); }
From source file:com.github.rvesse.airline.help.html.HtmlCommandUsageGenerator.java
/** * Outputs a documentation section with the name and description of the * command/*from w w w .j a v a 2s .c o m*/ * * @param writer * Writer * @param programName * Program name * @param groupNames * Group name(s) * @param command * Command meta-data * @throws IOException */ protected void outputDescription(Writer writer, String programName, String[] groupNames, CommandMetadata command) throws IOException { writer.append("<h2 class=\"text-info\">NAME</h1>\n").append(NEWLINE); writer.append("<div class=\"row\">"); writer.append("<div class=\"span8 offset1\">"); writer.append(htmlize(programName)).append(" "); if (groupNames != null) { for (int i = 0; i < groupNames.length; i++) { writer.append(htmlize(groupNames[i])).append(" "); } } writer.append(htmlize(command.getName())).append(" "); writer.append("—"); writer.append(htmlize(command.getDescription())); writer.append("</div>\n"); writer.append("</div>\n"); writer.append(NEWLINE); }