List of usage examples for java.io Writer append
public Writer append(char c) throws IOException
From source file:org.apache.johnzon.maven.plugin.ExampleToModelMojo.java
private void fieldGetSetMethods(final Writer writer, final String jsonField, final String field, final String type, final String prefix, final int arrayLevel, final Collection<String> imports) throws IOException { final String actualType = buildArrayType(arrayLevel, type); final String actualField = buildValidFieldName(jsonField); final String methodName = StringUtils.capitalize(actualField); if (!jsonField.equals(field)) { // TODO: add it to imports in eager visitor imports.add("org.apache.johnzon.mapper.JohnzonProperty"); writer.append(prefix).append("@JohnzonProperty(\"").append(jsonField).append("\")\n"); }//w ww. j a v a 2 s.c o m writer.append(prefix).append("private ").append(actualType).append(" ").append(actualField).append(";\n"); writer.append(prefix).append("public ").append(actualType).append(" get").append(methodName) .append("() {\n"); writer.append(prefix).append(" return ").append(actualField).append(";\n"); writer.append(prefix).append("}\n"); writer.append(prefix).append("public void set").append(methodName).append("(final ").append(actualType) .append(" newValue) {\n"); writer.append(prefix).append(" this.").append(actualField).append(" = newValue;\n"); writer.append(prefix).append("}\n"); }
From source file:com.github.rvesse.airline.help.cli.bash.BashCompletionGenerator.java
private void generateCommandCompletionFunction(Writer writer, GlobalMetadata<T> global, CommandGroupMetadata group, CommandMetadata command) throws IOException { // Start Function writeCommandFunctionName(writer, global, group, command, true); // Prepare variables writer.append(" # Get completion data").append(NEWLINE); writer.append(" COMPREPLY=()").append(NEWLINE); writer.append(" CURR_WORD=${COMP_WORDS[COMP_CWORD]}").append(NEWLINE); writer.append(" PREV_WORD=${COMP_WORDS[COMP_CWORD-1]}").append(NEWLINE); writer.append(" COMMANDS=$1").append(DOUBLE_NEWLINE); // Prepare the option information Set<String> flagOpts = new HashSet<>(); Set<String> argOpts = new HashSet<>(); for (OptionMetadata option : command.getAllOptions()) { if (option.isHidden() && !this.includeHidden()) continue; if (option.getArity() == 0) { flagOpts.addAll(option.getOptions()); } else {//from w w w. java 2 s. co m argOpts.addAll(option.getOptions()); } } writeWordListVariable(writer, 2, "FLAG_OPTS", flagOpts.iterator()); writeWordListVariable(writer, 2, "ARG_OPTS", argOpts.iterator()); writer.append(NEWLINE); // Check whether we are completing a value for an argument flag if (argOpts.size() > 0) { writer.append(" $( containsElement ${PREV_WORD} ${ARG_OPTS[@]} )").append(NEWLINE); writer.append(" SAW_ARG=$?").append(NEWLINE); // If we previously saw an argument then we are completing that // argument writer.append(" if [[ ${SAW_ARG} -eq 0 ]]; then").append(NEWLINE); writer.append(" ARG_VALUES=").append(NEWLINE); writer.append(" ARG_GENERATED_VALUES=").append(NEWLINE); writer.append(" case ${PREV_WORD} in").append(NEWLINE); for (OptionMetadata option : command.getAllOptions()) { if (option.isHidden() || option.getArity() == 0) continue; // Add cases for the names indent(writer, 6); Iterator<String> names = option.getOptions().iterator(); while (names.hasNext()) { writer.append(names.next()); if (names.hasNext()) writer.append('|'); } writer.append(")\n"); // Then generate the completions for the option BashCompletion completion = getCompletionData(option); if (completion != null && StringUtils.isNotEmpty(completion.command())) { indent(writer, 8); writer.append("ARG_GENERATED_VALUES=$( ").append(completion.command()).append(" )") .append(NEWLINE); } AbstractAllowedValuesRestriction allowedValues = (AbstractAllowedValuesRestriction) CollectionUtils .find(option.getRestrictions(), new AllowedValuesOptionFinder()); if (allowedValues != null && allowedValues.getAllowedValues().size() > 0) { writeWordListVariable(writer, 8, "ARG_VALUES", allowedValues.getAllowedValues().iterator()); } writeCompletionGeneration(writer, 8, true, getCompletionData(option), "ARG_VALUES", "ARG_GENERATED_VALUES"); indent(writer, 8); writer.append(";;").append(NEWLINE); } writer.append(" esac").append(NEWLINE); writer.append(" fi").append(DOUBLE_NEWLINE); } // If we previously saw a flag we could see another option or an // argument if supported BashCompletion completion = null; if (command.getArguments() != null) { completion = getCompletionData(command.getArguments()); if (completion != null && StringUtils.isNotEmpty(completion.command())) { writer.append(" ARGUMENTS=$( ").append(completion.command()).append(" )").append(NEWLINE); } else { writer.append(" ARGUMENTS=").append(NEWLINE); } } else { writer.append(" ARGUMENTS=").append(NEWLINE); } writeCompletionGeneration(writer, 2, true, completion, "FLAG_OPTS", "ARG_OPTS", "ARGUMENTS"); // End Function writer.append('}').append(DOUBLE_NEWLINE); }
From source file:edu.berkeley.compbio.ncbitaxonomy.NcbiTaxonomyServiceEngineImpl.java
public void writeSynonyms(final Writer out) { //DepthFirstTreeIterator<Integer, PhylogenyNode<Integer>> i = getTree().depthFirstIterator(); Iterator<Integer> i = ncbiTaxonomyNodeDao.findAllIds().iterator(); // while (i.hasNext()) { //PhylogenyNode<Integer> n = i.next(); //Integer id = n.getPayload(); Integer id = i.next();//w ww .j a v a2s. com try { out.append(id.toString()).append("\t"); String scientificName = findScientificName(id); out.append(scientificName).append("\t"); Collection<String> synonyms = synonymsOfIdNoCache(id); synonyms.remove(scientificName); out.append(DSStringUtils.join(synonyms, "\t")).append("\n"); } catch (NoSuchNodeException e) { logger.error("Error", e); } catch (IOException e) { logger.error("Error", e); } } }
From source file:org.apache.hadoop.hbase.io.hfile.TestHFile.java
private int writeSomeRecords(Writer writer, int start, int n, boolean useTags) throws IOException { String value = "value"; KeyValue kv;/*from ww w .ja v a 2 s . c o m*/ for (int i = start; i < (start + n); i++) { String key = String.format(localFormatter, Integer.valueOf(i)); if (useTags) { Tag t = new Tag((byte) 1, "myTag1"); Tag[] tags = new Tag[1]; tags[0] = t; kv = new KeyValue(Bytes.toBytes(key), Bytes.toBytes("family"), Bytes.toBytes("qual"), HConstants.LATEST_TIMESTAMP, Bytes.toBytes(value + key), tags); writer.append(kv); } else { kv = new KeyValue(Bytes.toBytes(key), Bytes.toBytes("family"), Bytes.toBytes("qual"), Bytes.toBytes(value + key)); writer.append(kv); } } return (start + n); }
From source file:com.fizzed.rocker.compiler.JavaGenerator.java
public Writer tab(Writer w, int count) throws IOException { for (int i = 0; i < count; i++) { w.append(TAB); }//from w w w .j a v a 2 s .c o m return w; }
From source file:org.openhab.binding.samsungtv.internal.protocol.RemoteControllerLegacy.java
private void sendKeyData(KeyCode key) throws RemoteControllerException { logger.debug("Sending key code {}", key.getValue()); Writer localwriter = writer; Reader localreader = reader;/*from w w w . j a v a 2 s .co m*/ if (localwriter == null || localreader == null) { return; } /* @formatter:off * * offset value and description * ------ --------------------- * 0x00 always 0x00 * 0x01 0x0013 - string length (little endian) * 0x03 "iphone.iapp.samsung" - string content * 0x16 0x0011 - payload size (little endian) * 0x18 payload * * @formatter:on */ try { localwriter.append((char) 0x00); writeString(localwriter, APP_STRING); writeString(localwriter, createKeyDataPayload(key)); localwriter.flush(); /* * Read response. Response is pretty useless, because TV seems to * send same response in both ok and error situation. */ localreader.skip(1); readString(localreader); readCharArray(localreader); } catch (IOException e) { throw new RemoteControllerException(e); } }
From source file:com.github.jsonj.JsonObject.java
@Override public void serialize(Writer w) throws IOException { w.append(JsonSerializer.OPEN_BRACE); Iterator<Entry<Integer, JsonElement>> iterator = intMap.entrySet().iterator(); while (iterator.hasNext()) { Entry<Integer, JsonElement> entry = iterator.next(); EfficientString key = EfficientString.get(entry.getKey()); JsonElement value = entry.getValue(); w.append(JsonSerializer.QUOTE);// w w w.j a v a 2s.c o m w.append(JsonSerializer.jsonEscape(key.toString())); w.append(JsonSerializer.QUOTE); w.append(JsonSerializer.COLON); value.serialize(w); if (iterator.hasNext()) { w.append(JsonSerializer.COMMA); } } w.append(JsonSerializer.CLOSE_BRACE); }
From source file:com.amalto.core.storage.record.SystemDataRecordXmlWriter.java
@Override public void write(DataRecord record, Writer writer) throws IOException { FieldPrinter fieldPrinter = new FieldPrinter(record, writer); Set<FieldMetadata> fields = type == null ? new HashSet<FieldMetadata>(record.getType().getFields()) : new HashSet<FieldMetadata>(type.getFields()); // Print isMany=false as attributes fieldPrinter.printAttributes(true);// w w w .ja va 2 s .c o m writer.write("<" + getRootElementName(record)); //$NON-NLS-1$ Iterator<FieldMetadata> iterator = fields.iterator(); while (iterator.hasNext()) { FieldMetadata field = iterator.next(); if (field instanceof SimpleTypeFieldMetadata && !field.isMany() && isValidAttributeType(field.getType())) { writer.append(' '); field.accept(fieldPrinter); iterator.remove(); } } writer.write('>'); // Print isMany=true as elements fieldPrinter.printAttributes(false); for (FieldMetadata field : fields) { field.accept(fieldPrinter); } writer.write("</" + getRootElementName(record) + ">"); //$NON-NLS-1$ //$NON-NLS-2$ writer.flush(); }
From source file:com.bstek.dorado.view.output.ClientObjectOutputter.java
/** * JavaPOJO?JSON//w w w. j a va 2 s .c o m */ @Override protected void outputObject(Object object, OutputContext context) throws IOException, Exception { Writer writer = context.getWriter(); if (object != null) { JsonBuilder json = context.getJsonBuilder(); if (usePrototype && StringUtils.isNotEmpty(prototype)) { writer.write("new "); writer.write(prototype); writer.write("("); } if (isEscapeable(context)) { json.escapeableObject(); } else { json.object(); } if (!usePrototype && StringUtils.isNotEmpty(shortTypeName) && !DEFAULT_SHORT_TYPE_NAME.equals(shortTypeName)) { json.key("$type").value(shortTypeName); } outputObjectProperties(object, context); json.endObject(); if (usePrototype && StringUtils.isNotEmpty(prototype)) { writer.write(")"); } } else { writer.append("null"); } }
From source file:org.exoplatform.social.notification.plugin.SpaceInvitationPlugin.java
@Override public boolean makeDigest(NotificationContext ctx, Writer writer) { List<NotificationInfo> notifications = ctx.getNotificationInfos(); NotificationInfo first = notifications.get(0); String language = getLanguage(first); TemplateContext templateContext = new TemplateContext(first.getKey().getId(), language); Map<String, List<String>> receiverMap = new LinkedHashMap<String, List<String>>(); try {/* ww w.ja va 2 s . com*/ for (NotificationInfo message : notifications) { String spaceId = message.getValueOwnerParameter(SocialNotificationUtils.SPACE_ID.getKey()); Space space = Utils.getSpaceService().getSpaceById(spaceId); if (ArrayUtils.contains(space.getInvitedUsers(), first.getTo()) == false) { continue; } SocialNotificationUtils.processInforSendTo(receiverMap, first.getTo(), spaceId); } writer.append(SocialNotificationUtils.getMessageByIds(receiverMap, templateContext, "space")); } catch (IOException e) { ctx.setException(e); return false; } return true; }