/** * Appends the specified character onto this CharWrap. * * @param c * The character to be appended. * @return A reference to this CharWrap. */ public CharWrap append(char c) { ensureCapacity(size + 1); storage[size + offset] = c; size++; return this; }
/** * Appends the specified character data onto this CharWrap. * * @param array * The array holding the character data to be appended. * @param start * The offset within the array of the beginning of the character * data. * @param length * The length of the character data. * @return A reference to this CharWrap. */ public CharWrap append(char[] array, int start, int length) { ensureCapacity(size + length); System.arraycopy(array, start, storage, size + offset, length); size += length; return this; }
/** * Appends the characters in the supplied string onto this CharWrap. * * @param s * A String holding the character data to be appended. * @return A reference to this CharWrap. */ public final CharWrap append(String s) { if (s == null) s = "null"; int length = s.length(); ensureCapacity(size + length); int start = size + offset; if (length < 8) { // breakeven point optimised for JDK 1.4.2 for (int i = length - 1; i >= 0; --i) { storage[start + i] = s.charAt(i); } } else { s.getChars(0, length, storage, size + offset); } size += length; return this; }
case '&': svb.append("&"); svb.ensureCapacity(svb.size + i); break; case '<': svb.append("<"); svb.ensureCapacity(svb.size + i); break; case '>': svb.append(">"); svb.ensureCapacity(svb.size + i); break; case '"': svb.append("""); svb.ensureCapacity(svb.size + i); break; svb.ensureCapacity(svb.size + i); break; default:
public final void writeSlow(char[] towrite, int start, int length) { // AMAZINGLY, in 1.5 it is quicker to create this here than economise it. CharWrap svb = new CharWrap(length + 10); int limit = start + length; for (int i = length; i > 0; --i) { char c = towrite[limit - i]; switch (c) { case '"': case '\\': case '/': svb.append('\\'); svb.append(c); svb.ensureCapacity(svb.size + i); break; default: svb.appendFast(c); } } internalwriter.write(svb.storage, svb.offset, svb.size); } }
public Object parse(String toparse) { PushbackRIS lr = new PushbackRIS(new StringRIS(toparse)); int size = LexUtil.readInt(lr); if (size > toparse.length() / 2) { throw UniversalRuntimeException.accumulate(new IllegalArgumentException(), "Possible DOS attack! Impossibly long string array encoded"); } String[] togo = new String[size]; LexUtil.expect(lr, ":"); CharWrap readbuffer = new CharWrap(); for (int i = 0; i < size; ++i) { try { int length = LexUtil.readInt(lr); if (size > toparse.length()) { throw UniversalRuntimeException.accumulate(new IllegalArgumentException(), "Possible DOS attack! Impossibly long string encoded"); } LexUtil.expect(lr, ":"); readbuffer.ensureCapacity(length); lr.read(readbuffer.storage, 0, length); togo[i] = new String(readbuffer.storage, 0, length); } catch (Exception e) { throw UniversalRuntimeException.accumulate(e, "Error reading integer vector at position " + i + " of expected " + size); } } return togo; }