Transforms the given {@link ClientConfig} to xml string
formatting the output with given {@code indent}, -1 means no
formatting.
179776
public static String generate(ClientConfig clientConfig, int indent) {
        Preconditions.isNotNull(clientConfig, "ClientConfig");

        StringBuilder xml = new StringBuilder();
        xml.append("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>");
        XmlGenerator gen = new XmlGenerator(xml);

        gen.open("hazelcast-client", "xmlns", "http://www.hazelcast.com/schema/client-config",
                "xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance",
                "xsi:schemaLocation", "http://www.hazelcast.com/schema/client-config "
                        + "http://www.hazelcast.com/schema/client-config/hazelcast-client-config-4.0.xsd");

        //GroupConfig
        group(gen, clientConfig.getGroupConfig());
        //InstanceName
        gen.node("instance-name", clientConfig.getInstanceName());
        //attributes
        gen.appendLabels(clientConfig.getLabels());
        //Properties
        gen.appendProperties(clientConfig.getProperties());
        //Network
        network(gen, clientConfig.getNetworkConfig());
        //ExecutorPoolSize
        if (clientConfig.getExecutorPoolSize() > 0) {
            gen.node("executor-pool-size", clientConfig.getExecutorPoolSize());
        }
        //Security
        security(gen, clientConfig.getSecurityConfig());
        //Listeners
        listener(gen, clientConfig.getListenerConfigs());
        //Serialization
        serialization(gen, clientConfig.getSerializationConfig());
        //Native
        nativeMemory(gen, clientConfig.getNativeMemoryConfig());
        //ProxyFactories
        proxyFactory(gen, clientConfig.getProxyFactoryConfigs());
        //LoadBalancer
        loadBalancer(gen, clientConfig.getLoadBalancer());
        //NearCache
        nearCaches(gen, clientConfig.getNearCacheConfigMap());
        //QueryCaches
        queryCaches(gen, clientConfig.getQueryCacheConfigs());
        //ConnectionStrategy
        ClientConnectionStrategyConfig connectionStrategy = clientConfig.getConnectionStrategyConfig();
        gen.node("connection-strategy", null, "async-start", connectionStrategy.isAsyncStart(),
                "reconnect-mode", connectionStrategy.getReconnectMode());
        //UserCodeDeployment
        userCodeDeployment(gen, clientConfig.getUserCodeDeploymentConfig());
        //FlakeIdGenerator
        flakeIdGenerator(gen, clientConfig.getFlakeIdGeneratorConfigMap());

        //close HazelcastClient
        gen.close();

        return format(xml.toString(), indent);
    }
143167
public <Message extends PMessage<Message, Field>, Field extends PField>
    void formatTo(OutputStream out, Message message) {
        IndentedPrintWriter builder = new IndentedPrintWriter(out, indent, newline);
        if (message == null) {
            builder.append(null);
        } else {
            builder.append(message.descriptor().getQualifiedName())
                   .append(space);
            appendMessage(builder, message);
        }
        builder.flush();
    }
970887
public String format(String clientID, String name, long time, Level level, Object message,
	        Throwable t){

		if (!patternParsed && pattern != null) {
			parsePattern(pattern);
		}

		StringBuffer formattedStringBuffer = new StringBuffer(64);
		if (commandArray != null) {
			int length = commandArray.length;

			for (int index = 0; index < length; index++) {
				FormatCommandInterface currentConverter = commandArray[index];
				if (currentConverter != null) {
					formattedStringBuffer.append(currentConverter.execute(clientID, name, time,
					        level, message, t));
				}
			}
		}

		return formattedStringBuffer.toString();
	}
1043799
protected void writeMethodSignature(Writer out, int indent, MethodForConnection method) throws IOException
   {
      writeWithIndent(out, indent, "/**\n");
      writeWithIndent(out, indent, " * " + method.getMethodName());
      writeEol(out);
      for (MethodParam param : method.getParams())
      {
         writeIndent(out, indent);
         out.write(" * @param " + param.getName() + " " + param.getName());
         writeEol(out);
      }
      if (!method.getReturnType().equals("void"))
      {
         writeIndent(out, indent);
         out.write(" * @return " + method.getReturnType());
         writeEol(out);
      }
      for (String ex : method.getExceptionType())
      {
         writeIndent(out, indent);
         out.write(" * @throws " + ex + " " + ex);
         writeEol(out);
      }

      writeWithIndent(out, indent, " */\n");

      writeWithIndent(out, indent, "public " + method.getReturnType() + " " +
            method.getMethodName() + "(");
      int paramSize = method.getParams().size();
      for (int i = 0; i < paramSize; i++)
      {
         MethodParam param = method.getParams().get(i);
         out.write(param.getType());
         out.write(" ");
         out.write(param.getName());
         if (i + 1 < paramSize)
            out.write(", ");
      }
      out.write(")");
      int exceptionSize = method.getExceptionType().size();
      for (int i = 0; i < exceptionSize; i++)
      {
         if (i == 0)
            out.write(" throws ");
         String ex = method.getExceptionType().get(i);
         out.write(ex);
         if (i + 1 < exceptionSize)
            out.write(", ");
      }
   }
1157747
@Override
   public void writeXmlBody(Definition def, Writer out) throws IOException
   {
      writeConnectorVersion(out);

      int indent = 1;
      writeIndent(out, indent);
      out.write("<vendor-name>Red Hat Inc</vendor-name>");
      writeEol(out);
      writeIndent(out, indent);
      out.write("<eis-type>Test RA</eis-type>");
      writeEol(out);
      writeIndent(out, indent);
      out.write("<resourceadapter-version>0.1</resourceadapter-version>");
      writeEol(out);
      writeIndent(out, indent);
      out.write("<resourceadapter>");
      writeEol(out);

      if (def.isUseRa())
      {
         writeIndent(out, indent + 1);
         out.write("<resourceadapter-class>" + def.getRaPackage() + "." +
               def.getRaClass() + "</resourceadapter-class>");
         writeEol(out);
         writeConfigPropsXml(def.getRaConfigProps(), out, indent + 1);
      }

      if (def.isSupportOutbound())
      {
         writeOutbound(def, out, indent + 1);
      }
      if (def.isSupportInbound())
      {
         writeInbound(def, out, indent + 1);
      }

      if (def.isGenAdminObject() && def.getAdminObjects().size() > 0)
      {
         for (int i = 0; i < def.getAdminObjects().size(); i++)
         {
            writeIndent(out, indent + 1);
            out.write("<adminobject>");
            writeEol(out);
            writeIndent(out, indent + 2);
            out.write("<adminobject-interface>" + def.getRaPackage() + "." +
                  def.getAdminObjects().get(i).getAdminObjectInterface() + "</adminobject-interface>");
            writeEol(out);
            writeIndent(out, indent + 2);
            out.write("<adminobject-class>" + def.getRaPackage() + "." +
                  def.getAdminObjects().get(i).getAdminObjectClass() + "</adminobject-class>");
            writeEol(out);
            writeConfigPropsXml(def.getAdminObjects().get(i).getAoConfigProps(), out, indent + 2);
            writeIndent(out, indent + 1);
            out.write("</adminobject>");
            writeEol(out);
         }
      }

      if (def.getSecurityPermissions() != null && def.getSecurityPermissions().size() > 0)
      {
         for (int i = 0; i < def.getSecurityPermissions().size(); i++)
         {
            writeIndent(out, indent + 1);
            out.write("<security-permission>");
            writeEol(out);
            writeIndent(out, indent + 2);
            out.write("<security-permission-spec>" + def.getSecurityPermissions().get(i).getPermissionSpec() +
                  "</security-permission-spec>");
            writeEol(out);
            writeIndent(out, indent + 1);
            out.write("</security-permission>");
            writeEol(out);
         }
      }

      writeIndent(out, indent);
      out.write("</resourceadapter>");
      writeEol(out);
      out.write("</connector>");
      writeEol(out);
   }
734006
public String mkString(NumberFormat formatter, String rowsDelimiter, String columnsDelimiter) {
        // TODO: rewrite using iterators
        int[] formats = new int[columns];

        for (int i = 0; i < rows; i++) {
            for (int j = 0; j < columns; j++) {
                double value = get(i, j);
                String output = formatter.format(value);
                int size = output.length();
                formats[j] = size > formats[j] ? size : formats[j];
            }
        }

        StringBuilder sb = new StringBuilder();

        for (int i = 0; i < rows; i++) {
            for (int j = 0; j < columns; j++) {
                String output = formatter.format(get(i, j));
                int outputLength = output.length();

                if (outputLength < formats[j]) {
                    int align = formats[j] - outputLength;
                    if (align > INDENTS.length - 1) {
                        indent(sb, align);
                    } else {
                        sb.append(INDENTS[align - 1]);
                    }
                }

                sb.append(output)
                        .append(j < columns - 1 ? columnsDelimiter : "");
            }
            sb.append(rowsDelimiter);
        }

        return sb.toString();
    }
821401
@SuppressWarnings("unchecked")
    public TextFormatter<T> getFormatter(final FieldAccessor field, final Configuration config) {

        if(field.hasAnnotation(CsvFormat.class)) {
            CsvFormat formatAnno = field.getAnnotation(CsvFormat.class).get();

            final TextFormatter<T> formatter = (TextFormatter<T>) config.getBeanFactory().create(formatAnno.formatter());
            if(!formatAnno.message().isEmpty()) {
                formatter.setValidationMessage(formatAnno.message());
            }
            return formatter;

        } else {
            return getDefaultFormatter(field, config);

        }
    }
559610
public static void write(Node node, OutputStream out, String charset, int indent) {
		transform(new DOMSource(node), new StreamResult(out), charset, indent);
	}
1747
function indent(string, nchars, prefix) {
    "use strict";
    return string.split('\n').map(function(line) {
        return (prefix || '') + new Array(nchars).join(' ') + line;
    }).join('\n');
}
1313351
public static String stripFormattingfromXMLString(String xml) {
		try {
			Document document = DocumentUtilities.toDocument(xml);

			DOMImplementationRegistry registry = DOMImplementationRegistry
					.newInstance();
			DOMImplementationLS domImplementationLS = (DOMImplementationLS) registry
					.getDOMImplementation("LS");
			LSSerializer serializaer = domImplementationLS.createLSSerializer();

			serializaer.getDomConfig().setParameter("format-pretty-print",
					Boolean.FALSE);

			serializaer.getDomConfig().setParameter("xml-declaration",
					Boolean.TRUE);

			// otherwise UTF-16 is used by default
			LSOutput lsOutput = domImplementationLS.createLSOutput();
			lsOutput.setEncoding("UTF-8");
			ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
			lsOutput.setByteStream(byteStream);

			serializaer.write(document, lsOutput);

			return new String(byteStream.toByteArray(), "UTF-8");

		} catch (UnsupportedEncodingException e) {
			throw new RuntimeException(e);
		} catch (ClassNotFoundException e) {
			throw new RuntimeException(e);
		} catch (InstantiationException e) {
			throw new RuntimeException(e);
		} catch (IllegalAccessException e) {
			throw new RuntimeException(e);
		} catch (ClassCastException e) {
			throw new RuntimeException(e);
		}
	}
824435
public static String escapeXML(final char[] chars, final int offset, final int length) {
        final StringBuilder escaped = new StringBuilder();

        final int end = offset + length;
        for (int i = offset; i < end; ++i) {
            final char c = chars[i];

            switch (c) {
            case '\'':
                escaped.append("&apos;");
                break;
            case '\"':
                escaped.append("&quot;");
                break;
            case '<':
                escaped.append("&lt;");
                break;
            case '>':
                escaped.append("&gt;");
                break;
            case '&':
                escaped.append("&amp;");
                break;
            default:
                escaped.append(c);
            }
        }

        return escaped.toString();
    }
59929
@Override
    public String convert(String content) {
        StringWriter writer = new StringWriter();
        HtmlDocumentBuilder builder = new HtmlDocumentBuilder(writer);
        builder.setEmitAsDocument(false);
        parser.setBuilder(builder);

        parser.parse(content);
        parser.setBuilder(null);
        return writer.toString();
    }
434381
private static String escapeXml (String nonEscapedXmlStr) {
        StringBuilder escapedXML = new StringBuilder();
        for (int i = 0; i < nonEscapedXmlStr.length(); i++) {
            char c = nonEscapedXmlStr.charAt(i);
            switch (c) {
                case '<':
                    escapedXML.append("&lt;");
                    break;
                case '>':
                    escapedXML.append("&gt;");
                    break;
                case '\"':
                    escapedXML.append("&quot;");
                    break;
                case '&':
                    escapedXML.append("&amp;");
                    break;
                case '\'':
                    escapedXML.append("&apos;");
                    break;
                default:
                    if (c > 0x7e) {
                        escapedXML.append("&#" + ((int) c) + ";");
                    } else {
                        escapedXML.append(c);
                    }
            }
        }
        return escapedXML.toString();
    }
572141
public static XMLStreamWriter getIndentingXmlStreamWriter(Writer writer) throws XMLStreamException, IOException {
        XMLOutputFactory f = XMLOutputFactory.newInstance();
        return new IndentingXMLStreamWriter(f.createXMLStreamWriter(writer));
    }
917718
private Transformer createIndentingTransformer() throws TransformerConfigurationException {
        Transformer transformer = createTransformer();
        transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
        transformer.setOutputProperty(OutputKeys.INDENT, "yes");
        return transformer;
    }
746291
public static String xmlAttribEncode(final String attrValue) {
    final StringBuffer buf = new StringBuffer(attrValue);
    int quotePos;

    for (quotePos = -1; (quotePos = buf.indexOf("\"", quotePos + 1)) >= 0;) {
      buf.deleteCharAt(quotePos);
      buf.insert(quotePos, "&quot;");
      quotePos += 5;
    }

    for (quotePos = -1; (quotePos = buf.indexOf("<", quotePos + 1)) >= 0;) {
      buf.deleteCharAt(quotePos);
      buf.insert(quotePos, "&lt;");
      quotePos += 3;
    }

    for (quotePos = -1; (quotePos = buf.indexOf(">", quotePos + 1)) >= 0;) {
      buf.deleteCharAt(quotePos);
      buf.insert(quotePos, "&gt;");
      quotePos += 3;
    }

    return buf.toString();
  }
909555
static public String encode(byte[] bytes, String indentation) {
        StringBuilder result = new StringBuilder();
        int length = bytes.length;
        if (length == 0) return "";  // empty byte array
        if (indentation != null) result.append(indentation);
        encodeBytes(bytes[0], bytes[0], 0, result);
        for (int i = 1; i < length; i++) {
            if (i % 50 == 0) {
                // format to indented 80 character blocks
                result.append("\n");
                if (indentation != null) result.append(indentation);
            }
            encodeBytes(bytes[i - 1], bytes[i], i, result);
        }
        encodeLastByte(bytes[length - 1], length - 1, result);
        return result.toString();
    }