mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

Jean-Noël Rouvignac
28.11.2015 0364afd608de95af991df681c3f952467b7c67ad
OPENDJ-1802 Make ByteStringBuilder methods more intentional

ByteStringBuilder.java:
Changed:
- append(byte) to appendByte(int)
- append(short) to appendShort(int)
- append(int) to appendInt(int)
- append(long) to appendLong(long)
- append(Object) to appendObject(Object)
- append(String) to appendUtf8(String)
- append(char[]) to appendUtf8(char[])
- All remaining append() to appendBytes().
I changed appendByte() and appendShort() to accept int parameters.
This avoids continuously casting, at the expense of a possible loss of the high bits.
24 files modified
515 ■■■■ changed files
opendj-sdk/opendj-core/clirr-ignored-api-changes.xml 20 ●●●●● patch | view | raw | blame | history
opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/io/ASN1ByteSequenceReader.java 2 ●●● patch | view | raw | blame | history
opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/io/ASN1InputStreamReader.java 2 ●●● patch | view | raw | blame | history
opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/AVA.java 10 ●●●● patch | view | raw | blame | history
opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/Base64.java 12 ●●●● patch | view | raw | blame | history
opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/ByteString.java 5 ●●●● patch | view | raw | blame | history
opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/ByteStringBuilder.java 107 ●●●●● patch | view | raw | blame | history
opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/DN.java 2 ●●● patch | view | raw | blame | history
opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/Filter.java 4 ●●●● patch | view | raw | blame | history
opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/RDN.java 4 ●●●● patch | view | raw | blame | history
opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/AbstractSubstringMatchingRuleImpl.java 19 ●●●● patch | view | raw | blame | history
opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/CertificateExactMatchingRuleImpl.java 27 ●●●● patch | view | raw | blame | history
opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/IntegerOrderingMatchingRuleImpl.java 32 ●●●● patch | view | raw | blame | history
opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/TimeBasedMatchingRulesImpl.java 6 ●●●● patch | view | raw | blame | history
opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/UUIDEqualityMatchingRuleImpl.java 2 ●●● patch | view | raw | blame | history
opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/UniqueMemberEqualityMatchingRuleImpl.java 4 ●●●● patch | view | raw | blame | history
opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldif/AbstractLDIFReader.java 2 ●●● patch | view | raw | blame | history
opendj-sdk/opendj-core/src/test/java/org/forgerock/opendj/io/ASN1ReaderTestCase.java 22 ●●●● patch | view | raw | blame | history
opendj-sdk/opendj-core/src/test/java/org/forgerock/opendj/ldap/ByteSequenceReaderTest.java 6 ●●●● patch | view | raw | blame | history
opendj-sdk/opendj-core/src/test/java/org/forgerock/opendj/ldap/ByteStringBuilderTestCase.java 78 ●●●● patch | view | raw | blame | history
opendj-sdk/opendj-core/src/test/java/org/forgerock/opendj/ldap/ByteStringTestCase.java 12 ●●●● patch | view | raw | blame | history
opendj-sdk/opendj-core/src/test/java/org/forgerock/opendj/ldap/schema/IntegerOrderingMatchingRuleTest.java 2 ●●● patch | view | raw | blame | history
opendj-sdk/opendj-grizzly/src/main/java/org/forgerock/opendj/grizzly/ASN1BufferReader.java 8 ●●●●● patch | view | raw | blame | history
opendj-sdk/opendj-grizzly/src/main/java/org/forgerock/opendj/grizzly/ASN1BufferWriter.java 127 ●●●● patch | view | raw | blame | history
opendj-sdk/opendj-core/clirr-ignored-api-changes.xml
@@ -510,4 +510,24 @@
    <differenceType>8001</differenceType>
    <justification>OPENDJ-1654: LDAPOptions should be converted in a SchemaOptions style API</justification>
  </difference>
  <difference>
    <className>org/forgerock/opendj/ldap/ByteStringBuilder</className>
    <differenceType>7002</differenceType>
    <method>%regex[(org\.forgerock\.opendj\.ldap\.ByteStringBuilder|int) append\(.*\)]</method>
    <justification>OPENDJ-1802 ByteStringBuilder.append() => appendByte(), appendShort(), appendInt(), appendLong(), appendBytes(), appendObject()</justification>
  </difference>
  <difference>
    <className>org/forgerock/opendj/ldap/ByteStringBuilder</className>
    <differenceType>7004</differenceType>
    <method>org.forgerock.opendj.ldap.ByteStringBuilder append(byte)</method>
    <to>org.forgerock.opendj.ldap.ByteStringBuilder appendByte(int)</to>
    <justification>OPENDJ-1802 Consider making ByteString / ByteStringBuilder methods more intentional</justification>
  </difference>
  <difference>
    <className>org/forgerock/opendj/ldap/ByteStringBuilder</className>
    <differenceType>7006</differenceType>
    <method>org.forgerock.opendj.ldap.ByteStringBuilder append(byte)</method>
    <to>void</to>
    <justification>OPENDJ-1802 Consider making ByteString / ByteStringBuilder methods more intentional</justification>
  </difference>
</differences>
opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/io/ASN1ByteSequenceReader.java
@@ -259,7 +259,7 @@
                    ERR_ASN1_OCTET_STRING_TRUNCATED_VALUE.get(peekLength);
            throw DecodeException.fatalError(message);
        }
        builder.append(reader, peekLength);
        builder.appendBytes(reader, peekLength);
        state = ASN1.ELEMENT_READ_STATE_NEED_TYPE;
        return builder;
opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/io/ASN1InputStreamReader.java
@@ -309,7 +309,7 @@
        int bytesNeeded = peekLength;
        int bytesRead;
        while (bytesNeeded > 0) {
            bytesRead = builder.append(in, bytesNeeded);
            bytesRead = builder.appendBytes(in, bytesNeeded);
            if (bytesRead < 0) {
                final LocalizableMessage message =
                        ERR_ASN1_OCTET_STRING_TRUNCATED_VALUE.get(peekLength);
opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/AVA.java
@@ -802,11 +802,11 @@
     * @see DN#toNormalizedByteString()
     */
    ByteStringBuilder toNormalizedByteString(final ByteStringBuilder builder) {
        builder.append(toLowerCase(attributeType.getNameOrOID()));
        builder.append("=");
        builder.appendUtf8(toLowerCase(attributeType.getNameOrOID()));
        builder.appendUtf8("=");
        final ByteString value = getEqualityNormalizedValue();
        if (value.length() > 0) {
            builder.append(escapeBytes(value));
            builder.appendBytes(escapeBytes(value));
        }
        return builder;
    }
@@ -871,9 +871,9 @@
        for (int i = 0; i < value.length(); i++) {
            final byte b = value.byteAt(i);
            if (isByteToEscape(b)) {
                builder.append(DN.NORMALIZED_ESC_BYTE);
                builder.appendByte(DN.NORMALIZED_ESC_BYTE);
            }
            builder.append(b);
            builder.appendByte(b);
        }
        return builder.toByteString();
    }
opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/Base64.java
@@ -277,11 +277,11 @@
                    append = false;
                    switch (j) {
                    case 2:
                        builder.append((byte) ((value >>> 4) & 0xFF));
                        builder.appendByte(value >>> 4 & 0xFF);
                        break;
                    case 3:
                        builder.append((byte) ((value >>> 10) & 0xFF));
                        builder.append((byte) ((value >>> 2) & 0xFF));
                        builder.appendByte(value >>> 10 & 0xFF);
                        builder.appendByte(value >>> 2 & 0xFF);
                        break;
                    }
                    break;
@@ -297,9 +297,9 @@
            }
            if (append) {
                builder.append((byte) ((value >>> 16) & 0xFF));
                builder.append((byte) ((value >>> 8) & 0xFF));
                builder.append((byte) (value & 0xFF));
                builder.appendByte(value >>> 16 & 0xFF);
                builder.appendByte(value >>> 8 & 0xFF);
                builder.appendByte(value & 0xFF);
            } else {
                break;
            }
opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/ByteString.java
@@ -678,22 +678,19 @@
        return bytes;
    }
    /** {@inheritDoc} */
    @Override
    public ByteBuffer copyTo(final ByteBuffer byteBuffer) {
        byteBuffer.put(buffer, offset, length);
        return byteBuffer;
    }
    /** {@inheritDoc} */
    @Override
    public ByteStringBuilder copyTo(final ByteStringBuilder builder) {
        builder.append(buffer, offset, length);
        builder.appendBytes(buffer, offset, length);
        return builder;
    }
    /** {@inheritDoc} */
    @Override
    public boolean copyTo(CharBuffer charBuffer, CharsetDecoder decoder) {
        return copyTo(ByteBuffer.wrap(buffer, offset, length), charBuffer, decoder);
opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/ByteStringBuilder.java
@@ -42,9 +42,7 @@
import com.forgerock.opendj.util.PackedLong;
/**
 * A mutable sequence of bytes backed by a byte array.
 */
/** A mutable sequence of bytes backed by a byte array. */
public final class ByteStringBuilder implements ByteSequence {
    /** Maximum size in bytes of a compact encoded value. */
@@ -59,17 +57,17 @@
        @Override
        public void write(final byte[] bytes) {
            append(bytes);
            appendBytes(bytes);
        }
        @Override
        public void write(final byte[] bytes, final int i, final int i1) {
            append(bytes, i, i1);
            appendBytes(bytes, i, i1);
        }
        @Override
        public void write(final int i) {
            append((byte) (i & 0xFF));
            appendByte(i & 0xFF);
        }
    }
@@ -99,13 +97,11 @@
            this.subLength = length;
        }
        /** {@inheritDoc} */
        @Override
        public ByteSequenceReader asReader() {
            return new ByteSequenceReader(this);
        }
        /** {@inheritDoc} */
        @Override
        public byte byteAt(final int index) {
            if (index >= subLength || index < 0) {
@@ -116,7 +112,6 @@
            return buffer[subOffset + index];
        }
        /** {@inheritDoc} */
        @Override
        public int compareTo(final byte[] b, final int offset, final int length) {
            ByteString.checkArrayBounds(b, offset, length);
@@ -125,7 +120,6 @@
            return ByteString.compareTo(buffer, subOffset, subLength, b, offset, length);
        }
        /** {@inheritDoc} */
        @Override
        public int compareTo(final ByteSequence o) {
            if (this == o) {
@@ -136,14 +130,12 @@
            return -o.compareTo(buffer, subOffset, subLength);
        }
        /** {@inheritDoc} */
        @Override
        public byte[] copyTo(final byte[] b) {
            copyTo(b, 0);
            return b;
        }
        /** {@inheritDoc} */
        @Override
        public byte[] copyTo(final byte[] b, final int offset) {
            if (offset < 0) {
@@ -155,27 +147,23 @@
            return b;
        }
        /** {@inheritDoc} */
        @Override
        public ByteBuffer copyTo(final ByteBuffer byteBuffer) {
            byteBuffer.put(buffer, subOffset, subLength);
            return byteBuffer;
        }
        /** {@inheritDoc} */
        @Override
        public ByteStringBuilder copyTo(final ByteStringBuilder builder) {
            // Protect against reallocation: use builder's buffer.
            return builder.append(buffer, subOffset, subLength);
            return builder.appendBytes(buffer, subOffset, subLength);
        }
        /** {@inheritDoc} */
        @Override
        public boolean copyTo(CharBuffer charBuffer, CharsetDecoder decoder) {
            return ByteString.copyTo(ByteBuffer.wrap(buffer, subOffset, subLength), charBuffer, decoder);
        }
        /** {@inheritDoc} */
        @Override
        public OutputStream copyTo(final OutputStream stream) throws IOException {
            // Protect against reallocation: use builder's buffer.
@@ -183,7 +171,6 @@
            return stream;
        }
        /** {@inheritDoc} */
        @Override
        public boolean equals(final byte[] b, final int offset, final int length) {
            ByteString.checkArrayBounds(b, offset, length);
@@ -192,7 +179,6 @@
            return ByteString.equals(buffer, subOffset, subLength, b, offset, length);
        }
        /** {@inheritDoc} */
        @Override
        public boolean equals(final Object o) {
            if (this == o) {
@@ -207,7 +193,6 @@
            }
        }
        /** {@inheritDoc} */
        @Override
        public int hashCode() {
            // Protect against reallocation: use builder's buffer.
@@ -219,13 +204,11 @@
            return length == 0;
        }
        /** {@inheritDoc} */
        @Override
        public int length() {
            return subLength;
        }
        /** {@inheritDoc} */
        @Override
        public ByteSequence subSequence(final int start, final int end) {
            if (start < 0 || start > end || end > subLength) {
@@ -235,7 +218,6 @@
            return new SubSequence(subOffset + start, end - start);
        }
        /** {@inheritDoc} */
        @Override
        public boolean startsWith(ByteSequence prefix) {
            if (prefix == null || prefix.length() > length) {
@@ -244,19 +226,16 @@
            return prefix.equals(buffer, 0, prefix.length());
        }
        /** {@inheritDoc} */
        @Override
        public String toBase64String() {
            return Base64.encode(this);
        }
        /** {@inheritDoc} */
        @Override
        public byte[] toByteArray() {
            return copyTo(new byte[subLength]);
        }
        /** {@inheritDoc} */
        @Override
        public ByteString toByteString() {
            // Protect against reallocation: use builder's buffer.
@@ -265,7 +244,6 @@
            return ByteString.wrap(b);
        }
        /** {@inheritDoc} */
        @Override
        public String toString() {
            // Protect against reallocation: use builder's buffer.
@@ -289,9 +267,7 @@
     */
    private OutputStreamImpl os;
    /**
     * Creates a new byte string builder with an initial capacity of 32 bytes.
     */
    /** Creates a new byte string builder with an initial capacity of 32 bytes. */
    public ByteStringBuilder() {
        // Initially create a 32 byte buffer.
        this(32);
@@ -331,9 +307,9 @@
     *            The byte to be appended to this byte string builder.
     * @return This byte string builder.
     */
    public ByteStringBuilder append(final byte b) {
    public ByteStringBuilder appendByte(final int b) {
        ensureAdditionalCapacity(1);
        buffer[length++] = b;
        buffer[length++] = (byte) b;
        return this;
    }
@@ -356,8 +332,8 @@
     *            The byte array to be appended to this byte string builder.
     * @return This byte string builder.
     */
    public ByteStringBuilder append(final byte[] bytes) {
        return append(bytes, 0, bytes.length);
    public ByteStringBuilder appendBytes(final byte[] bytes) {
        return appendBytes(bytes, 0, bytes.length);
    }
    /**
@@ -377,7 +353,7 @@
     *             negative or if {@code offset + length} is greater than
     *             {@code bytes.length}.
     */
    public ByteStringBuilder append(final byte[] bytes, final int offset, final int length) {
    public ByteStringBuilder appendBytes(final byte[] bytes, final int offset, final int length) {
        ByteString.checkArrayBounds(bytes, offset, length);
        if (length != 0) {
@@ -401,7 +377,7 @@
     *             If {@code length} is less than zero or greater than
     *             {@code buffer.remaining()}.
     */
    public ByteStringBuilder append(final ByteBuffer buffer, final int length) {
    public ByteStringBuilder appendBytes(final ByteBuffer buffer, final int length) {
        if (length < 0 || length > buffer.remaining()) {
            throw new IndexOutOfBoundsException();
        }
@@ -422,13 +398,12 @@
     *            The byte sequence to be appended to this byte string builder.
     * @return This byte string builder.
     */
    public ByteStringBuilder append(final ByteSequence bytes) {
    public ByteStringBuilder appendBytes(final ByteSequence bytes) {
        return bytes.copyTo(this);
    }
    /**
     * Appends the provided {@link ByteSequenceReader} to this byte string
     * builder.
     * Appends the provided {@link ByteSequenceReader} to this byte string builder.
     *
     * @param reader
     *            The byte sequence reader to be appended to this byte string
@@ -440,7 +415,7 @@
     *             If {@code length} is less than zero or greater than
     *             {@code reader.remaining()}.
     */
    public ByteStringBuilder append(final ByteSequenceReader reader, final int length) {
    public ByteStringBuilder appendBytes(final ByteSequenceReader reader, final int length) {
        if (length < 0 || length > reader.remaining()) {
            throw new IndexOutOfBoundsException();
        }
@@ -463,7 +438,7 @@
     *            byte string builder.
     * @return This byte string builder.
     */
    public ByteStringBuilder append(final char[] chars) {
    public ByteStringBuilder appendUtf8(final char[] chars) {
        if (chars == null) {
            return this;
        }
@@ -512,7 +487,7 @@
     * @throws IOException
     *           If an I/O error occurs.
     */
    public void append(DataInput stream, int length) throws EOFException, IOException {
    public void appendBytes(DataInput stream, int length) throws EOFException, IOException {
        if (length < 0) {
            throw new IndexOutOfBoundsException();
        }
@@ -537,7 +512,7 @@
     * @throws IOException
     *             If an I/O error occurs.
     */
    public int append(final InputStream stream, final int length) throws IOException {
    public int appendBytes(final InputStream stream, final int length) throws IOException {
        if (length < 0) {
            throw new IndexOutOfBoundsException();
        }
@@ -560,7 +535,7 @@
     *            this byte string builder.
     * @return This byte string builder.
     */
    public ByteStringBuilder append(int i) {
    public ByteStringBuilder appendInt(int i) {
        ensureAdditionalCapacity(4);
        for (int j = length + 3; j >= length; j--) {
            buffer[j] = (byte) (i & 0xFF);
@@ -579,7 +554,7 @@
     *            byte string builder.
     * @return This byte string builder.
     */
    public ByteStringBuilder append(long l) {
    public ByteStringBuilder appendLong(long l) {
        ensureAdditionalCapacity(8);
        for (int i = length + 7; i >= length; i--) {
            buffer[i] = (byte) (l & 0xFF);
@@ -615,13 +590,13 @@
     * byte string builder. The object is converted to a byte string as follows:
     * <ul>
     * <li>if the object is an instance of {@code ByteSequence} then this method
     * is equivalent to calling {@link #append(ByteSequence)}
     * is equivalent to calling {@link #appendBytes(ByteSequence)}
     * <li>if the object is a {@code byte[]} then this method is equivalent to
     * calling {@link #append(byte[])}
     * calling {@link #appendBytes(byte[])}
     * <li>if the object is a {@code char[]} then this method is equivalent to
     * calling {@link #append(char[])}
     * calling {@link #appendUtf8(char[])}
     * <li>for all other types of object this method is equivalent to calling
     * {@link #append(String)} with the {@code toString()} representation of the
     * {@link #appendUtf8(String)} with the {@code toString()} representation of the
     * provided object.
     * </ul>
     * <b>Note:</b> this method treats {@code Long} and {@code Integer} objects
@@ -636,17 +611,17 @@
     *            The object to be appended to this byte string builder.
     * @return This byte string builder.
     */
    public ByteStringBuilder append(final Object o) {
    public ByteStringBuilder appendObject(final Object o) {
        if (o == null) {
            return this;
        } else if (o instanceof ByteSequence) {
            return append((ByteSequence) o);
            return appendBytes((ByteSequence) o);
        } else if (o instanceof byte[]) {
            return append((byte[]) o);
            return appendBytes((byte[]) o);
        } else if (o instanceof char[]) {
            return append((char[]) o);
            return appendUtf8((char[]) o);
        } else {
            return append(o.toString());
            return appendUtf8(o.toString());
        }
    }
@@ -659,7 +634,7 @@
     *            byte string builder.
     * @return This byte string builder.
     */
    public ByteStringBuilder append(short i) {
    public ByteStringBuilder appendShort(int i) {
        ensureAdditionalCapacity(2);
        for (int j = length + 1; j >= length; j--) {
            buffer[j] = (byte) (i & 0xFF);
@@ -678,7 +653,7 @@
     *            string builder.
     * @return This byte string builder.
     */
    public ByteStringBuilder append(final String s) {
    public ByteStringBuilder appendUtf8(final String s) {
        if (s == null) {
            return this;
        }
@@ -696,7 +671,7 @@
            } else {
                // There is a multi-byte char. Defer to JDK
                try {
                    return append(s.getBytes("UTF-8"));
                    return appendBytes(s.getBytes("UTF-8"));
                } catch (final UnsupportedEncodingException e) {
                    // TODO: I18N
                    throw new RuntimeException("Unable to encode String '" + s + "' to UTF-8 bytes", e);
@@ -786,7 +761,6 @@
        return new ByteSequenceReader(this);
    }
    /** {@inheritDoc} */
    @Override
    public byte byteAt(final int index) {
        if (index >= length || index < 0) {
@@ -854,14 +828,12 @@
        return this;
    }
    /** {@inheritDoc} */
    @Override
    public int compareTo(final byte[] bytes, final int offset, final int length) {
        ByteString.checkArrayBounds(bytes, offset, length);
        return ByteString.compareTo(this.buffer, 0, this.length, bytes, offset, length);
    }
    /** {@inheritDoc} */
    @Override
    public int compareTo(final ByteSequence o) {
        if (this == o) {
@@ -870,14 +842,12 @@
        return -o.compareTo(buffer, 0, length);
    }
    /** {@inheritDoc} */
    @Override
    public byte[] copyTo(final byte[] bytes) {
        copyTo(bytes, 0);
        return bytes;
    }
    /** {@inheritDoc} */
    @Override
    public byte[] copyTo(final byte[] bytes, final int offset) {
        if (offset < 0) {
@@ -887,27 +857,23 @@
        return bytes;
    }
    /** {@inheritDoc} */
    @Override
    public ByteBuffer copyTo(final ByteBuffer byteBuffer) {
        byteBuffer.put(buffer, 0, length);
        return byteBuffer;
    }
    /** {@inheritDoc} */
    @Override
    public ByteStringBuilder copyTo(final ByteStringBuilder builder) {
        builder.append(buffer, 0, length);
        builder.appendBytes(buffer, 0, length);
        return builder;
    }
    /** {@inheritDoc} */
    @Override
    public boolean copyTo(CharBuffer charBuffer, CharsetDecoder decoder) {
        return ByteString.copyTo(ByteBuffer.wrap(buffer, 0, length), charBuffer, decoder);
    }
    /** {@inheritDoc} */
    @Override
    public OutputStream copyTo(final OutputStream stream) throws IOException {
        stream.write(buffer, 0, length);
@@ -947,7 +913,6 @@
        return this;
    }
    /** {@inheritDoc} */
    @Override
    public boolean equals(final byte[] bytes, final int offset, final int length) {
        ByteString.checkArrayBounds(bytes, offset, length);
@@ -1010,13 +975,11 @@
        return ByteString.hashCode(buffer, 0, length);
    }
    /** {@inheritDoc} */
    @Override
    public boolean isEmpty() {
        return length == 0;
    }
    /** {@inheritDoc} */
    @Override
    public int length() {
        return length;
@@ -1110,7 +1073,6 @@
        return new SubSequence(start, end - start);
    }
    /** {@inheritDoc} */
    @Override
    public boolean startsWith(ByteSequence prefix) {
        if (prefix == null || prefix.length() > length) {
@@ -1119,13 +1081,11 @@
        return prefix.equals(buffer, 0, prefix.length());
    }
    /** {@inheritDoc} */
    @Override
    public String toBase64String() {
        return Base64.encode(this);
    }
    /** {@inheritDoc} */
    @Override
    public byte[] toByteArray() {
        return copyTo(new byte[length]);
@@ -1145,7 +1105,6 @@
        return ByteString.wrap(b);
    }
    /** {@inheritDoc} */
    @Override
    public String toString() {
        return ByteString.toString(buffer, 0, length);
opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/DN.java
@@ -901,7 +901,7 @@
                    final RDN rdn = parent(i).rdn();
                    // Only add a separator if the RDN is not RDN.maxValue().
                    if (rdn.size() != 0) {
                        builder.append(DN.NORMALIZED_RDN_SEPARATOR);
                        builder.appendByte(DN.NORMALIZED_RDN_SEPARATOR);
                    }
                    rdn.toNormalizedByteString(builder);
                }
opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/Filter.java
@@ -1179,9 +1179,9 @@
                    throw new LocalizedIllegalArgumentException(message);
                }
                valueBuffer.append(byteValue);
                valueBuffer.appendByte(byteValue);
            } else {
                valueBuffer.append(valueBytes[i]);
                valueBuffer.appendByte(valueBytes[i]);
            }
        }
    }
opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/RDN.java
@@ -429,7 +429,7 @@
        switch (size()) {
        case 0:
            // Handle RDN.maxValue().
            builder.append(DN.NORMALIZED_AVA_SEPARATOR);
            builder.appendByte(DN.NORMALIZED_AVA_SEPARATOR);
            break;
        case 1:
            getFirstAVA().toNormalizedByteString(builder);
@@ -438,7 +438,7 @@
            Iterator<AVA> it = getSortedAvas();
            it.next().toNormalizedByteString(builder);
            while (it.hasNext()) {
                builder.append(DN.NORMALIZED_AVA_SEPARATOR);
                builder.appendByte(DN.NORMALIZED_AVA_SEPARATOR);
                it.next().toNormalizedByteString(builder);
            }
            break;
opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/AbstractSubstringMatchingRuleImpl.java
@@ -81,7 +81,6 @@
            this.normFinal = normFinal;
        }
        /** {@inheritDoc} */
        @Override
        public ConditionResult matches(final ByteSequence normalizedAttributeValue) {
            final int valueLength = normalizedAttributeValue.length();
@@ -143,7 +142,6 @@
            return ConditionResult.TRUE;
        }
        /** {@inheritDoc} */
        @Override
        public <T> T createIndexQuery(IndexQueryFactory<T> factory) throws DecodeException {
            if (normInitial == null && (normAnys == null || normAnys.length == 0) && normFinal == null) {
@@ -235,7 +233,6 @@
            this.indexID = substringIndexId + ":" + this.substringKeySize;
        }
        /** {@inheritDoc} */
        @Override
        public void createKeys(Schema schema, ByteSequence value, Collection<ByteString> keys) throws DecodeException {
            final ByteString normValue = normalizeAttributeValue(schema, value);
@@ -256,7 +253,6 @@
            return AbstractSubstringMatchingRuleImpl.this.keyToHumanReadableString(key);
        }
        /** {@inheritDoc} */
        @Override
        public String getIndexID() {
            return indexID;
@@ -280,10 +276,8 @@
        return key.toString();
    }
    /** {@inheritDoc} */
    @Override
    public final Assertion getAssertion(final Schema schema, final ByteSequence assertionValue)
            throws DecodeException {
    public final Assertion getAssertion(final Schema schema, final ByteSequence assertionValue) throws DecodeException {
        if (assertionValue.length() == 0) {
            throw DecodeException.error(WARN_ATTR_SYNTAX_SUBSTRING_EMPTY.get());
        }
@@ -330,7 +324,6 @@
        return getSubstringAssertion(schema, initialString, anyStrings, finalString);
    }
    /** {@inheritDoc} */
    @Override
    public final Assertion getSubstringAssertion(final Schema schema, final ByteSequence subInitial,
            final List<? extends ByteSequence> subAnyElements, final ByteSequence subFinal)
@@ -513,8 +506,8 @@
                if (valueBuffer == null) {
                    valueBuffer = new ByteStringBuilder();
                }
                valueBuffer.append(reader.read(length));
                valueBuffer.append(evaluateEscapedChar(reader, escapeChars));
                valueBuffer.appendUtf8(reader.read(length));
                valueBuffer.appendInt(evaluateEscapedChar(reader, escapeChars));
                reader.mark();
                length = 0;
                continue;
@@ -524,7 +517,7 @@
                    if (c == delimiterChar) {
                        reader.reset();
                        if (valueBuffer != null) {
                            valueBuffer.append(reader.read(length));
                            valueBuffer.appendUtf8(reader.read(length));
                            return valueBuffer.toByteString();
                        } else {
                            if (length > 0) {
@@ -540,7 +533,7 @@
        reader.reset();
        if (valueBuffer != null) {
            valueBuffer.append(reader.read(length));
            valueBuffer.appendUtf8(reader.read(length));
            return valueBuffer.toByteString();
        } else {
            if (length > 0) {
@@ -550,10 +543,8 @@
        }
    }
    /** {@inheritDoc} */
    @Override
    public final Collection<? extends Indexer> createIndexers(IndexingOptions options) {
        return Collections.singleton(new SubstringIndexer(options.substringKeySize()));
    }
}
opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/CertificateExactMatchingRuleImpl.java
@@ -57,22 +57,13 @@
 */
final class CertificateExactMatchingRuleImpl
        extends AbstractEqualityMatchingRuleImpl {
    private static final LocalizedLogger logger = LocalizedLogger.getLoggerForThisClass();
    /**
     * The GSER identifier for the serialNumber named value.
     */
    /** The GSER identifier for the serialNumber named value. */
    private static final String GSER_ID_SERIALNUMBER = "serialNumber";
    /**
     * The GSER identifier for the issuer named value.
     */
    /** The GSER identifier for the issuer named value. */
    private static final String GSER_ID_ISSUER = "issuer";
    /**
     * The GSER identifier for the rdnSequence IdentifiedChoiceValue.
     */
    /** The GSER identifier for the rdnSequence IdentifiedChoiceValue. */
    private static final String GSER_ID_RDNSEQUENCE = "rdnSequence";
    CertificateExactMatchingRuleImpl() {
@@ -119,7 +110,6 @@
        return createEncodedValue(serialNumber, certificateIssuer);
    }
    /** {@inheritDoc} */
    @Override
    public Assertion getAssertion(final Schema schema, final ByteSequence value)
            throws DecodeException {
@@ -213,11 +203,10 @@
     * @return the encoded ByteString
     */
    private static ByteString createEncodedValue(BigInteger serial, ByteString issuerDN) {
        ByteStringBuilder builder = new ByteStringBuilder();
        builder.append(issuerDN);
        builder.append((byte) 0); // Separator
        builder.append(serial.toByteArray());
        return builder.toByteString();
        return new ByteStringBuilder()
            .appendBytes(issuerDN)
            .appendByte(0) // Separator
            .appendBytes(serial.toByteArray())
            .toByteString();
    }
}
opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/IntegerOrderingMatchingRuleImpl.java
@@ -95,7 +95,7 @@
        // Encode the absolute value of the integer..
        for (int i = startIndex; i < length; i++) {
            builder.append((byte) (absBytes[i] ^ signMask));
            builder.appendByte(absBytes[i] ^ signMask);
        }
        return builder.toByteString();
@@ -107,33 +107,33 @@
        if ((length & 0x0000000F) == length) {
            // 0000xxxx
            final byte b0 = (byte) (0x80 | length & 0x0F);
            builder.append((byte) (b0 ^ signMask));
            builder.appendByte(b0 ^ signMask);
        } else if ((length & 0x00000FFF) == length) {
            // 0001xxxx xxxxxxxx
            final byte b0 = (byte) (0x90 | length >> 8 & 0x0F);
            builder.append((byte) (b0 ^ signMask));
            builder.append((byte) (length & 0xFF ^ signMask));
            builder.appendByte(b0 ^ signMask);
            builder.appendByte(length & 0xFF ^ signMask);
        } else if ((length & 0x000FFFFF) == length) {
            // 0010xxxx xxxxxxxx xxxxxxxx
            final byte b0 = (byte) (0xA0 | length >> 16 & 0x0F);
            builder.append((byte) (b0 ^ signMask));
            builder.append((byte) (length >> 8 & 0xFF ^ signMask));
            builder.append((byte) (length & 0xFF ^ signMask));
            builder.appendByte(b0 ^ signMask);
            builder.appendByte(length >> 8 & 0xFF ^ signMask);
            builder.appendByte(length & 0xFF ^ signMask);
        } else if ((length & 0x0FFFFFFF) == length) {
            // 0011xxxx xxxxxxxx xxxxxxxx xxxxxxxx
            final byte b0 = (byte) (0xB0 | length >> 24 & 0x0F);
            builder.append((byte) (b0 ^ signMask));
            builder.append((byte) (length >> 16 & 0xFF ^ signMask));
            builder.append((byte) (length >> 8 & 0xFF ^ signMask));
            builder.append((byte) (length & 0xFF ^ signMask));
            builder.appendByte(b0 ^ signMask);
            builder.appendByte(length >> 16 & 0xFF ^ signMask);
            builder.appendByte(length >> 8 & 0xFF ^ signMask);
            builder.appendByte(length & 0xFF ^ signMask);
        } else {
            // 0100xxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxx0000
            final byte b0 = (byte) (0xC0 | length >> 28 & 0x0F);
            builder.append((byte) (b0 ^ signMask));
            builder.append((byte) (length >> 20 & 0xFF ^ signMask));
            builder.append((byte) (length >> 12 & 0xFF ^ signMask));
            builder.append((byte) (length >> 4 & 0xFF ^ signMask));
            builder.append((byte) (length << 4 & 0xFF ^ signMask));
            builder.appendByte(b0 ^ signMask);
            builder.appendByte(length >> 20 & 0xFF ^ signMask);
            builder.appendByte(length >> 12 & 0xFF ^ signMask);
            builder.appendByte(length >> 4 & 0xFF ^ signMask);
            builder.appendByte(length << 4 & 0xFF ^ signMask);
        }
    }
opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/TimeBasedMatchingRulesImpl.java
@@ -457,8 +457,8 @@
            // Since we reached here we have a valid assertion value.
            // Construct a normalized value in the order: SECOND MINUTE HOUR DATE MONTH YEAR.
            return new ByteStringBuilder(6 * 4)
                .append(second).append(minute).append(hour)
                .append(date).append(month).append(year).toByteString();
                .appendInt(second).appendInt(minute).appendInt(hour)
                .appendInt(date).appendInt(month).appendInt(year).toByteString();
        }
        private boolean isDateInvalid(int date, int month, int year) {
@@ -563,7 +563,7 @@
        }
        private ByteString getKey(int value, char type) {
            return new ByteStringBuilder().append(type).append(value).toByteString();
            return new ByteStringBuilder().appendInt(type).appendInt(value).toByteString();
        }
    }
opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/UUIDEqualityMatchingRuleImpl.java
@@ -122,7 +122,7 @@
            default:
                final int high4Bits = decodeHexByte(value, i++);
                final int low4Bits = decodeHexByte(value, i);
                builder.append((byte) ((high4Bits << 4) | low4Bits));
                builder.appendByte((high4Bits << 4) | low4Bits);
                break;
            }
        }
opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/UniqueMemberEqualityMatchingRuleImpl.java
@@ -63,8 +63,8 @@
        try {
            DN dn = DN.valueOf(stringValue.substring(0, dnEndPosition), schema.asNonStrictSchema());
            return new ByteStringBuilder()
                .append(dn.toNormalizedByteString())
                .append(optionalUid).toByteString();
                .appendBytes(dn.toNormalizedByteString())
                .appendUtf8(optionalUid).toByteString();
        } catch (final LocalizedIllegalArgumentException e) {
            throw DecodeException.error(e.getMessageObject());
        }
opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldif/AbstractLDIFReader.java
@@ -297,7 +297,7 @@
                    int bytesRead;
                    final byte[] buffer = new byte[4096];
                    while ((bytesRead = inputStream.read(buffer)) > 0) {
                        builder.append(buffer, 0, bytesRead);
                        builder.appendBytes(buffer, 0, bytesRead);
                    }
                    value = builder.toByteString();
opendj-sdk/opendj-core/src/test/java/org/forgerock/opendj/io/ASN1ReaderTestCase.java
@@ -528,9 +528,9 @@
    @Test(dataProvider = "elementArrays")
    public void testDecodeValidArrayAsOctetString(final byte[] b) throws Exception {
        final ByteStringBuilder bsb = new ByteStringBuilder();
        bsb.append(ASN1.UNIVERSAL_OCTET_STRING_TYPE);
        bsb.appendByte(ASN1.UNIVERSAL_OCTET_STRING_TYPE);
        bsb.appendBERLength(b.length);
        bsb.append(b);
        bsb.appendBytes(b);
        assertEquals(getReader(bsb.toByteArray(), 0).readOctetString(), ByteString.wrap(b));
    }
@@ -547,9 +547,9 @@
    @Test(dataProvider = "elementArrays")
    public void testDecodeValidArrayAsOctetStringAsString(final byte[] b) throws Exception {
        final ByteStringBuilder bsb = new ByteStringBuilder();
        bsb.append(ASN1.UNIVERSAL_OCTET_STRING_TYPE);
        bsb.appendByte(ASN1.UNIVERSAL_OCTET_STRING_TYPE);
        bsb.appendBERLength(b.length);
        bsb.append(b);
        bsb.appendBytes(b);
        assertEquals(getReader(bsb.toByteArray(), 0).readOctetStringAsString(), new String(b,
                "UTF-8"));
@@ -567,9 +567,9 @@
    @Test(dataProvider = "elementArrays")
    public void testDecodeValidArrayAsOctetStringAsStringCharSet(final byte[] b) throws Exception {
        final ByteStringBuilder bsb = new ByteStringBuilder();
        bsb.append(ASN1.UNIVERSAL_OCTET_STRING_TYPE);
        bsb.appendByte(ASN1.UNIVERSAL_OCTET_STRING_TYPE);
        bsb.appendBERLength(b.length);
        bsb.append(b);
        bsb.appendBytes(b);
        assertEquals(getReader(bsb.toByteArray(), 0).readOctetStringAsString(), new String(b,
                "UTF-8"));
@@ -587,9 +587,9 @@
    @Test(dataProvider = "elementArrays")
    public void testDecodeValidArrayAsOctetStringBuilder(final byte[] b) throws Exception {
        final ByteStringBuilder bsb = new ByteStringBuilder();
        bsb.append(ASN1.UNIVERSAL_OCTET_STRING_TYPE);
        bsb.appendByte(ASN1.UNIVERSAL_OCTET_STRING_TYPE);
        bsb.appendBERLength(b.length);
        bsb.append(b);
        bsb.appendBytes(b);
        final ByteStringBuilder bsb2 = new ByteStringBuilder();
        getReader(bsb.toByteArray(), 0).readOctetString(bsb2);
@@ -609,11 +609,11 @@
    @Test(dataProvider = "elementArrays")
    public void testDecodeValidArrayAsSequence(final byte[] encodedElements) throws Exception {
        final ByteStringBuilder bsb = new ByteStringBuilder();
        bsb.append(ASN1.UNIVERSAL_SEQUENCE_TYPE);
        bsb.appendByte(ASN1.UNIVERSAL_SEQUENCE_TYPE);
        bsb.appendBERLength(encodedElements.length + 2);
        bsb.append(ASN1.UNIVERSAL_OCTET_STRING_TYPE);
        bsb.appendByte(ASN1.UNIVERSAL_OCTET_STRING_TYPE);
        bsb.appendBERLength(encodedElements.length);
        bsb.append(encodedElements);
        bsb.appendBytes(encodedElements);
        final ASN1Reader reader = getReader(bsb.toByteArray(), 0);
        assertEquals(reader.peekLength(), encodedElements.length + 2);
opendj-sdk/opendj-core/src/test/java/org/forgerock/opendj/ldap/ByteSequenceReaderTest.java
@@ -22,7 +22,7 @@
 *
 *
 *      Copyright 2009 Sun Microsystems, Inc.
 *      Portions Copyright 2014 ForgeRock AS
 *      Portions Copyright 2014-2015 ForgeRock AS
 */
package org.forgerock.opendj.ldap;
@@ -50,8 +50,8 @@
    public Object[][] byteSequenceReaderProvider() {
        return new Object[][] {
            { ByteString.wrap(EIGHT_BYTES).asReader(), EIGHT_BYTES },
            { new ByteStringBuilder().append(EIGHT_BYTES).asReader(), EIGHT_BYTES },
            { new ByteStringBuilder().append(EIGHT_BYTES).subSequence(0, 8).asReader(), EIGHT_BYTES }
            { new ByteStringBuilder().appendBytes(EIGHT_BYTES).asReader(), EIGHT_BYTES },
            { new ByteStringBuilder().appendBytes(EIGHT_BYTES).subSequence(0, 8).asReader(), EIGHT_BYTES }
        };
    }
opendj-sdk/opendj-core/src/test/java/org/forgerock/opendj/ldap/ByteStringBuilderTestCase.java
@@ -68,7 +68,7 @@
        final Object[][] addlSequences = new Object[builders.length + 1][];
        System.arraycopy(builders, 0, addlSequences, 0, builders.length);
        addlSequences[builders.length] =
                new Object[] { new ByteStringBuilder().append(EIGHT_BYTES).subSequence(2, 6),
                new Object[] { new ByteStringBuilder().appendBytes(EIGHT_BYTES).subSequence(2, 6),
                    new byte[] { b(0x03), b(0x04), b(0x05), b(0x06) } };
        return addlSequences;
@@ -108,63 +108,63 @@
    @Test(expectedExceptions = IndexOutOfBoundsException.class)
    public void testAppendBadByteBufferLength1() {
        new ByteStringBuilder().append(ByteBuffer.wrap(new byte[5]), -1);
        new ByteStringBuilder().appendBytes(ByteBuffer.wrap(new byte[5]), -1);
    }
    @Test(expectedExceptions = IndexOutOfBoundsException.class)
    public void testAppendBadByteBufferLength2() {
        new ByteStringBuilder().append(ByteBuffer.wrap(new byte[5]), 6);
        new ByteStringBuilder().appendBytes(ByteBuffer.wrap(new byte[5]), 6);
    }
    @Test(expectedExceptions = IndexOutOfBoundsException.class)
    public void testAppendBadByteSequenceReaderLength1() {
        new ByteStringBuilder().append(ByteString.wrap(new byte[5]).asReader(), -1);
        new ByteStringBuilder().appendBytes(ByteString.wrap(new byte[5]).asReader(), -1);
    }
    @Test(expectedExceptions = IndexOutOfBoundsException.class)
    public void testAppendBadByteSequenceReaderLength2() {
        new ByteStringBuilder().append(ByteString.wrap(new byte[5]).asReader(), 6);
        new ByteStringBuilder().appendBytes(ByteString.wrap(new byte[5]).asReader(), 6);
    }
    @Test(expectedExceptions = IndexOutOfBoundsException.class)
    public void testAppendBadInputStreamLength() throws Exception {
        final ByteArrayInputStream stream = new ByteArrayInputStream(new byte[5]);
        new ByteStringBuilder().append(stream, -1);
        new ByteStringBuilder().appendBytes(stream, -1);
    }
    @Test(expectedExceptions = IndexOutOfBoundsException.class)
    public void testAppendBadLength1() {
        new ByteStringBuilder().append(new byte[5], 0, 6);
        new ByteStringBuilder().appendBytes(new byte[5], 0, 6);
    }
    @Test(expectedExceptions = IndexOutOfBoundsException.class)
    public void testAppendBadLength2() {
        new ByteStringBuilder().append(new byte[5], 0, -1);
        new ByteStringBuilder().appendBytes(new byte[5], 0, -1);
    }
    @Test(expectedExceptions = IndexOutOfBoundsException.class)
    public void testAppendBadOffset1() {
        new ByteStringBuilder().append(new byte[5], -1, 3);
        new ByteStringBuilder().appendBytes(new byte[5], -1, 3);
    }
    @Test(expectedExceptions = IndexOutOfBoundsException.class)
    public void testAppendBadOffset2() {
        new ByteStringBuilder().append(new byte[5], 6, 0);
        new ByteStringBuilder().appendBytes(new byte[5], 6, 0);
    }
    @Test
    public void testAppendInputStream() throws Exception {
        final ByteStringBuilder bsb = new ByteStringBuilder();
        final ByteArrayInputStream stream = new ByteArrayInputStream(new byte[5]);
        Assert.assertEquals(bsb.append(stream, 10), 5);
        Assert.assertEquals(bsb.appendBytes(stream, 10), 5);
    }
    @Test
    public void testAppendDataInputWithNonEmptyBuilder() throws Exception {
        final ByteStringBuilder bsb = new ByteStringBuilder();
        bsb.append((byte) 0);
        bsb.appendByte(0);
        final DataInput stream = new DataInputStream(new ByteArrayInputStream(new byte[5]));
        bsb.append(stream, 5);
        bsb.appendBytes(stream, 5);
        Assert.assertEquals(bsb.length(), 6);
    }
@@ -187,7 +187,7 @@
    private ByteStringBuilder builder(int length) {
        final ByteStringBuilder builder = new ByteStringBuilder();
        for (int i = 0; i < length; i++) {
            builder.append(42);
            builder.appendInt(42);
        }
        return builder;
    }
@@ -234,7 +234,7 @@
    @Test
    public void testTrimToSize() {
        final ByteStringBuilder bsb = new ByteStringBuilder();
        bsb.append(EIGHT_BYTES);
        bsb.appendBytes(EIGHT_BYTES);
        Assert.assertTrue(bsb.getBackingArray().length > 8);
        bsb.trimToSize();
        Assert.assertEquals(bsb.getBackingArray().length, 8);
@@ -275,45 +275,45 @@
        final ByteSequenceReader testByteReader = testByteString.asReader();
        final InputStream testStream = new ByteArrayInputStream(EIGHT_BYTES);
        final ByteStringBuilder testBuilderFromStream = new ByteStringBuilder(8);
        testBuilderFromStream.append(testStream, 8);
        testBuilderFromStream.appendBytes(testStream, 8);
        return new Object[][] {
            { new ByteStringBuilder().append(b(0x00)).append(b(0x01)),
            { new ByteStringBuilder().appendByte(0x00).appendByte(0x01),
                new byte[] { b(0x00), b(0x01) } },
            { new ByteStringBuilder(5)
                      .append(new byte[] { b(0x01), b(0x02), b(0x03), b(0x04) })
                      .append(new byte[] { b(0x05), b(0x06), b(0x07), b(0x08) }),
                      .appendBytes(new byte[] { b(0x01), b(0x02), b(0x03), b(0x04) })
                      .appendBytes(new byte[] { b(0x05), b(0x06), b(0x07), b(0x08) }),
                EIGHT_BYTES },
            { new ByteStringBuilder(3).append(EIGHT_BYTES, 0, 3).append(EIGHT_BYTES, 3, 5),
            { new ByteStringBuilder(3).appendBytes(EIGHT_BYTES, 0, 3).appendBytes(EIGHT_BYTES, 3, 5),
                EIGHT_BYTES },
            { new ByteStringBuilder().append(testBuffer, 3).append(testBuffer, 5), EIGHT_BYTES },
            { new ByteStringBuilder(2).append(testByteString), EIGHT_BYTES },
            { new ByteStringBuilder().append(testByteReader, 5).append(testByteReader, 3),
            { new ByteStringBuilder().appendBytes(testBuffer, 3).appendBytes(testBuffer, 5), EIGHT_BYTES },
            { new ByteStringBuilder(2).appendBytes(testByteString), EIGHT_BYTES },
            { new ByteStringBuilder().appendBytes(testByteReader, 5).appendBytes(testByteReader, 3),
                EIGHT_BYTES },
            { testBuilderFromStream, EIGHT_BYTES },
            { new ByteStringBuilder().append(Short.MIN_VALUE).append(Short.MAX_VALUE),
            { new ByteStringBuilder().appendShort(Short.MIN_VALUE).appendShort(Short.MAX_VALUE),
                new byte[] { b(0x80), b(0x00), b(0x7F), b(0xFF) } },
            {
                new ByteStringBuilder(5).append(Integer.MIN_VALUE).append(Integer.MAX_VALUE),
                new ByteStringBuilder(5).appendInt(Integer.MIN_VALUE).appendInt(Integer.MAX_VALUE),
                new byte[] { b(0x80), b(0x00), b(0x00), b(0x00), b(0x7F),
                    b(0xFF), b(0xFF), b(0xFF) } },
            {
                new ByteStringBuilder().append(Long.MIN_VALUE).append(Long.MAX_VALUE),
                new ByteStringBuilder().appendLong(Long.MIN_VALUE).appendLong(Long.MAX_VALUE),
                new byte[] { b(0x80), b(0x00), b(0x00), b(0x00), b(0x00),
                    b(0x00), b(0x00), b(0x00), b(0x7F), b(0xFF), b(0xFF),
                    b(0xFF), b(0xFF), b(0xFF), b(0xFF), b(0xFF) } },
            { new ByteStringBuilder(11).append("this is a").append(" test"),
            { new ByteStringBuilder(11).appendUtf8("this is a").appendUtf8(" test"),
                "this is a test".getBytes("UTF-8") },
            { new ByteStringBuilder().append((Object) "this is a").append((Object) " test"),
            { new ByteStringBuilder().appendObject((Object) "this is a").appendObject((Object) " test"),
                "this is a test".getBytes("UTF-8") },
            {
                new ByteStringBuilder().append("this is a".toCharArray()).append(
                new ByteStringBuilder().appendUtf8("this is a".toCharArray()).appendUtf8(
                        " test".toCharArray()), "this is a test".getBytes("UTF-8") },
            {
                new ByteStringBuilder().append((Object) "this is a".toCharArray()).append(
                new ByteStringBuilder().appendObject((Object) "this is a".toCharArray()).appendObject(
                        (Object) " test".toCharArray()), "this is a test".getBytes("UTF-8") },
            {
                new ByteStringBuilder().append((Object) EIGHT_BYTES).append((Object) EIGHT_BYTES),
                new ByteStringBuilder().appendObject((Object) EIGHT_BYTES).appendObject((Object) EIGHT_BYTES),
                new byte[] { b(0x01), b(0x02), b(0x03), b(0x04), b(0x05),
                    b(0x06), b(0x07), b(0x08), b(0x01), b(0x02), b(0x03),
                    b(0x04), b(0x05), b(0x06), b(0x07), b(0x08) } },
@@ -341,7 +341,7 @@
    @Test
    public void testCopyCtor() {
        final ByteStringBuilder builder = new ByteStringBuilder(400);
        builder.append("this is a ByteString");
        builder.appendUtf8("this is a ByteString");
        final ByteString orig = builder.toByteString();
        final ByteString copy = new ByteStringBuilder(orig).toByteString();
        Assert.assertEquals(copy, orig);
@@ -351,7 +351,7 @@
    @Test
    public void testSetByte() {
        final ByteStringBuilder builder = new ByteStringBuilder();
        builder.append("this is a ByteString");
        builder.appendUtf8("this is a ByteString");
        builder.setByte(2, b('a'));
        builder.setByte(3, b('t'));
        Assert.assertEquals(builder.toByteString().toString(), "that is a ByteString");
@@ -372,7 +372,7 @@
    @Test
    public void testSetLength() {
        final ByteStringBuilder builder = new ByteStringBuilder();
        builder.append("this is a ByteString");
        builder.appendUtf8("this is a ByteString");
        builder.setLength(builder.length() - 16);
        Assert.assertEquals(builder.toString(), "this");
        builder.setLength(builder.length() + 1);
@@ -387,28 +387,28 @@
    @Test
    public void testAppendNullCharArray() {
        final ByteStringBuilder builder = new ByteStringBuilder();
        builder.append((char[]) null);
        builder.appendUtf8((char[]) null);
        Assert.assertTrue(builder.isEmpty());
    }
    @Test
    public void testAppendNullString() {
        final ByteStringBuilder builder = new ByteStringBuilder();
        builder.append((String) null);
        builder.appendUtf8((String) null);
        Assert.assertTrue(builder.isEmpty());
    }
    @Test
    public void testAppendNonAsciiCharArray() {
        final ByteStringBuilder builder = new ByteStringBuilder();
        builder.append(new char[] { 'œ', 'Œ' });
        builder.appendUtf8(new char[] { 'œ', 'Œ' });
        Assert.assertEquals(builder.toString(), "œŒ");
    }
    @Test
    public void testAppendNonAsciiString() {
        final ByteStringBuilder builder = new ByteStringBuilder();
        builder.append("œŒ");
        builder.appendUtf8("œŒ");
        Assert.assertEquals(builder.toString(), "œŒ");
    }
@@ -448,7 +448,7 @@
    public void testSubSequenceIsEmpty() {
        final ByteStringBuilder builder = new ByteStringBuilder();
        Assert.assertTrue(builder.subSequence(0, builder.length()).isEmpty());
        builder.append("This is a ByteString");
        builder.appendUtf8("This is a ByteString");
        Assert.assertFalse(builder.subSequence(0, builder.length()).isEmpty());
    }
}
opendj-sdk/opendj-core/src/test/java/org/forgerock/opendj/ldap/ByteStringTestCase.java
@@ -265,7 +265,7 @@
    @Test
    public void testToHex() throws Exception {
        ByteString byteString = new ByteStringBuilder().append("org=example").toByteString();
        ByteString byteString = new ByteStringBuilder().appendUtf8("org=example").toByteString();
        assertThat(byteString.toHexString()).isEqualTo("6F 72 67 3D 65 78 61 6D 70 6C 65");
        assertThat(ByteString.empty().toHexString()).isEqualTo("");
@@ -273,7 +273,7 @@
    @Test
    public void testToPercentHex() throws Exception {
        ByteString byteString = new ByteStringBuilder().append("org=example").toByteString();
        ByteString byteString = new ByteStringBuilder().appendUtf8("org=example").toByteString();
        assertThat(byteString.toPercentHexString())
            .isEqualTo("%6F%72%67%3D%65%78%61%6D%70%6C%65");
    }
@@ -281,7 +281,7 @@
    @Test
    public void testCopyToCharBuffer() throws Exception {
        String value = "org=example";
        ByteString byteString = new ByteStringBuilder().append(value).toByteString();
        ByteString byteString = new ByteStringBuilder().appendUtf8(value).toByteString();
        CharBuffer buffer = CharBuffer.allocate(value.length());
        final CharsetDecoder decoder = Charset.forName("UTF-8").newDecoder();
@@ -295,7 +295,7 @@
    @Test
    public void testCopyToCharBufferFailure() throws Exception {
        // Non valid UTF-8 byte sequence
        ByteString byteString = new ByteStringBuilder().append((byte) 0x80).toByteString();
        ByteString byteString = new ByteStringBuilder().appendByte(0x80).toByteString();
        CharBuffer buffer = CharBuffer.allocate(1);
        final CharsetDecoder decoder = Charset.forName("UTF-8").newDecoder();
@@ -308,7 +308,7 @@
    @Test
    public void testCopyToByteBuffer() throws Exception {
        String value = "org=example";
        ByteString byteString = new ByteStringBuilder().append(value).toByteString();
        ByteString byteString = new ByteStringBuilder().appendUtf8(value).toByteString();
        ByteBuffer buffer = ByteBuffer.allocate(value.length());
        byteString.copyTo(buffer);
@@ -326,7 +326,7 @@
    @Test
    public void testToHexPlusAsciiString() throws Exception {
        final String eol = System.getProperty("line.separator");
        ByteString byteString = new ByteStringBuilder().append("cn=testvalue,org=example").toByteString();
        ByteString byteString = new ByteStringBuilder().appendUtf8("cn=testvalue,org=example").toByteString();
        assertThat(byteString.toHexPlusAsciiString(10)).isEqualTo(
              "          63 6E 3D 74 65 73 74 76   61 6C 75 65 2C 6F 72 67  cn=testv alue,org" + eol
            + "          3D 65 78 61 6D 70 6C 65                            =example " + eol);
opendj-sdk/opendj-core/src/test/java/org/forgerock/opendj/ldap/schema/IntegerOrderingMatchingRuleTest.java
@@ -117,7 +117,7 @@
    private String expected(int... bytes) {
        ByteStringBuilder builder = new ByteStringBuilder();
        for (int b : bytes) {
            builder.append((byte) b);
            builder.appendByte(b);
        }
        return builder.toByteString().toHexString();
    }
opendj-sdk/opendj-grizzly/src/main/java/org/forgerock/opendj/grizzly/ASN1BufferReader.java
@@ -22,7 +22,7 @@
 *
 *
 *      Copyright 2010 Sun Microsystems, Inc.
 *      Portions copyright 2012-2014 ForgeRock AS.
 *      Portions copyright 2012-2015 ForgeRock AS.
 */
package org.forgerock.opendj.grizzly;
@@ -43,9 +43,7 @@
import org.glassfish.grizzly.memory.CompositeBuffer;
import org.glassfish.grizzly.memory.MemoryManager;
/**
 * Grizzly ASN1 reader implementation.
 */
/** Grizzly ASN1 reader implementation. */
final class ASN1BufferReader extends AbstractASN1Reader {
    private final class ChildSequenceLimiter implements SequenceLimiter {
        private SequenceLimiter parent;
@@ -371,7 +369,7 @@
        // Copy the value and construct the element to return.
        // TODO: Is there a more efficient way to do this?
        for (int i = 0; i < peekLength; i++) {
            builder.append(buffer.get());
            builder.appendByte(buffer.get());
        }
        logger.trace("READ ASN.1 OCTETSTRING(type=0x%x, length=%d)", peekType, peekLength);
opendj-sdk/opendj-grizzly/src/main/java/org/forgerock/opendj/grizzly/ASN1BufferWriter.java
@@ -22,7 +22,7 @@
 *
 *
 *      Copyright 2010 Sun Microsystems, Inc.
 *      Portions copyright 2012-2014 ForgeRock AS.
 *      Portions copyright 2012-2015 ForgeRock AS.
 */
package org.forgerock.opendj.grizzly;
@@ -44,9 +44,7 @@
import com.forgerock.opendj.util.StaticUtils;
/**
 * Grizzly ASN1 writer implementation.
 */
/** Grizzly ASN1 writer implementation. */
final class ASN1BufferWriter extends AbstractASN1Writer implements Cacheable {
    private class ChildSequenceBuffer implements SequenceBuffer {
        private SequenceBuffer parent;
@@ -66,18 +64,17 @@
                child = new ChildSequenceBuffer();
                child.parent = this;
            }
            buffer.append(type);
            buffer.appendByte(type);
            child.buffer.clear();
            return child;
        }
        public void writeByte(final byte b) throws IOException {
            buffer.append(b);
            buffer.appendByte(b);
        }
        public void writeByteArray(final byte[] bs, final int offset, final int length)
                throws IOException {
            buffer.append(bs, offset, length);
        public void writeByteArray(final byte[] bs, final int offset, final int length) throws IOException {
            buffer.appendBytes(bs, offset, length);
        }
    }
@@ -250,27 +247,27 @@
        if (((intValue < 0) && ((intValue & 0xFFFFFF80) == 0xFFFFFF80))
                || ((intValue & 0x0000007F) == intValue)) {
            writeLength(sequenceBuffer, 1);
            sequenceBuffer.writeByte((byte) (intValue & 0xFF));
            sequenceBuffer.writeByte((byte) intValue);
            logger.trace("WRITE ASN.1 INTEGER(type=0x%x, length=%d, value=%d)", type, 1, intValue);
        } else if (((intValue < 0) && ((intValue & 0xFFFF8000) == 0xFFFF8000))
                || ((intValue & 0x00007FFF) == intValue)) {
            writeLength(sequenceBuffer, 2);
            sequenceBuffer.writeByte((byte) ((intValue >> 8) & 0xFF));
            sequenceBuffer.writeByte((byte) (intValue & 0xFF));
            sequenceBuffer.writeByte((byte) (intValue >> 8));
            sequenceBuffer.writeByte((byte) intValue);
            logger.trace("WRITE ASN.1 INTEGER(type=0x%x, length=%d, value=%d)", type, 2, intValue);
        } else if (((intValue < 0) && ((intValue & 0xFF800000) == 0xFF800000))
                || ((intValue & 0x007FFFFF) == intValue)) {
            writeLength(sequenceBuffer, 3);
            sequenceBuffer.writeByte((byte) ((intValue >> 16) & 0xFF));
            sequenceBuffer.writeByte((byte) ((intValue >> 8) & 0xFF));
            sequenceBuffer.writeByte((byte) (intValue & 0xFF));
            sequenceBuffer.writeByte((byte) (intValue >> 16));
            sequenceBuffer.writeByte((byte) (intValue >> 8));
            sequenceBuffer.writeByte((byte) intValue);
            logger.trace("WRITE ASN.1 INTEGER(type=0x%x, length=%d, value=%d)", type, 3, intValue);
        } else {
            writeLength(sequenceBuffer, 4);
            sequenceBuffer.writeByte((byte) ((intValue >> 24) & 0xFF));
            sequenceBuffer.writeByte((byte) ((intValue >> 16) & 0xFF));
            sequenceBuffer.writeByte((byte) ((intValue >> 8) & 0xFF));
            sequenceBuffer.writeByte((byte) (intValue & 0xFF));
            sequenceBuffer.writeByte((byte) (intValue >> 24));
            sequenceBuffer.writeByte((byte) (intValue >> 16));
            sequenceBuffer.writeByte((byte) (intValue >> 8));
            sequenceBuffer.writeByte((byte) intValue);
            logger.trace("WRITE ASN.1 INTEGER(type=0x%x, length=%d, value=%d)", type, 4, intValue);
        }
        return this;
@@ -282,69 +279,69 @@
        if (((longValue < 0) && ((longValue & 0xFFFFFFFFFFFFFF80L) == 0xFFFFFFFFFFFFFF80L))
                || ((longValue & 0x000000000000007FL) == longValue)) {
            writeLength(sequenceBuffer, 1);
            sequenceBuffer.writeByte((byte) (longValue & 0xFF));
            sequenceBuffer.writeByte((byte) longValue);
            logger.trace("WRITE ASN.1 INTEGER(type=0x%x, length=%d, value=%d)", type, 1, longValue);
        } else if (((longValue < 0) && ((longValue & 0xFFFFFFFFFFFF8000L) == 0xFFFFFFFFFFFF8000L))
                || ((longValue & 0x0000000000007FFFL) == longValue)) {
            writeLength(sequenceBuffer, 2);
            sequenceBuffer.writeByte((byte) ((longValue >> 8) & 0xFF));
            sequenceBuffer.writeByte((byte) (longValue & 0xFF));
            sequenceBuffer.writeByte((byte) (longValue >> 8));
            sequenceBuffer.writeByte((byte) longValue);
            logger.trace("WRITE ASN.1 INTEGER(type=0x%x, length=%d, value=%d)", type, 2, longValue);
        } else if (((longValue < 0) && ((longValue & 0xFFFFFFFFFF800000L) == 0xFFFFFFFFFF800000L))
                || ((longValue & 0x00000000007FFFFFL) == longValue)) {
            writeLength(sequenceBuffer, 3);
            sequenceBuffer.writeByte((byte) ((longValue >> 16) & 0xFF));
            sequenceBuffer.writeByte((byte) ((longValue >> 8) & 0xFF));
            sequenceBuffer.writeByte((byte) (longValue & 0xFF));
            sequenceBuffer.writeByte((byte) (longValue >> 16));
            sequenceBuffer.writeByte((byte) (longValue >> 8));
            sequenceBuffer.writeByte((byte) longValue);
            logger.trace("WRITE ASN.1 INTEGER(type=0x%x, length=%d, value=%d)", type, 3, longValue);
        } else if (((longValue < 0) && ((longValue & 0xFFFFFFFF80000000L) == 0xFFFFFFFF80000000L))
                || ((longValue & 0x000000007FFFFFFFL) == longValue)) {
            writeLength(sequenceBuffer, 4);
            sequenceBuffer.writeByte((byte) ((longValue >> 24) & 0xFF));
            sequenceBuffer.writeByte((byte) ((longValue >> 16) & 0xFF));
            sequenceBuffer.writeByte((byte) ((longValue >> 8) & 0xFF));
            sequenceBuffer.writeByte((byte) (longValue & 0xFF));
            sequenceBuffer.writeByte((byte) (longValue >> 24));
            sequenceBuffer.writeByte((byte) (longValue >> 16));
            sequenceBuffer.writeByte((byte) (longValue >> 8));
            sequenceBuffer.writeByte((byte) longValue);
            logger.trace("WRITE ASN.1 INTEGER(type=0x%x, length=%d, value=%d)", type, 4, longValue);
        } else if (((longValue < 0) && ((longValue & 0xFFFFFF8000000000L) == 0xFFFFFF8000000000L))
                || ((longValue & 0x0000007FFFFFFFFFL) == longValue)) {
            writeLength(sequenceBuffer, 5);
            sequenceBuffer.writeByte((byte) ((longValue >> 32) & 0xFF));
            sequenceBuffer.writeByte((byte) ((longValue >> 24) & 0xFF));
            sequenceBuffer.writeByte((byte) ((longValue >> 16) & 0xFF));
            sequenceBuffer.writeByte((byte) ((longValue >> 8) & 0xFF));
            sequenceBuffer.writeByte((byte) (longValue & 0xFF));
            sequenceBuffer.writeByte((byte) (longValue >> 32));
            sequenceBuffer.writeByte((byte) (longValue >> 24));
            sequenceBuffer.writeByte((byte) (longValue >> 16));
            sequenceBuffer.writeByte((byte) (longValue >> 8));
            sequenceBuffer.writeByte((byte) longValue);
            logger.trace("WRITE ASN.1 INTEGER(type=0x%x, length=%d, value=%d)", type, 5, longValue);
        } else if (((longValue < 0) && ((longValue & 0xFFFF800000000000L) == 0xFFFF800000000000L))
                || ((longValue & 0x00007FFFFFFFFFFFL) == longValue)) {
            writeLength(sequenceBuffer, 6);
            sequenceBuffer.writeByte((byte) ((longValue >> 40) & 0xFF));
            sequenceBuffer.writeByte((byte) ((longValue >> 32) & 0xFF));
            sequenceBuffer.writeByte((byte) ((longValue >> 24) & 0xFF));
            sequenceBuffer.writeByte((byte) ((longValue >> 16) & 0xFF));
            sequenceBuffer.writeByte((byte) ((longValue >> 8) & 0xFF));
            sequenceBuffer.writeByte((byte) (longValue & 0xFF));
            sequenceBuffer.writeByte((byte) (longValue >> 40));
            sequenceBuffer.writeByte((byte) (longValue >> 32));
            sequenceBuffer.writeByte((byte) (longValue >> 24));
            sequenceBuffer.writeByte((byte) (longValue >> 16));
            sequenceBuffer.writeByte((byte) (longValue >> 8));
            sequenceBuffer.writeByte((byte) longValue);
            logger.trace("WRITE ASN.1 INTEGER(type=0x%x, length=%d, value=%d)", type, 6, longValue);
        } else if (((longValue < 0) && ((longValue & 0xFF80000000000000L) == 0xFF80000000000000L))
                || ((longValue & 0x007FFFFFFFFFFFFFL) == longValue)) {
            writeLength(sequenceBuffer, 7);
            sequenceBuffer.writeByte((byte) ((longValue >> 48) & 0xFF));
            sequenceBuffer.writeByte((byte) ((longValue >> 40) & 0xFF));
            sequenceBuffer.writeByte((byte) ((longValue >> 32) & 0xFF));
            sequenceBuffer.writeByte((byte) ((longValue >> 24) & 0xFF));
            sequenceBuffer.writeByte((byte) ((longValue >> 16) & 0xFF));
            sequenceBuffer.writeByte((byte) ((longValue >> 8) & 0xFF));
            sequenceBuffer.writeByte((byte) (longValue & 0xFF));
            sequenceBuffer.writeByte((byte) (longValue >> 48));
            sequenceBuffer.writeByte((byte) (longValue >> 40));
            sequenceBuffer.writeByte((byte) (longValue >> 32));
            sequenceBuffer.writeByte((byte) (longValue >> 24));
            sequenceBuffer.writeByte((byte) (longValue >> 16));
            sequenceBuffer.writeByte((byte) (longValue >> 8));
            sequenceBuffer.writeByte((byte) longValue);
            logger.trace("WRITE ASN.1 INTEGER(type=0x%x, length=%d, value=%d)", type, 7, longValue);
        } else {
            writeLength(sequenceBuffer, 8);
            sequenceBuffer.writeByte((byte) ((longValue >> 56) & 0xFF));
            sequenceBuffer.writeByte((byte) ((longValue >> 48) & 0xFF));
            sequenceBuffer.writeByte((byte) ((longValue >> 40) & 0xFF));
            sequenceBuffer.writeByte((byte) ((longValue >> 32) & 0xFF));
            sequenceBuffer.writeByte((byte) ((longValue >> 24) & 0xFF));
            sequenceBuffer.writeByte((byte) ((longValue >> 16) & 0xFF));
            sequenceBuffer.writeByte((byte) ((longValue >> 8) & 0xFF));
            sequenceBuffer.writeByte((byte) (longValue & 0xFF));
            sequenceBuffer.writeByte((byte) (longValue >> 56));
            sequenceBuffer.writeByte((byte) (longValue >> 48));
            sequenceBuffer.writeByte((byte) (longValue >> 40));
            sequenceBuffer.writeByte((byte) (longValue >> 32));
            sequenceBuffer.writeByte((byte) (longValue >> 24));
            sequenceBuffer.writeByte((byte) (longValue >> 16));
            sequenceBuffer.writeByte((byte) (longValue >> 8));
            sequenceBuffer.writeByte((byte) longValue);
            logger.trace("WRITE ASN.1 INTEGER(type=0x%x, length=%d, value=%d)", type, 8, longValue);
        }
        return this;
@@ -437,22 +434,22 @@
            buffer.writeByte((byte) length);
        } else if ((length & 0x000000FF) == length) {
            buffer.writeByte((byte) 0x81);
            buffer.writeByte((byte) (length & 0xFF));
            buffer.writeByte((byte) length);
        } else if ((length & 0x0000FFFF) == length) {
            buffer.writeByte((byte) 0x82);
            buffer.writeByte((byte) ((length >> 8) & 0xFF));
            buffer.writeByte((byte) (length & 0xFF));
            buffer.writeByte((byte) (length >> 8));
            buffer.writeByte((byte) length);
        } else if ((length & 0x00FFFFFF) == length) {
            buffer.writeByte((byte) 0x83);
            buffer.writeByte((byte) ((length >> 16) & 0xFF));
            buffer.writeByte((byte) ((length >> 8) & 0xFF));
            buffer.writeByte((byte) (length & 0xFF));
            buffer.writeByte((byte) (length >> 16));
            buffer.writeByte((byte) (length >> 8));
            buffer.writeByte((byte) length);
        } else {
            buffer.writeByte((byte) 0x84);
            buffer.writeByte((byte) ((length >> 24) & 0xFF));
            buffer.writeByte((byte) ((length >> 16) & 0xFF));
            buffer.writeByte((byte) ((length >> 8) & 0xFF));
            buffer.writeByte((byte) (length & 0xFF));
            buffer.writeByte((byte) (length >> 24));
            buffer.writeByte((byte) (length >> 16));
            buffer.writeByte((byte) (length >> 8));
            buffer.writeByte((byte) length);
        }
    }
}