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

Jean-Noël Rouvignac
30.11.2015 f4b8f759fd6e59b16535187b4772e98f541690cb
opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/ByteSequenceReader.java
@@ -26,6 +26,8 @@
 */
package org.forgerock.opendj.ldap;
import static com.forgerock.opendj.ldap.CoreMessages.*;
import java.io.IOException;
import java.io.InputStream;
@@ -318,7 +320,7 @@
     *             If there are fewer bytes remaining in this reader than are
     *             required to satisfy the request.
     */
    public long readCompactUnsigned() {
    public long readCompactUnsignedLong() {
        try {
            return PackedLong.readCompactUnsignedLong(asInputStream());
        } catch (IOException e) {
@@ -327,6 +329,27 @@
    }
    /**
     * Relative read method for reading a compacted int value.
     * Compaction allows to reduce number of bytes needed to hold int types
     * depending on its value (i.e: if value < 128, value will be encoded using one byte only).
     * Reads the next bytes at this reader's current position, composing them into an int value
     * according to big-endian byte order, and then increments the position by the size of the
     * encoded int.
     *
     * @return The int value at this reader's current position.
     * @throws IndexOutOfBoundsException
     *             If there are fewer bytes remaining in this reader than are
     *             required to satisfy the request.
     */
    public int readCompactUnsignedInt() {
        long l = readCompactUnsignedLong();
        if (l > Integer.MAX_VALUE) {
            throw new IllegalStateException(ERR_INVALID_COMPACTED_UNSIGNED_INT.get(Integer.MAX_VALUE, l).toString());
        }
        return (int) l;
    }
    /**
     * Relative read method for reading an short value. Reads the next 2 bytes at
     * this reader's current position, composing them into an short value
     * according to big-endian byte order, and then increments the position by
opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/TimeBasedMatchingRulesImpl.java
@@ -295,7 +295,7 @@
                    int assertHour = reader.readByte();
                    int assertDay = reader.readByte();
                    int assertMonth = reader.readByte();
                    int assertYear = (int) reader.readCompactUnsigned();
                    int assertYear = reader.readCompactUnsignedInt();
                    List<T> queries = new ArrayList<>();
                    if (assertSecond >= 0) {
@@ -506,7 +506,7 @@
            int assertHour = r.readByte();
            int assertDay = r.readByte();
            int assertMonth = r.readByte();
            int assertYear = (int) r.readCompactUnsigned();
            int assertYear = r.readCompactUnsignedInt();
            // All the non-zero and non -1 values should match.
            return ConditionResult.valueOf(
opendj-sdk/opendj-core/src/main/resources/com/forgerock/opendj/ldap/core.properties
@@ -1643,6 +1643,8 @@
 value "%s" could not be parsed as a valid assertion value because the \
 character '%c' is not allowed. The acceptable values are s (second), \
 m (minute), h (hour), D (date), M (month) and Y (year)
ERR_INVALID_COMPACTED_UNSIGNED_INT="Expected a compacted unsigned int (value less than %d), \
 but got a compacted unsigned long: %d
# Labels for generated documentation
DOC_LOCALE_TAG=Code tag: %s
opendj-sdk/opendj-core/src/test/java/org/forgerock/opendj/ldap/ByteStringBuilderTestCase.java
@@ -87,7 +87,7 @@
    @Test(dataProvider = "unsignedLongValues")
    public void testCanAppendCompactPositiveValue(long value) {
        assertThat(new ByteStringBuilder().appendCompactUnsigned(value).asReader().readCompactUnsigned())
        assertThat(new ByteStringBuilder().appendCompactUnsigned(value).asReader().readCompactUnsignedLong())
            .isEqualTo(value);
    }