/** * Writes the given string. If markup is us ascii (default), and the wrapped writer encodes in UTF, this will write * the string <b>as is, with no transcoding</b> (for speed). Hence, this should never be used for just any content. * * @return this for consistency */ private final XMLWriter w(String s) { return markupIsAscii ? w(new Utf8String(s)) : w(s); }
public Utf8Array ascii7BitLowerCase() { byte [] upper = new byte[getByteLength()]; for (int i=0; i< upper.length; i++ ) { byte b = getByte(i); if ((b >= 0x41) && (b < (0x41+26))) { b |= 0x20; // Lowercase } upper[i] = b; } return new Utf8Array(upper); }
public static Encoder newEncoder(Charset charset, int... requiresEscape) { switch (requiresEscape.length) { case 0: return new Encoder(charset, new EmptyPredicate()); case 1: return new Encoder(charset, new SingletonPredicate(requiresEscape[0])); default: return new Encoder(charset, new ArrayPredicate(requiresEscape)); } }
private static boolean verifyFirst(byte c, byte [] identifier) { if (!((c == '_') || ((c >= 'a') && (c <= 'z')))) { throw new IllegalArgumentException("Illegal starting character '" + (char)c + "' of identifier '" + new Utf8String(new Utf8Array(identifier)).toString() +"'."); } return true; } private static boolean verifyAny(byte c, byte [] identifier) {
/** * Will convert the utf8 sequence to a Java string * @return The converted Java String */ @Override public String toString() { return Utf8.toString(getBytes(), getByteOffset(), getByteLength()); }
private DataTypeIdentifier(final byte [] prefix, DataTypeIdentifier nested, final byte [] postfix) { utf8 = new Utf8String(new Utf8Array(createPrefixDataType(prefix, nested, postfix))); } private DataTypeIdentifier(final byte [] prefix, DataTypeIdentifier key, DataTypeIdentifier value) {
private DataTypeIdentifier(final byte [] prefix, DataTypeIdentifier key, DataTypeIdentifier value) { utf8 = new Utf8String(new Utf8Array(createMapDataType(prefix, key, value))); }
public XMLWriter openTag(String s) { return openTag(new Utf8String(s)); } public XMLWriter openTag(Utf8String tag) {
public DataTypeIdentifier(AbstractUtf8Array utf8) { this.utf8 = new Utf8String(utf8); verify(utf8.wrap().array()); } public DataTypeIdentifier(byte [] utf8) {
public XMLWriter forceAttribute(String name, Object value) { return forceAttribute(new Utf8String(name), value); }
/** * Creates a new routing table specification for a named protocol. * * @param protocol The name of the protocol that this belongs to. */ public RoutingTableSpec(Utf8String protocol) { this(protocol.toString(), true); }
/** * Writes an attribute by its utf8 value * * @param name the name of the attribute. An exception is thrown if this is null * @param value the value of the attribute. This method does nothing if the value is null or empty */ public XMLWriter attribute(Utf8String name, AbstractUtf8Array value) { if (value.isEmpty()) return this; allowAttribute(); return w(SPACE).w(name).w(ATTRIBUTE_START).w(value).w(ATTRIBUTE_END); }
public static String encode(String str, Charset charset, int... requiresEscape) { return newEncoder(charset, requiresEscape).encode(str); }
@Override public boolean equals(Object obj) { if (!(obj instanceof DataTypeName)) return false; DataTypeName datatype = (DataTypeName)obj; return this.name.equals(datatype.name); }
public String encode(String str) { StringBuilder out = new StringBuilder(); for (int c : new CodePointSequence(str)) { if (c < 0x20 || c >= 0x7F || c == ESCAPE_CHAR || predicate.requiresEscape(c)) { escape(c, out); } else { out.appendCodePoint(c); } } return out.toString(); }
public CaseInsensitiveIdentifier(AbstractUtf8Array utf8) { super(utf8.ascii7BitLowerCase()); original = new Identifier(utf8); } public String toString() { return original.toString(); }
/** * Encode a valid Unicode codepoint as a sequence of UTF-8 bytes into a new allocated array. * * @param codepoint Unicode codepoint to encode * @return number of bytes written * @throws IndexOutOfBoundsException if there is insufficient room for the encoded data in the given array */ public static byte[] encode(int codepoint) { byte[] destination = new byte[codePointAsUtf8Length(codepoint)]; encode(codepoint, destination, 0); return destination; }
/** * Writes an attribute by its utf8 value * * @param name the name of the attribute. An exception is thrown if this is null * @param value the value of the attribute. */ public XMLWriter attribute(Utf8String name, long value) { allowAttribute(); return w(SPACE).w(name).w(ATTRIBUTE_START).w(value).w(ATTRIBUTE_END); }
/** * Creates a new XML DocumentBuilder * * @return a DocumentBuilder * @throws RuntimeException if we fail to create one */ public static DocumentBuilder getDocumentBuilder() { return getDocumentBuilder("com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl", null); }