private void addSourcesContentMap(Appendable out) throws IOException { boolean found = false; List<String> contents = new ArrayList<>(); contents.addAll(Collections.nCopies(sourceFileMap.size(), "")); for (Map.Entry<String, String> entry : sourceFileContentMap.entrySet()) { Integer index = sourceFileMap.get(entry.getKey()); if (index != null && index < contents.size()) { contents.set(index, entry.getValue()); found = true; } } if (!found) { return; } appendFieldStart(out, "sourcesContent"); out.append("["); for (int i = 0; i < contents.size(); i++) { if (i != 0) { out.append(","); } out.append(escapeString(contents.get(i))); } out.append("]"); appendFieldEnd(out); }
public static void appendContentUrl( Appendable writer, String location, HttpServletRequest request) throws IOException { StringBuilder buffer = new StringBuilder(); ContentUrlTag.appendContentPrefix(request, buffer); writer.append(buffer.toString()); writer.append(location); }
@Override public void appendValue( T instance, Appendable buffy, boolean needsEscaping, TranslationContext serializationContext, Format format) throws IOException { String instanceString = ""; if (instance != null && serializationContext != null) instanceString = marshall(instance, serializationContext); // andruid 1/4/10 // instance.toString(); if (needsEscaping) { switch (format) { case JSON: buffy.append(JSONObject.escape(instanceString)); ; break; case XML: XMLTools.escapeXML(buffy, instanceString); break; default: XMLTools.escapeXML(buffy, instanceString); break; } } else buffy.append(instanceString); }
/** * Construit une chaîne de caractères qui contiendra le noeud spécifié ainsi que tous les noeuds * enfants. * * @param model Arborescence à écrire. * @param node Noeud de l'arborescence à écrire. * @param buffer Buffer dans lequel écrire le noeud. * @param level Niveau d'indentation (à partir de 0). * @param last Indique si les niveaux précédents sont en train d'écrire leurs derniers items. * @return Le tableau {@code last}, qui peut éventuellement avoir été agrandit. */ private static boolean[] format( final TreeModel model, final Object node, final Appendable buffer, final int level, boolean[] last, final String lineSeparator) throws IOException { for (int i = 0; i < level; i++) { if (i != level - 1) { buffer.append(last[i] ? '\u00A0' : '\u2502').append("\u00A0\u00A0\u00A0"); } else { buffer.append(last[i] ? '\u2514' : '\u251C').append("\u2500\u2500\u2500"); } } buffer.append(String.valueOf(node)).append(lineSeparator); if (level >= last.length) { last = XArray.resize(last, level * 2); } final int count = model.getChildCount(node); for (int i = 0; i < count; i++) { last[level] = (i == count - 1); last = format(model, model.getChild(node, i), buffer, level + 1, last, lineSeparator); } return last; }
/** Dumps messages to the given output stream, returning the highest message level seen. */ static MessageLevel dumpMessages(MessageQueue mq, MessageContext mc, Appendable out) { MessageLevel maxLevel = MessageLevel.values()[0]; for (Message m : mq.getMessages()) { MessageLevel level = m.getMessageLevel(); if (maxLevel.compareTo(level) < 0) { maxLevel = level; } } MessageLevel ignoreLevel = null; if (maxLevel.compareTo(MessageLevel.LINT) < 0) { // If there's only checkpoints, be quiet. ignoreLevel = MessageLevel.LOG; } try { for (Message m : mq.getMessages()) { MessageLevel level = m.getMessageLevel(); if (ignoreLevel != null && level.compareTo(ignoreLevel) <= 0) { continue; } out.append(level.name() + ": "); m.format(mc, out); out.append("\n"); if (maxLevel.compareTo(level) < 0) { maxLevel = level; } } } catch (IOException ex) { ex.printStackTrace(); } return maxLevel; }
/* ------------------------------------------------------------ */ public void dump(Appendable out, String indent) throws IOException { out.append(this.getClass().getSimpleName()) .append("@") .append(Long.toHexString(this.hashCode())) .append("\n"); int size = _bindings.size(); int i = 0; for (Map.Entry<String, Binding> entry : ((Map<String, Binding>) _bindings).entrySet()) { boolean last = ++i == size; out.append(indent).append(" +- ").append(entry.getKey()).append(": "); Binding binding = entry.getValue(); Object value = binding.getObject(); if ("comp".equals(entry.getKey()) && value instanceof Reference && "org.eclipse.jetty.jndi.ContextFactory" .equals(((Reference) value).getFactoryClassName())) { ContextFactory.dump(out, indent + (last ? " " : " | ")); } else if (value instanceof Dumpable) { ((Dumpable) value).dump(out, indent + (last ? " " : " | ")); } else { out.append(value.getClass().getSimpleName()).append("="); out.append(String.valueOf(value).replace('\n', '|').replace('\r', '|')); out.append("\n"); } } }
@Override public ValidationState getValidationState(Appendable errMsg) { try { // TODO: check duplicate columns here!!! if (ntmp.getSourceIndex() == -1) { if (ntmp.getTargetIndex() == -1) { errMsg.append( "The network cannot be created without selecting the source and target columns."); return ValidationState.INVALID; } else { errMsg.append( "No edges will be created in the network; the target column is not selected.\nDo you want to continue?"); return ValidationState.REQUEST_CONFIRMATION; } } else { if (ntmp.getTargetIndex() == -1) { errMsg.append( "No edges will be created in the network; the source column is not selected.\nDo you want to continue?"); return ValidationState.REQUEST_CONFIRMATION; } else { return ValidationState.OK; } } } catch (IOException ioe) { ioe.printStackTrace(); return ValidationState.INVALID; } }
public void appendScript(Appendable target) throws IOException { target.append(name).append('('); boolean first = true; List<?> parameters = getParameters(); if (null != parameters) { for (Iterator<?> param = parameters.iterator(); param.hasNext(); ) { Object element = param.next(); if (!first) { target.append(','); } if (null != element) { ScriptUtils.appendScript(target, element); } else { target.append("null"); } first = false; } } target.append(")"); }
/** {@inheritDoc} */ @Override protected void toTextInternal(Appendable writer) throws IOException { writer.append(getArithmeticSign()); if (stateObject != null) { writer.append(SPACE); stateObject.toString(writer); } }
private static void appendFirstField(Appendable out, String name, CharSequence value) throws IOException { out.append("\""); out.append(name); out.append("\""); out.append(":"); out.append(value); }
public void appendString(Appendable appendable, String start, String separator, String end) { try { appendable.append(start); appendable.append(end); } catch (IOException e) { throw new RuntimeException(e); } }
public void complete() { try { if (c == '{') _buffer.append("{}"); else if (c != 0) _buffer.append("}"); } catch (IOException e) { throw new RuntimeException(e); } }
private static void writeJSONValue(Appendable sb, Object o, int indentFactor, int indent) throws Exception { if (o == null) sb.append("null"); else if (o instanceof String) sb.append(JSONObject.quote((String) o)); else if (o instanceof JSONObject) writeJSON(sb, (JSONObject) o, indentFactor, indent); else if (o instanceof JSONArray) writeJSON(sb, (JSONArray) o, indentFactor, indent); else sb.append(o.toString()); }
protected static void unicodeEscape(Appendable out, int ch) throws IOException { out.append('\\'); out.append('u'); out.append(hexdigits[(ch >>> 12)]); out.append(hexdigits[(ch >>> 8) & 0xf]); out.append(hexdigits[(ch >>> 4) & 0xf]); out.append(hexdigits[(ch) & 0xf]); }
@Override public void addEndText(final Appendable out, final Object... data) { try { out.append("</applet>"); out.append("\n"); } catch (IOException e) { throw new RuntimeException(e); } }
public void formatShort(Appendable out) throws IOException { if (!FilePosition.PREDEFINED.equals(this)) { MessageContext mc = new MessageContext(); mc.addInputSource(source); out.append(mc.abbreviate(source)).append(":").append(String.valueOf(this.startLineNo)); } else { out.append("predefined"); } }
public void write(Appendable out) throws IOException { out.append('<'); for (Iterator<Parameter> iter = parameters.iterator(); iter.hasNext(); ) { iter.next().write(out); if (iter.hasNext()) out.append(", "); } out.append("> "); getType().write(out); }
public static void writeReplaceWhitespaces( final String str, final char replacement, final Appendable writer) throws IOException { for (char c : steal(str)) { if (Character.isWhitespace(c)) { writer.append(replacement); } else { writer.append(c); } } }
void appendAnnotation( final Unit<?> unit, final CharSequence symbol, final CharSequence annotation, final Appendable appendable) throws IOException { appendable.append('{'); appendable.append(annotation); appendable.append('}'); }
public void appendRootModuleInfo( Appendable appendable, boolean isDebugMode, Function<String, String> moduleNameToUri) throws IOException { ModuleConfig moduleConfig = config.getModuleConfig(); JsonObject plovrModuleInfo = createModuleInfo(moduleConfig); appendable.append("PLOVR_MODULE_INFO=").append(plovrModuleInfo.toString()).append(";\n"); JsonObject plovrModuleUris = createModuleUris(moduleConfig, moduleNameToUri); appendable.append("PLOVR_MODULE_URIS=").append(plovrModuleUris.toString()).append(";\n"); appendable.append("PLOVR_MODULE_USE_DEBUG_MODE=" + isDebugMode + ";\n"); }
private void write(final CharSequence data) throws IOException { if (data.length() == 0) { return; } if (atStartOfLine) { atStartOfLine = false; output.append(indent); } output.append(data); }
@Override public void printMalformedExpression(Appendable a, int flags) throws IOException { a.append("-("); if (negated == null) { a.append("null"); } else { negated.print(a, flags); } a.append(')'); }
/* ------------------------------------------------------------ */ public static void toHex(byte b, Appendable buf) { try { int d = 0xf & ((0xF0 & b) >> 4); buf.append((char) ((d > 9 ? ('A' - 10) : '0') + d)); d = 0xf & b; buf.append((char) ((d > 9 ? ('A' - 10) : '0') + d)); } catch (IOException e) { throw new RuntimeException(e); } }
@Override protected void toString(Appendable sb, Escaper escaper) throws IOException { if (isString()) { sb.append('"'); sb.append(escaper.escapeJsonString(value.toString())); sb.append('"'); } else { sb.append(value.toString()); } }
public static void appendJsonStringEscapedChar(final char c, final Appendable jsonString) throws IOException { switch (c) { case '\\': case '"': jsonString.append('\\'); jsonString.append(c); break; case '\b': jsonString.append("\\b"); break; case '\t': jsonString.append("\\t"); break; case '\n': jsonString.append("\\n"); break; case '\f': jsonString.append("\\f"); break; case '\r': jsonString.append("\\r"); break; default: if (c < ' ') { jsonString.append("\\u"); appendUnsignedStringPadded(jsonString, (int) c, 4, 4); } else { jsonString.append(c); } } }
private static void addNameMap(Appendable out, Map<String, Integer> map) throws IOException { int i = 0; for (Entry<String, Integer> entry : map.entrySet()) { String key = entry.getKey(); if (i != 0) { out.append(","); } out.append(escapeString(key)); i++; } }
private void appendTraditional(Appendable out, CharSource contents) throws IOException { if (useEval) { out.append("(0,eval(\""); append(out, Mode.ESCAPED, contents); appendSourceUrl(out, Mode.ESCAPED); out.append("\"));"); } else { out.append(contents.read()); appendSourceUrl(out, Mode.NORMAL); } }
/** * Turns a <code>byte</code> array into hex octets. * * @param a the {@link Appendable}, may not be <code>null</code> * @param bytes the <code>byte</code> array * @return {@link Appendable} */ public static Appendable append(Appendable a, byte[] bytes) { try { for (byte b : bytes) { a.append(DIGITS[(byte) ((b & 0xF0) >> 4)]); a.append(DIGITS[(byte) (b & 0x0F)]); } } catch (IOException ex) { // Bla } return a; }
public void addClass(Class type) { try { if (c == 0) throw new IllegalStateException(); _buffer.append(c); _buffer.append("\"class\":"); append(_buffer, type.getName()); c = ','; } catch (IOException e) { throw new RuntimeException(e); } }
static FieldType writeFieldName(String name, IndexSchema schema, Appendable out, int flags) throws IOException { FieldType ft = null; ft = schema.getFieldTypeNoEx(name); out.append(name); if (ft == null) { out.append("(UNKNOWN FIELD " + name + ')'); } out.append(':'); return ft; }