List of usage examples for java.io Writer append
public Writer append(char c) throws IOException
From source file:org.eclipse.orion.internal.server.servlets.file.FileHandlerV1.java
protected void handleGetMetadata(HttpServletRequest request, HttpServletResponse response, Writer responseWriter, IFileStore file) throws IOException, NoSuchAlgorithmException, JSONException, CoreException { JSONObject result = ServletFileStoreHandler.toJSON(file, file.fetchInfo(EFS.NONE, null), getURI(request)); String etag = generateFileETag(file); result.put(ProtocolConstants.KEY_ETAG, etag); response.setHeader(ProtocolConstants.KEY_ETAG, etag); response.setHeader("Cache-Control", "no-cache"); //$NON-NLS-1$ //$NON-NLS-2$ OrionServlet.decorateResponse(request, result, JsonURIUnqualificationStrategy.ALL); responseWriter.append(result.toString()); }
From source file:com.github.rvesse.airline.help.cli.bash.BashCompletionGenerator.java
private void writeCompletionGeneration(Writer writer, int indent, boolean isNestedFunction, BashCompletion completion, String... varNames) throws IOException { indent(writer, indent);/* ww w .j a v a 2s . c o m*/ writer.append("COMPREPLY=( $(compgen "); if (completion != null) { // Add -o flag as appropriate switch (completion.behaviour()) { case FILENAMES: writer.append("-o default "); break; case DIRECTORIES: writer.append("-o dirnames "); break; case AS_FILENAMES: writer.append("-o filenames "); break; case AS_DIRECTORIES: writer.append("-o plusdirs "); break; case SYSTEM_COMMANDS: writer.append("-c "); break; default: // No completion behaviour break; } } // Build a word list from available variables writer.append("-W \""); for (int i = 0; i < varNames.length; i++) { writer.append("${").append(varNames[i]).append("}"); if (i < varNames.length - 1) writer.append(' '); } if (completion != null && completion.behaviour() == CompletionBehaviour.CLI_COMMANDS) { writer.append(" ${COMMANDS}"); } writer.append("\" -- ${CURR_WORD}) )").append(NEWLINE); // Echo is necessary due when using a nested function calls if (isNestedFunction) { indent(writer, indent); writer.append("echo ${COMPREPLY[@]}").append(NEWLINE); } indent(writer, indent); writer.append("return 0").append(NEWLINE); }
From source file:net.officefloor.plugin.web.http.application.WebApplicationAutoWireOfficeFloorSourceTest.java
/** * Writes the response./*from ww w .j a v a2 s. c o m*/ * * @param response * Response. * @param connection * {@link ServerHttpConnection}. */ private static void writeResponse(String response, ServerHttpConnection connection) throws IOException { Writer writer = connection.getHttpResponse().getEntityWriter(); writer.append(response); }
From source file:com.joliciel.talismane.terminology.viewer.TerminologyViewerController.java
@FXML protected void handleExportButtonAction(ActionEvent event) { FileChooser fileChooser = new FileChooser(); //Set extension filter FileChooser.ExtensionFilter extFilter = new FileChooser.ExtensionFilter("CSV (*.csv)", "*.csv"); fileChooser.getExtensionFilters().add(extFilter); FileChooser.ExtensionFilter allFilter = new FileChooser.ExtensionFilter("All files (*)", "*"); fileChooser.getExtensionFilters().add(allFilter); String currentDir = System.getProperty("user.dir"); fileChooser.setInitialDirectory(new File(currentDir)); //Show save file dialog File file = fileChooser.showSaveDialog(primaryStage); if (file != null) { try {// w ww . j a v a2 s . c o m CSV.setAddQuotesAlways(true); CSV.setCsvSeparator(csvSeparator); Writer writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file))); ObservableList<Term> terms = tblTerms.getItems(); writer.append(CSV.format("Term") + CSV.format("Frequency") + CSV.format("Expansions") + CSV.format("Contexts") + "\n"); for (Term term : terms) { if (term instanceof TermWrapper) { term = ((TermWrapper) term).getWrappedTerm(); } writer.append(CSV.format(term.getText())); writer.append(CSV.format(term.getFrequency())); writer.append(CSV.format(term.getExpansionCount())); StringBuilder sb = new StringBuilder(); for (Context context : terminologyBase.getContexts(term)) { sb.append(context.getTextSegment() + "|"); } writer.append(CSV.format(sb.toString())); writer.append("\n"); writer.flush(); } writer.close(); } catch (IOException ioe) { throw new RuntimeException(ioe); } } }
From source file:com.github.rvesse.airline.help.cli.bash.BashCompletionGenerator.java
private void writeGroupFunctionCall(Writer writer, GlobalMetadata<T> global, CommandGroupMetadata group, int indent) throws IOException { // Just call the group function and pass its value back up indent(writer, indent);//from w w w. j av a2s. com writer.append("COMPREPLY=( $( "); writeGroupFunctionName(writer, global, group, false); writer.append(" ) )").append(NEWLINE); }
From source file:org.apache.flink.yarn.appMaster.ApplicationMaster.java
private void generateConfigurationFile() throws IOException { // Update yaml conf -> set jobManager address to this machine's address. FileInputStream fis = new FileInputStream(currDir + "/flink-conf.yaml"); BufferedReader br = new BufferedReader(new InputStreamReader(fis)); Writer output = new BufferedWriter(new FileWriter(currDir + "/flink-conf-modified.yaml")); String line;/*from ww w . j a v a 2 s . c o m*/ while ((line = br.readLine()) != null) { if (line.contains(ConfigConstants.JOB_MANAGER_IPC_ADDRESS_KEY)) { output.append(ConfigConstants.JOB_MANAGER_IPC_ADDRESS_KEY + ": " + ownHostname + "\n"); } else if (line.contains(ConfigConstants.JOB_MANAGER_WEB_ROOT_PATH_KEY)) { output.append(ConfigConstants.JOB_MANAGER_WEB_ROOT_PATH_KEY + ": " + "\n"); } else { output.append(line + "\n"); } } // just to make sure. output.append(ConfigConstants.JOB_MANAGER_IPC_ADDRESS_KEY + ": " + ownHostname + "\n"); output.append(ConfigConstants.JOB_MANAGER_IPC_PORT_KEY + ": " + jobManagerPort + "\n"); // already offsetted here. output.append(ConfigConstants.JOB_MANAGER_WEB_ROOT_PATH_KEY + ": " + localWebInterfaceDir + "\n"); output.append(ConfigConstants.JOB_MANAGER_WEB_LOG_PATH_KEY + ": " + logDirs + "\n"); output.append(ConfigConstants.JOB_MANAGER_WEB_PORT_KEY + ": " + jobManagerWebPort + "\n"); if (slots != -1) { // configure slots and default dop output.append(ConfigConstants.TASK_MANAGER_NUM_TASK_SLOTS + ": " + slots + "\n"); output.append( ConfigConstants.DEFAULT_PARALLELIZATION_DEGREE_KEY + ": " + slots * taskManagerCount + "\n"); } // add dynamic properties List<Tuple2<String, String>> dynamicProperties = CliFrontend .getDynamicProperties(dynamicPropertiesEncodedString); for (Tuple2<String, String> dynamicProperty : dynamicProperties) { String propLine = dynamicProperty.f0 + ": " + dynamicProperty.f1; output.append(propLine + "\n"); LOG.debug("Adding user-supplied configuration value to generated configuration file: " + propLine); } output.close(); br.close(); File newConf = new File(currDir + "/flink-conf-modified.yaml"); if (!newConf.exists()) { LOG.warn("modified yaml does not exist!"); } }
From source file:serposcope.controllers.google.GoogleTargetController.java
protected void getTableJson(Group group, GoogleTarget target, List<GoogleSearch> searches, List<Run> runs, LocalDate startDate, LocalDate endDate, Writer writer) throws IOException { writer.append("[[[-1, 0, 0, ["); if (runs.isEmpty() || searches.isEmpty()) { writer.append("]]],[]]"); }/*ww w. ja va 2s. c o m*/ // events List<Event> events = baseDB.event.list(group, startDate, endDate); for (int i = 0; i < runs.size(); i++) { Run run = runs.get(i); Event event = null; for (Event candidat : events) { if (run.getDay().equals(candidat.getDay())) { event = candidat; break; } } if (event != null) { writer.append("[\"").append(StringEscapeUtils.escapeJson(event.getTitle())).append("\",") .append('"').append(StringEscapeUtils.escapeJson(event.getDescription())).append("\"]"); } else { writer.append("0"); } if (i != runs.size() - 1) { writer.append(","); } } writer.append("]],"); Map<Integer, StringBuilder> builders = new HashMap<>(); for (GoogleSearch search : searches) { StringBuilder builder; builders.put(search.getId(), builder = new StringBuilder("[")); GoogleBest best = googleDB.rank.getBest(target.getGroupId(), target.getId(), search.getId()); builder.append(search.getId()).append(",[\"").append(StringEscapeUtils.escapeJson(search.getKeyword())) .append("\",\"") .append(search.getTld() == null ? "" : StringEscapeUtils.escapeJson(search.getTld())) .append("\",\"").append(SMARTPHONE.equals(search.getDevice()) ? 'M' : 'D').append("\",\"") .append(search.getLocal() == null ? "" : StringEscapeUtils.escapeJson(search.getLocal())) .append("\",\"") .append(search.getDatacenter() == null ? "" : StringEscapeUtils.escapeJson(search.getDatacenter())) .append("\",\"").append(search.getCustomParameters() == null ? "" : StringEscapeUtils.escapeJson(search.getCustomParameters())) .append("\"],"); if (best == null) { builder.append("0,"); } else { builder.append("[").append(best.getRank()).append(",\"") .append(best.getRunDay() != null ? best.getRunDay().toLocalDate().toString() : "?") .append("\",\"").append(StringEscapeUtils.escapeJson(best.getUrl())).append("\"],"); } builder.append("["); } for (int i = 0; i < runs.size(); i++) { Run run = runs.get(i); Map<Integer, GoogleRank> ranks = googleDB.rank.list0(run.getId(), group.getId(), target.getId()) .stream().collect(Collectors.toMap((r) -> r.googleSearchId, Function.identity())); for (GoogleSearch search : searches) { StringBuilder builder = builders.get(search.getId()); GoogleRank fullRank = ranks.get(search.getId()); if (fullRank != null && fullRank.rank != GoogleRank.UNRANKED) { builder.append("[").append(fullRank.rank).append(",").append(fullRank.previousRank) .append(",\"").append(StringEscapeUtils.escapeJson(fullRank.url)).append("\"],"); } else { builder.append("0,"); } if (i == runs.size() - 1) { builder.deleteCharAt(builder.length() - 1); builder.append("]]"); } } } List<StringBuilder> buildersArray = new ArrayList<>(builders.values()); for (int i = 0; i < buildersArray.size(); i++) { writer.append(buildersArray.get(i)); if (i != buildersArray.size() - 1) { writer.append(","); } } writer.append("],["); for (int i = 0; i < runs.size(); i++) { Run run = runs.get(i); writer.append("\"").append(run.getDay().toString()).append("\""); if (i != runs.size() - 1) { writer.append(","); } } writer.append("]]"); }
From source file:com.consol.citrus.report.HtmlReporter.java
/** * Creates the HTML report file// ww w . j a va2 s . c o m * @param content The String content of the report file */ private void createReportFile(String content) { Writer fileWriter = null; File targetDirectory = new File(OUTPUT_DIRECTORY); if (!targetDirectory.exists()) { boolean success = targetDirectory.mkdirs(); if (!success) { throw new CitrusRuntimeException("Unable to create folder structure for HTML report"); } } try { fileWriter = new FileWriter(OUTPUT_DIRECTORY + File.separator + REPORT_FILE_NAME); fileWriter.append(content); fileWriter.flush(); } catch (IOException e) { log.error("Failed to save HTML test report", e); } finally { if (fileWriter != null) { try { fileWriter.close(); } catch (IOException e) { log.error("Error closing HTML report file", e); } } } }
From source file:com.github.jknack.handlebars.internal.Variable.java
@SuppressWarnings("unchecked") @Override/*from w ww.ja v a 2 s .co m*/ protected void merge(final Context scope, final Writer writer) throws IOException { Helper<Object> helper = this.helper; boolean blockParam = scope.isBlockParams() && noArg; if (helper != null && !blockParam) { Options options = new Options.Builder(handlebars, name, type, scope, empty(this)) .setParams(params(scope)).setHash(hash(scope)).setWriter(writer).build(); options.data(Context.PARAM_SIZE, this.params.size()); CharSequence result = helper.apply(determineContext(scope), options); writer.append(formatAndEscape(result, Formatter.NOOP)); } else { Object value = scope.get(path); if (value == null) { if (missing != null) { Options options = new Options.Builder(handlebars, name, type, scope, empty(this)) .setParams(params(scope)).setHash(hash(scope)).setWriter(writer).build(); value = missing.apply(determineContext(scope), options); } } if (value instanceof Lambda) { value = Lambdas.merge(handlebars, (Lambda<Object, Object>) value, scope, this); } writer.append(formatAndEscape(value, formatter)); } }
From source file:com.github.rvesse.airline.help.cli.bash.BashCompletionGenerator.java
private void writeCommandCase(Writer writer, GlobalMetadata<T> global, CommandGroupMetadata group, CommandMetadata command, int indent, boolean isNestedFunction) throws IOException { // Start the case indent(writer, indent);/*from w w w . ja v a2 s. c om*/ writer.append(command.getName()).append(')').append(NEWLINE); indent += 2; // Call the function writeCommandFunctionCall(writer, global, group, command, indent); if (isNestedFunction) { // If within a nested function needs to echo the reply indent(writer, indent); writer.append("echo ${COMPREPLY[@]}").append(NEWLINE); } // Want to return and terminate the case indent(writer, indent); writer.append("return $?").append(NEWLINE); indent(writer, indent); writer.append(";;").append(NEWLINE); }