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

Nicolas Capponi
09.34.2014 12da42ad5df736612d6e7cefccab7dad3e5a3c21
Add ByteStringBuilder#clear(int) and  ByteStringBuilder#capacity() methods
to align class with ByteStringBuilder class from server 2.x
2 files modified
44 ■■■■■ changed files
opendj-core/src/main/java/org/forgerock/opendj/ldap/ByteStringBuilder.java 36 ●●●●● patch | view | raw | blame | history
opendj-core/src/test/java/org/forgerock/opendj/ldap/ByteStringBuilderTestCase.java 8 ●●●●● patch | view | raw | blame | history
opendj-core/src/main/java/org/forgerock/opendj/ldap/ByteStringBuilder.java
@@ -720,6 +720,16 @@
    }
    /**
     * Returns the current capacity of this byte string builder. The capacity
     * may increase as more data is appended.
     *
     * @return The current capacity of this byte string builder.
     */
    public int capacity() {
        return buffer.length;
    }
    /**
     * Sets the length of this byte string builder to zero.
     * <p>
     * <b>NOTE:</b> if this method is called, then
@@ -735,6 +745,32 @@
    }
    /**
     * Sets the length of this byte string builder to zero, and resets the
     * capacity to the specified size.
     * <p>
     * <b>NOTE:</b> if this method is called, then
     * {@code ByteSequenceReader.rewind()} must also be called on any associated
     * byte sequence readers in order for them to remain valid.
     *
     * @param capacity
     *            The new capacity.
     * @return This byte string builder.
     * @throws IllegalArgumentException
     *             If the {@code capacity} is negative.
     * @see #asReader()
     */
    public ByteStringBuilder clear(int capacity) {
        if (capacity < 0) {
            throw new IllegalArgumentException();
        }
        if (capacity != buffer.length) {
            buffer = new byte[capacity];
        }
        length = 0;
        return this;
    }
    /**
     * {@inheritDoc}
     */
    public int compareTo(final byte[] bytes, final int offset, final int length) {
opendj-core/src/test/java/org/forgerock/opendj/ldap/ByteStringBuilderTestCase.java
@@ -124,6 +124,14 @@
        bs.byteAt(0);
    }
    @Test(dataProvider = "builderProvider", expectedExceptions = IndexOutOfBoundsException.class)
    public void testClearWithNewCapacity(ByteStringBuilder bs, byte[] ba) {
        bs.clear(123);
        Assert.assertEquals(bs.length(), 0);
        Assert.assertEquals(bs.capacity(), 123);
        bs.byteAt(0);
    }
    @Test
    public void testEnsureAdditionalCapacity() {
        final ByteStringBuilder bsb = new ByteStringBuilder(8);