@Override public int hashCode() { final int l = getByteLength(); final int c = getByteOffset(); final byte [] b = getBytes(); int h = 0; for (int i=0; i < l; i++) { int v = b[c+i]; h ^= v << ((i%4)*8); } return h; } @Override
/** * This will create a string based on the utf8 sequence. * @param utf8 The backing array */ public Utf8String(AbstractUtf8Array utf8) { super(utf8.getBytes(), utf8.getByteOffset(), utf8.getByteLength()); s = utf8.toString(); }
/** * This will return the byte at the given position. */ public byte getByte(int index) { return getBytes()[getByteOffset() + index]; }
public void append(AbstractUtf8Array v) throws IOException { final int length = v.getByteLength(); if (shouldCopy(length)) { makeRoom(length); v.writeTo(current); } else { append(v.wrap()); } } public void append(final byte[] alreadyEncoded) throws java.io.IOException {
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 Identifier(AbstractUtf8Array utf8) { this(utf8.getBytes()); } public Identifier(byte [] utf8) {
public boolean isEmpty() { return getByteLength() == 0; }
public CaseInsensitiveIdentifier(AbstractUtf8Array utf8) { super(utf8.ascii7BitLowerCase()); original = new Identifier(utf8); } public String toString() { return original.toString(); }
public GenericWriter write(AbstractUtf8Array v) throws java.io.IOException { write(v.toString()); return this; } }
public DataTypeIdentifier(AbstractUtf8Array utf8) { this.utf8 = new Utf8String(utf8); verify(utf8.wrap().array()); } public DataTypeIdentifier(byte [] utf8) {
/** * 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 LowercaseIdentifier(AbstractUtf8Array utf8) { this(utf8.getBytes()); } public LowercaseIdentifier(byte [] utf8) {
/** * This will write the utf8 sequence to the given target. */ final public void writeTo(ByteBuffer target) { target.put(getBytes(), getByteOffset(), getByteLength()); }
/** * Wraps the utf8 sequence in a ByteBuffer * @return The wrapping buffer. */ public ByteBuffer wrap() { return ByteBuffer.wrap(getBytes(), getByteOffset(), getByteLength()); }
@Override public int compareTo(AbstractUtf8Array rhs) { final int l = getByteLength(); final int rl = rhs.getByteLength(); if (l < rl) { return -1; } else if (l > rl) { return 1; } else { final byte [] b = getBytes(); final byte [] rb = rhs.getBytes(); final int c = getByteOffset(); final int rc = rhs.getByteOffset(); for (int i=0; i < l; i++) { if (b[c+i] < rb[rc+i]) { return -1; } else if (b[c+i] > rb[rc+i]) { return 1; } } return 0; } }
/** * Will convert the utf8 sequence to a Java string * @return The converted Java String */ @Override public String toString() { return Utf8.toString(getBytes(), getByteOffset(), getByteLength()); }