public boolean isEmpty() { return getByteLength() == 0; }
/** * Wraps the utf8 sequence in a ByteBuffer * @return The wrapping buffer. */ public ByteBuffer wrap() { return ByteBuffer.wrap(getBytes(), getByteOffset(), getByteLength()); }
/** * This will write the utf8 sequence to the given target. */ final public void writeTo(ByteBuffer target) { target.put(getBytes(), getByteOffset(), getByteLength()); }
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); }
@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
@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; } }
/** * 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(); }
/** * Will convert the utf8 sequence to a Java string * @return The converted Java String */ @Override public String toString() { return Utf8.toString(getBytes(), getByteOffset(), getByteLength()); }
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 {