opendj-sdk/opendj-core/clirr-ignored-api-changes.xml
@@ -530,4 +530,10 @@ <to>void</to> <justification>OPENDJ-1802 Consider making ByteString / ByteStringBuilder methods more intentional</justification> </difference> <difference> <className>org/forgerock/opendj/ldap/ByteSequenceReader</className> <differenceType>7002</differenceType> <method>%regex[(\w|\.)+ get\w*\([^)]*\)]</method> <justification>OPENDJ-1802 ByteSequenceReader.get*() => readByte(), readBytes() and read*()</justification> </difference> </differences> opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/io/ASN1ByteSequenceReader.java
@@ -38,9 +38,7 @@ import org.forgerock.opendj.ldap.ByteStringBuilder; import org.forgerock.opendj.ldap.DecodeException; /** * An ASN.1 reader that reads from a {@link ByteSequenceReader}. */ /** An ASN.1 reader that reads from a {@link ByteSequenceReader}. */ final class ASN1ByteSequenceReader extends AbstractASN1Reader { private static final LocalizedLogger logger = LocalizedLogger.getLoggerForThisClass(); @@ -67,24 +65,24 @@ this.maxElementSize = maxElementSize; } /** {@inheritDoc} */ @Override public void close() throws IOException { readerStack.clear(); } /** {@inheritDoc} */ @Override public boolean elementAvailable() throws IOException { return (state != ASN1.ELEMENT_READ_STATE_NEED_TYPE || needTypeState(false)) && (state != ASN1.ELEMENT_READ_STATE_NEED_FIRST_LENGTH_BYTE || needFirstLengthByteState(false)) && peekLength <= reader.remaining(); } /** {@inheritDoc} */ @Override public boolean hasNextElement() throws IOException { return state != ASN1.ELEMENT_READ_STATE_NEED_TYPE || needTypeState(false); } /** {@inheritDoc} */ @Override public int peekLength() throws IOException { peekType(); @@ -95,7 +93,7 @@ return peekLength; } /** {@inheritDoc} */ @Override public byte peekType() throws IOException { if (state == ASN1.ELEMENT_READ_STATE_NEED_TYPE) { // Read just the type. @@ -103,7 +101,7 @@ final LocalizableMessage message = ERR_ASN1_TRUCATED_TYPE_BYTE.get(); throw DecodeException.fatalError(message); } final int type = reader.get(); final int type = reader.readByte(); peekType = (byte) type; state = ASN1.ELEMENT_READ_STATE_NEED_FIRST_LENGTH_BYTE; @@ -112,7 +110,7 @@ return peekType; } /** {@inheritDoc} */ @Override public boolean readBoolean() throws IOException { // Read the header if haven't done so already peekLength(); @@ -126,13 +124,13 @@ final LocalizableMessage message = ERR_ASN1_BOOLEAN_TRUNCATED_VALUE.get(peekLength); throw DecodeException.fatalError(message); } final int readByte = reader.get(); final int readByte = reader.readByte(); state = ASN1.ELEMENT_READ_STATE_NEED_TYPE; return readByte != 0x00; } /** {@inheritDoc} */ @Override public void readEndSequence() throws IOException { if (readerStack.isEmpty()) { final LocalizableMessage message = ERR_ASN1_SEQUENCE_READ_NOT_STARTED.get(); @@ -150,20 +148,19 @@ state = ASN1.ELEMENT_READ_STATE_NEED_TYPE; } /** {@inheritDoc} */ @Override public void readEndExplicitTag() throws DecodeException, IOException { readEndSequence(); } /** {@inheritDoc} */ @Override public void readEndSet() throws IOException { // From an implementation point of view, a set is equivalent to a // sequence. readEndSequence(); } /** {@inheritDoc} */ @Override public int readEnumerated() throws IOException { // Read the header if haven't done so already peekLength(); @@ -178,7 +175,7 @@ return (int) readInteger(); } /** {@inheritDoc} */ @Override public long readInteger() throws IOException { // Read the header if haven't done so already peekLength(); @@ -195,7 +192,7 @@ if (peekLength > 4) { long longValue = 0; for (int i = 0; i < peekLength; i++) { final int readByte = reader.get(); final int readByte = reader.readByte(); if (i == 0 && readByte < 0) { longValue = 0xFFFFFFFFFFFFFFFFL; } @@ -207,7 +204,7 @@ } else { int intValue = 0; for (int i = 0; i < peekLength; i++) { final int readByte = reader.get(); final int readByte = reader.readByte(); if (i == 0 && readByte < 0) { intValue = 0xFFFFFFFF; } @@ -219,7 +216,7 @@ } } /** {@inheritDoc} */ @Override public void readNull() throws IOException { // Read the header if haven't done so already peekLength(); @@ -233,7 +230,7 @@ state = ASN1.ELEMENT_READ_STATE_NEED_TYPE; } /** {@inheritDoc} */ @Override public ByteString readOctetString() throws IOException { // Read the header if haven't done so already peekLength(); @@ -245,10 +242,10 @@ } state = ASN1.ELEMENT_READ_STATE_NEED_TYPE; return reader.getByteString(peekLength); return reader.readByteString(peekLength); } /** {@inheritDoc} */ @Override public ByteStringBuilder readOctetString(final ByteStringBuilder builder) throws IOException { // Read the header if haven't done so already peekLength(); @@ -265,7 +262,7 @@ return builder; } /** {@inheritDoc} */ @Override public String readOctetStringAsString() throws IOException { // Read the header if haven't done so already peekLength(); @@ -277,10 +274,10 @@ } state = ASN1.ELEMENT_READ_STATE_NEED_TYPE; return reader.getString(peekLength); return reader.readStringUtf8(peekLength); } /** {@inheritDoc} */ @Override public void readStartSequence() throws IOException { // Read the header if haven't done so already peekLength(); @@ -291,7 +288,7 @@ throw DecodeException.fatalError(message); } final ByteSequenceReader subByteString = reader.getByteSequence(peekLength).asReader(); final ByteSequenceReader subByteString = reader.readByteSequence(peekLength).asReader(); readerStack.addFirst(reader); reader = subByteString; @@ -299,20 +296,19 @@ state = ASN1.ELEMENT_READ_STATE_NEED_TYPE; } /** {@inheritDoc} */ @Override public void readStartExplicitTag() throws DecodeException, IOException { readStartSequence(); } /** {@inheritDoc} */ @Override public void readStartSet() throws IOException { // From an implementation point of view, a set is equivalent to a // sequence. readStartSequence(); } /** {@inheritDoc} */ @Override public ASN1Reader skipElement() throws IOException { // Read the header if haven't done so already peekLength(); @@ -346,7 +342,7 @@ } return false; } int readByte = reader.get(); int readByte = reader.readByte(); peekLength = (readByte & 0x7F); if (peekLength != readByte) { int lengthBytesNeeded = peekLength; @@ -367,7 +363,7 @@ } while (lengthBytesNeeded > 0) { readByte = reader.get(); readByte = reader.readByte(); peekLength = (peekLength << 8) | (readByte & 0xFF); lengthBytesNeeded--; } @@ -405,7 +401,7 @@ } return false; } final int type = reader.get(); final int type = reader.readByte(); peekType = (byte) type; state = ASN1.ELEMENT_READ_STATE_NEED_FIRST_LENGTH_BYTE; opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/ByteSequenceReader.java
@@ -68,34 +68,33 @@ } /** * Relative get method. Reads the byte at the current position. * Relative read method. Reads the byte at the current position. * * @return The byte at this reader's current position. * @throws IndexOutOfBoundsException * If there are fewer bytes remaining in this reader than are * required to satisfy the request, that is, if * {@code remaining() * < 1}. * {@code remaining() < 1}. */ public byte get() { public byte readByte() { final byte b = sequence.byteAt(pos); pos++; return b; } /** * Relative bulk get method. This method transfers bytes from this reader * Relative bulk read method. This method transfers bytes from this reader * into the given destination array. An invocation of this method of the * form: * * <pre> * src.get(b); * src.readBytes(b); * </pre> * * Behaves in exactly the same way as the invocation: * * <pre> * src.get(b, 0, b.length); * src.readBytes(b, 0, b.length); * </pre> * * @param b @@ -103,29 +102,28 @@ * @throws IndexOutOfBoundsException * If there are fewer bytes remaining in this reader than are * required to satisfy the request, that is, if * {@code remaining() * < b.length}. * {@code remaining() < b.length}. */ public void get(final byte[] b) { get(b, 0, b.length); public void readBytes(final byte[] b) { readBytes(b, 0, b.length); } /** * Relative bulk get method. Copies {@code length} bytes from this reader * Relative bulk read method. Copies {@code length} bytes from this reader * into the given array, starting at the current position of this reader and * at the given {@code offset} in the array. The position of this reader is * then incremented by {@code length}. In other words, an invocation of this * method of the form: * * <pre> * src.get(b, offset, length); * src.read(b, offset, length); * </pre> * * Has exactly the same effect as the loop: * * <pre> * for (int i = offset; i < offset + length; i++) * b[i] = src.get(); * b[i] = src.readByte(); * </pre> * * Except that it first checks that there are sufficient bytes in this @@ -142,10 +140,9 @@ * @throws IndexOutOfBoundsException * If there are fewer bytes remaining in this reader than are * required to satisfy the request, that is, if * {@code remaining() * < length}. * {@code remaining() < length}. */ public void get(final byte[] b, final int offset, final int length) { public void readBytes(final byte[] b, final int offset, final int length) { if (offset < 0 || length < 0 || offset + length > b.length || length > remaining()) { throw new IndexOutOfBoundsException(); } @@ -155,7 +152,7 @@ } /** * Relative get method for reading a multi-byte BER length. Reads the next * Relative read method for reading a multi-byte BER length. Reads the next * one to five bytes at this reader's current position, composing them into * a integer value and then increments the position by the number of bytes * read. @@ -166,7 +163,7 @@ * If there are fewer bytes remaining in this reader than are * required to satisfy the request. */ public int getBERLength() { public int readBERLength() { // Make sure we have at least one byte to read. int newPos = pos + 1; if (newPos > sequence.length()) { @@ -195,7 +192,7 @@ } /** * Relative bulk get method. Returns a {@link ByteSequence} whose content is * Relative bulk read method. Returns a {@link ByteSequence} whose content is * the next {@code length} bytes from this reader, starting at the current * position of this reader. The position of this reader is then incremented * by {@code length}. @@ -211,10 +208,9 @@ * @throws IndexOutOfBoundsException * If there are fewer bytes remaining in this reader than are * required to satisfy the request, that is, if * {@code remaining() * < length}. * {@code remaining() < length}. */ public ByteSequence getByteSequence(final int length) { public ByteSequence readByteSequence(final int length) { final int newPos = pos + length; final ByteSequence subSequence = sequence.subSequence(pos, newPos); pos = newPos; @@ -222,7 +218,7 @@ } /** * Relative bulk get method. Returns a {@link ByteString} whose content is * Relative bulk read method. Returns a {@link ByteString} whose content is * the next {@code length} bytes from this reader, starting at the current * position of this reader. The position of this reader is then incremented * by {@code length}. @@ -230,13 +226,13 @@ * An invocation of this method of the form: * * <pre> * src.getByteString(length); * src.readByteString(length); * </pre> * * Has exactly the same effect as: * * <pre> * src.getByteSequence(length).toByteString(); * src.readByteSequence(length).toByteString(); * </pre> * * <b>NOTE:</b> The value returned from this method should NEVER be cached @@ -250,15 +246,14 @@ * @throws IndexOutOfBoundsException * If there are fewer bytes remaining in this reader than are * required to satisfy the request, that is, if * {@code remaining() * < length}. * {@code remaining() < length}. */ public ByteString getByteString(final int length) { return getByteSequence(length).toByteString(); public ByteString readByteString(final int length) { return readByteSequence(length).toByteString(); } /** * Relative get method for reading an integer value. Reads the next four * Relative read method for reading an integer value. Reads the next four * bytes at this reader's current position, composing them into an integer * value according to big-endian byte order, and then increments the * position by four. @@ -267,10 +262,9 @@ * @throws IndexOutOfBoundsException * If there are fewer bytes remaining in this reader than are * required to satisfy the request, that is, if * {@code remaining() * < 4}. * {@code remaining() < 4}. */ public int getInt() { public int readInt() { if (remaining() < 4) { throw new IndexOutOfBoundsException(); } @@ -285,7 +279,7 @@ } /** * Relative get method for reading a long value. Reads the next eight bytes * Relative read method for reading a long value. Reads the next eight bytes * at this reader's current position, composing them into a long value * according to big-endian byte order, and then increments the position by * eight. @@ -294,10 +288,9 @@ * @throws IndexOutOfBoundsException * If there are fewer bytes remaining in this reader than are * required to satisfy the request, that is, if * {@code remaining() * < 8}. * {@code remaining() < 8}. */ public long getLong() { public long readLong() { if (remaining() < 8) { throw new IndexOutOfBoundsException(); } @@ -312,7 +305,7 @@ } /** * Relative get method for reading a compacted long value. * Relative read method for reading a compacted long value. * Compaction allows to reduce number of bytes needed to hold long 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 a long value @@ -325,7 +318,7 @@ * If there are fewer bytes remaining in this reader than are * required to satisfy the request. */ public long getCompactUnsigned() { public long readCompactUnsigned() { try { return PackedLong.readCompactUnsignedLong(asInputStream()); } catch (IOException e) { @@ -334,7 +327,7 @@ } /** * Relative get method for reading an short value. Reads the next 2 bytes at * 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 * two. @@ -343,10 +336,9 @@ * @throws IndexOutOfBoundsException * If there are fewer bytes remaining in this reader than are * required to satisfy the request, that is, if * {@code remaining() * < 2}. * {@code remaining() < 2}. */ public short getShort() { public short readShort() { if (remaining() < 2) { throw new IndexOutOfBoundsException(); } @@ -361,7 +353,7 @@ } /** * Relative get method for reading a UTF-8 encoded string. Reads the next * Relative read method for reading a UTF-8 encoded string. Reads the next * number of specified bytes at this reader's current position, decoding * them into a string using UTF-8 and then increments the position by the * number of bytes read. If UTF-8 decoding fails, the platform's default @@ -373,10 +365,9 @@ * @throws IndexOutOfBoundsException * If there are fewer bytes remaining in this reader than are * required to satisfy the request, that is, if * {@code remaining() * < length}. * {@code remaining() < length}. */ public String getString(final int length) { public String readStringUtf8(final int length) { if (remaining() < length) { throw new IndexOutOfBoundsException(); } @@ -497,7 +488,6 @@ position(pos + length); } /** {@inheritDoc} */ @Override public String toString() { return sequence.toString(); opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/ByteStringBuilder.java
@@ -439,7 +439,7 @@ if (length != 0) { ensureAdditionalCapacity(length); reader.get(buffer, this.length, length); reader.readBytes(buffer, this.length, length); this.length += length; } opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/TimeBasedMatchingRulesImpl.java
@@ -290,12 +290,12 @@ @Override public <T> T createIndexQuery(IndexQueryFactory<T> factory) throws DecodeException { final ByteSequenceReader reader = assertionValue.asReader(); int assertSecond = reader.get(); int assertMinute = reader.get(); int assertHour = reader.get(); int assertDay = reader.get(); int assertMonth = reader.get(); int assertYear = (int) reader.getCompactUnsigned(); int assertSecond = reader.readByte(); int assertMinute = reader.readByte(); int assertHour = reader.readByte(); int assertDay = reader.readByte(); int assertMonth = reader.readByte(); int assertYear = (int) reader.readCompactUnsigned(); List<T> queries = new ArrayList<>(); if (assertSecond >= 0) { @@ -501,12 +501,12 @@ // Build the information from the assertion value. ByteSequenceReader r = assertionValue.asReader(); int assertSecond = r.get(); int assertMinute = r.get(); int assertHour = r.get(); int assertDay = r.get(); int assertMonth = r.get(); int assertYear = (int) r.getCompactUnsigned(); int assertSecond = r.readByte(); int assertMinute = r.readByte(); int assertHour = r.readByte(); int assertDay = r.readByte(); int assertMonth = r.readByte(); int assertYear = (int) r.readCompactUnsigned(); // All the non-zero and non -1 values should match. return ConditionResult.valueOf( opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/UUIDEqualityMatchingRuleImpl.java
@@ -164,8 +164,8 @@ private static ByteString hash(final ByteSequence normalizeAttributeValue) { final ByteSequenceReader uuid128Bytes = normalizeAttributeValue.asReader(); final long uuidHigh64 = uuid128Bytes.getLong(); final long uuidLow64 = uuid128Bytes.getLong(); final long uuidHigh64 = uuid128Bytes.readLong(); final long uuidLow64 = uuid128Bytes.readLong(); final long uuid64 = uuidHigh64 ^ uuidLow64; final int hash32 = ((int) (uuid64 >> 32)) ^ (int) uuid64; return ByteString.valueOf(hash32); opendj-sdk/opendj-core/src/test/java/org/forgerock/opendj/ldap/ByteSequenceReaderTest.java
@@ -56,18 +56,18 @@ } @Test(dataProvider = "readerProvider", expectedExceptions = IndexOutOfBoundsException.class) public void testGet(ByteSequenceReader reader, byte[] ba) { public void testReadByte(ByteSequenceReader reader, byte[] ba) { reader.rewind(); for (byte b : ba) { Assert.assertEquals(reader.get(), b); Assert.assertEquals(reader.readByte(), b); } // The next get should result in IOB exception. reader.get(); // The next read should result in IOB exception. reader.readByte(); } @Test(dataProvider = "readerProvider", expectedExceptions = IndexOutOfBoundsException.class) public void testBulkGet(ByteSequenceReader reader, byte[] ba) { public void testReadBytes(ByteSequenceReader reader, byte[] ba) { reader.rewind(); int remaining = ba.length; @@ -78,7 +78,7 @@ } byte[] readArray = new byte[length]; reader.get(readArray); reader.readBytes(readArray); byte[] subArray = new byte[length]; System.arraycopy(ba, ba.length - remaining, subArray, 0, length); Assert.assertTrue(Arrays.equals(readArray, subArray)); @@ -86,12 +86,12 @@ remaining -= length; } // Any more gets should result in IOB exception. reader.get(new byte[1]); // Any more reads should result in IOB exception. reader.readBytes(new byte[1]); } @Test(dataProvider = "readerProvider") public void testBulkGetWithOffset(ByteSequenceReader reader, byte[] ba) { public void testReadBytesWithOffset(ByteSequenceReader reader, byte[] ba) { reader.rewind(); int remaining = ba.length; byte[] readArray = new byte[ba.length]; @@ -102,7 +102,7 @@ length = remaining % 2; } reader.get(readArray, ba.length - remaining, length); reader.readBytes(readArray, ba.length - remaining, length); remaining -= length; } @@ -111,28 +111,28 @@ } @Test(dataProvider = "readerProvider", expectedExceptions = IndexOutOfBoundsException.class) public void testNegativeOffsetBulkGet(ByteSequenceReader reader, byte[] ba) { public void testNegativeOffsetReadBytes(ByteSequenceReader reader, byte[] ba) { reader.rewind(); byte[] array = new byte[ba.length]; reader.get(array, -1, ba.length); reader.readBytes(array, -1, ba.length); } @Test(dataProvider = "readerProvider", expectedExceptions = IndexOutOfBoundsException.class) public void testNegativeLengthBulkGet(ByteSequenceReader reader, byte[] ba) { public void testNegativeLengthReadBytes(ByteSequenceReader reader, byte[] ba) { reader.rewind(); byte[] array = new byte[ba.length]; reader.get(array, 0, -1); reader.readBytes(array, 0, -1); } @Test(dataProvider = "readerProvider", expectedExceptions = IndexOutOfBoundsException.class) public void testBadOffLenBulkGet(ByteSequenceReader reader, byte[] ba) { public void testBadOffLenReadBytes(ByteSequenceReader reader, byte[] ba) { reader.rewind(); byte[] array = new byte[ba.length]; reader.get(array, 3, ba.length); reader.readBytes(array, 3, ba.length); } @Test(expectedExceptions = IndexOutOfBoundsException.class) public void testGetBERLength() { public void testReadBERLength() { ByteSequenceReader reader = ByteString.wrap(new byte[]{ b(0x00), b(0x01), b(0x0F), b(0x10), b(0x7F), @@ -170,33 +170,33 @@ }; for (int length : expectedLength) { Assert.assertEquals(reader.getBERLength(), length); Assert.assertEquals(reader.readBERLength(), length); } // Last one is incomplete and should throw error reader.getBERLength(); reader.readBERLength(); } @Test(expectedExceptions = IndexOutOfBoundsException.class) public void testOversizedGetBERLength() { public void testOversizedReadBERLength() { ByteSequenceReader reader = ByteString.wrap(new byte[]{ b(0x85), b(0x10), b(0x00), b(0x00), b(0x00), b(0x00) }).asReader(); // Shouldn't be able to reader over a 4 byte length. reader.getBERLength(); reader.readBERLength(); } @Test(expectedExceptions = IndexOutOfBoundsException.class) public void testUndersizedGetBERLength() { public void testUndersizedReadBERLength() { ByteSequenceReader reader = ByteString.empty().asReader(); // Shouldn't be able to reader over a 4 byte length. reader.getBERLength(); reader.readBERLength(); } @Test(dataProvider = "readerProvider", expectedExceptions = IndexOutOfBoundsException.class) public void testGetByteSequence(ByteSequenceReader reader, byte[] ba) { public void testReadByteSequence(ByteSequenceReader reader, byte[] ba) { reader.rewind(); int remaining = ba.length; @@ -206,7 +206,7 @@ length = remaining % 2; } ByteSequence readSequence = reader.getByteSequence(length); ByteSequence readSequence = reader.readByteSequence(length); byte[] subArray = new byte[length]; System.arraycopy(ba, ba.length - remaining, subArray, 0, length); Assert.assertTrue(Arrays.equals(readSequence.toByteArray(), subArray)); @@ -214,12 +214,12 @@ remaining -= length; } // Any more gets should result in IOB exception. reader.getByteSequence(1); // Any more reads should result in IOB exception. reader.readByteSequence(1); } @Test(dataProvider = "readerProvider", expectedExceptions = IndexOutOfBoundsException.class) public void testGetByteString(ByteSequenceReader reader, byte[] ba) { public void testReadByteString(ByteSequenceReader reader, byte[] ba) { reader.rewind(); int remaining = ba.length; @@ -229,7 +229,7 @@ length = remaining % 2; } ByteString readSequence = reader.getByteString(length); ByteString readSequence = reader.readByteString(length); byte[] subArray = new byte[length]; System.arraycopy(ba, ba.length - remaining, subArray, 0, length); Assert.assertTrue(Arrays.equals(readSequence.toByteArray(), subArray)); @@ -237,53 +237,53 @@ remaining -= length; } // Any more gets should result in IOB exception. reader.getByteString(1); // Any more reads should result in IOB exception. reader.readByteString(1); } @Test(expectedExceptions = IndexOutOfBoundsException.class) public void testGetShort() { public void testReadShort() { ByteSequenceReader reader = ByteString.wrap(new byte[]{ b(0x80), b(0x00), b(0x7F), b(0xFF), b(0xFF) }).asReader(); Assert.assertEquals(reader.getShort(), Short.MIN_VALUE); Assert.assertEquals(reader.getShort(), Short.MAX_VALUE); Assert.assertEquals(reader.readShort(), Short.MIN_VALUE); Assert.assertEquals(reader.readShort(), Short.MAX_VALUE); // Any more gets should result in IOB exception. reader.getShort(); // Any more reads should result in IOB exception. reader.readShort(); } @Test(expectedExceptions = IndexOutOfBoundsException.class) public void testGetInt() { public void testReadInt() { ByteSequenceReader reader = ByteString.wrap(new byte[]{ b(0x80), b(0x00), b(0x00), b(0x00), b(0x7F), b(0xFF), b(0xFF), b(0xFF), b(0xFF) }).asReader(); Assert.assertEquals(reader.getInt(), Integer.MIN_VALUE); Assert.assertEquals(reader.getInt(), Integer.MAX_VALUE); Assert.assertEquals(reader.readInt(), Integer.MIN_VALUE); Assert.assertEquals(reader.readInt(), Integer.MAX_VALUE); // Any more gets should result in IOB exception. reader.getInt(); // Any more reads should result in IOB exception. reader.readInt(); } @Test(expectedExceptions = IndexOutOfBoundsException.class) public void testGetLong() { public void testReadLong() { ByteSequenceReader reader = ByteString.wrap(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), b(0xFF) }).asReader(); Assert.assertEquals(reader.getLong(), Long.MIN_VALUE); Assert.assertEquals(reader.getLong(), Long.MAX_VALUE); Assert.assertEquals(reader.readLong(), Long.MIN_VALUE); Assert.assertEquals(reader.readLong(), Long.MAX_VALUE); // Any more gets should result in IOB exception. reader.getLong(); // Any more reads should result in IOB exception. reader.readLong(); } @Test(dataProvider = "readerProvider", expectedExceptions = IndexOutOfBoundsException.class) public void testGetString(ByteSequenceReader reader, byte[] ba) { public void testReadString(ByteSequenceReader reader, byte[] ba) { reader.rewind(); int remaining = ba.length; @@ -293,15 +293,15 @@ length = remaining % 2; } String readString = reader.getString(length); String readString = reader.readStringUtf8(length); String subString = new String(ba, ba.length - remaining, length); Assert.assertTrue(readString.equals(subString)); remaining -= length; } // Any more gets should result in IOB exception. reader.getString(1); // Any more reads should result in IOB exception. reader.readStringUtf8(1); } @Test(dataProvider = "readerProvider", expectedExceptions = IndexOutOfBoundsException.class) @@ -310,7 +310,7 @@ for (int i = 0; i < ba.length; i++) { reader.position(i); String readString = reader.getString(ba.length - i); String readString = reader.readStringUtf8(ba.length - i); String subString = new String(ba, i, ba.length - i); Assert.assertTrue(readString.equals(subString)); } @@ -376,5 +376,4 @@ } } } } opendj-sdk/opendj-core/src/test/java/org/forgerock/opendj/ldap/ByteStringBuilderTestCase.java
@@ -87,8 +87,8 @@ @Test(dataProvider = "unsignedLongValues") public void testCanAppendCompactPositiveValue(long value) { assertThat(new ByteStringBuilder().appendCompactUnsigned(value).asReader().getCompactUnsigned()).isEqualTo( value); assertThat(new ByteStringBuilder().appendCompactUnsigned(value).asReader().readCompactUnsigned()) .isEqualTo(value); } @DataProvider @@ -243,11 +243,11 @@ @Test public void testAsOutputStream() throws Exception { final ByteStringBuilder bsb = new ByteStringBuilder(); final OutputStream os = bsb.asOutputStream(); try (final OutputStream os = bsb.asOutputStream()) { os.write(b(0x01)); os.write(2); os.write(new byte[] { 2, 3, 4, 5 }, 1, 2); os.close(); } Assert.assertEquals(bsb.length(), 4); Assert.assertEquals(bsb.toByteArray(), new byte[] { 1, 2, 3, 4 }); } @@ -256,15 +256,15 @@ public void testAsOutputStreamCompress() throws Exception { final ByteString data = ByteString.wrap(new byte[4000]); final ByteStringBuilder compressedData = new ByteStringBuilder(); final OutputStream compressor = new DeflaterOutputStream(compressedData.asOutputStream()); try (final OutputStream compressor = new DeflaterOutputStream(compressedData.asOutputStream())) { data.copyTo(compressor); compressor.close(); } Assert.assertTrue(compressedData.length() > 0 && compressedData.length() < 4000); final ByteStringBuilder decompressedData = new ByteStringBuilder(); final OutputStream decompressor = new InflaterOutputStream(decompressedData.asOutputStream()); try (final OutputStream decompressor = new InflaterOutputStream(decompressedData.asOutputStream())) { compressedData.copyTo(decompressor); decompressor.close(); } Assert.assertEquals(decompressedData.toByteString(), data); }