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.
| | |
| | | <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> |
| | |
| | | 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; |
| | |
| | | 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); |
| | |
| | | * @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; |
| | | } |
| | |
| | | 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(); |
| | | } |
| | |
| | | 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; |
| | |
| | | } |
| | | |
| | | 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; |
| | | } |
| | |
| | | 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); |
| | |
| | | |
| | | 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. */ |
| | |
| | | |
| | | @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); |
| | | } |
| | | } |
| | | |
| | |
| | | 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) { |
| | |
| | | return buffer[subOffset + index]; |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public int compareTo(final byte[] b, final int offset, final int length) { |
| | | ByteString.checkArrayBounds(b, offset, length); |
| | |
| | | return ByteString.compareTo(buffer, subOffset, subLength, b, offset, length); |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public int compareTo(final ByteSequence o) { |
| | | if (this == o) { |
| | |
| | | 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) { |
| | |
| | | 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. |
| | |
| | | return stream; |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public boolean equals(final byte[] b, final int offset, final int length) { |
| | | ByteString.checkArrayBounds(b, offset, length); |
| | |
| | | return ByteString.equals(buffer, subOffset, subLength, b, offset, length); |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public boolean equals(final Object o) { |
| | | if (this == o) { |
| | |
| | | } |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public int hashCode() { |
| | | // Protect against reallocation: use builder's buffer. |
| | |
| | | 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) { |
| | |
| | | return new SubSequence(subOffset + start, end - start); |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public boolean startsWith(ByteSequence prefix) { |
| | | if (prefix == null || prefix.length() > length) { |
| | |
| | | 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. |
| | |
| | | return ByteString.wrap(b); |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public String toString() { |
| | | // Protect against reallocation: use builder's buffer. |
| | |
| | | */ |
| | | 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); |
| | |
| | | * 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; |
| | | } |
| | | |
| | |
| | | * 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); |
| | | } |
| | | |
| | | /** |
| | |
| | | * 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) { |
| | |
| | | * 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(); |
| | | } |
| | |
| | | * 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 |
| | |
| | | * 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(); |
| | | } |
| | |
| | | * 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; |
| | | } |
| | |
| | | * @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(); |
| | | } |
| | |
| | | * @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(); |
| | | } |
| | |
| | | * 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); |
| | |
| | | * 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); |
| | |
| | | * 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 |
| | |
| | | * 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()); |
| | | } |
| | | } |
| | | |
| | |
| | | * 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); |
| | |
| | | * string builder. |
| | | * @return This byte string builder. |
| | | */ |
| | | public ByteStringBuilder append(final String s) { |
| | | public ByteStringBuilder appendUtf8(final String s) { |
| | | if (s == null) { |
| | | return this; |
| | | } |
| | |
| | | } 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); |
| | |
| | | return new ByteSequenceReader(this); |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public byte byteAt(final int index) { |
| | | if (index >= length || index < 0) { |
| | |
| | | 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) { |
| | |
| | | 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) { |
| | |
| | | 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); |
| | |
| | | return this; |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public boolean equals(final byte[] bytes, final int offset, final int length) { |
| | | ByteString.checkArrayBounds(bytes, offset, length); |
| | |
| | | return ByteString.hashCode(buffer, 0, length); |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public boolean isEmpty() { |
| | | return length == 0; |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public int length() { |
| | | return length; |
| | |
| | | return new SubSequence(start, end - start); |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public boolean startsWith(ByteSequence prefix) { |
| | | if (prefix == null || prefix.length() > length) { |
| | |
| | | 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]); |
| | |
| | | return ByteString.wrap(b); |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public String toString() { |
| | | return ByteString.toString(buffer, 0, length); |
| | |
| | | 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); |
| | | } |
| | |
| | | throw new LocalizedIllegalArgumentException(message); |
| | | } |
| | | |
| | | valueBuffer.append(byteValue); |
| | | valueBuffer.appendByte(byteValue); |
| | | } else { |
| | | valueBuffer.append(valueBytes[i]); |
| | | valueBuffer.appendByte(valueBytes[i]); |
| | | } |
| | | } |
| | | } |
| | |
| | | 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); |
| | |
| | | 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; |
| | |
| | | this.normFinal = normFinal; |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public ConditionResult matches(final ByteSequence normalizedAttributeValue) { |
| | | final int valueLength = normalizedAttributeValue.length(); |
| | |
| | | return ConditionResult.TRUE; |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public <T> T createIndexQuery(IndexQueryFactory<T> factory) throws DecodeException { |
| | | if (normInitial == null && (normAnys == null || normAnys.length == 0) && normFinal == null) { |
| | |
| | | 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); |
| | |
| | | return AbstractSubstringMatchingRuleImpl.this.keyToHumanReadableString(key); |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public String getIndexID() { |
| | | return indexID; |
| | |
| | | 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()); |
| | | } |
| | |
| | | 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) |
| | |
| | | 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; |
| | |
| | | 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) { |
| | |
| | | |
| | | reader.reset(); |
| | | if (valueBuffer != null) { |
| | | valueBuffer.append(reader.read(length)); |
| | | valueBuffer.appendUtf8(reader.read(length)); |
| | | return valueBuffer.toByteString(); |
| | | } else { |
| | | if (length > 0) { |
| | |
| | | } |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public final Collection<? extends Indexer> createIndexers(IndexingOptions options) { |
| | | return Collections.singleton(new SubstringIndexer(options.substringKeySize())); |
| | | } |
| | | |
| | | } |
| | |
| | | */ |
| | | 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() { |
| | |
| | | return createEncodedValue(serialNumber, certificateIssuer); |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public Assertion getAssertion(final Schema schema, final ByteSequence value) |
| | | throws DecodeException { |
| | |
| | | * @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(); |
| | | } |
| | | |
| | | } |
| | |
| | | |
| | | // 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(); |
| | |
| | | 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); |
| | | } |
| | | } |
| | | |
| | |
| | | // 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) { |
| | |
| | | } |
| | | |
| | | private ByteString getKey(int value, char type) { |
| | | return new ByteStringBuilder().append(type).append(value).toByteString(); |
| | | return new ByteStringBuilder().appendInt(type).appendInt(value).toByteString(); |
| | | } |
| | | } |
| | | |
| | |
| | | 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; |
| | | } |
| | | } |
| | |
| | | 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()); |
| | | } |
| | |
| | | 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(); |
| | |
| | | @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)); |
| | | } |
| | |
| | | @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")); |
| | |
| | | @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")); |
| | |
| | | @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); |
| | |
| | | @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); |
| | |
| | | * |
| | | * |
| | | * Copyright 2009 Sun Microsystems, Inc. |
| | | * Portions Copyright 2014 ForgeRock AS |
| | | * Portions Copyright 2014-2015 ForgeRock AS |
| | | */ |
| | | package org.forgerock.opendj.ldap; |
| | | |
| | |
| | | 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 } |
| | | }; |
| | | } |
| | | |
| | |
| | | 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; |
| | |
| | | |
| | | @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); |
| | | } |
| | | |
| | |
| | | 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; |
| | | } |
| | |
| | | @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); |
| | |
| | | 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) } }, |
| | |
| | | @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); |
| | |
| | | @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"); |
| | |
| | | @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); |
| | |
| | | @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(), "œŒ"); |
| | | } |
| | | |
| | |
| | | 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()); |
| | | } |
| | | } |
| | |
| | | |
| | | @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(""); |
| | |
| | | |
| | | @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"); |
| | | } |
| | |
| | | @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(); |
| | | |
| | |
| | | @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(); |
| | | |
| | |
| | | @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); |
| | |
| | | @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); |
| | |
| | | private String expected(int... bytes) { |
| | | ByteStringBuilder builder = new ByteStringBuilder(); |
| | | for (int b : bytes) { |
| | | builder.append((byte) b); |
| | | builder.appendByte(b); |
| | | } |
| | | return builder.toByteString().toHexString(); |
| | | } |
| | |
| | | * |
| | | * |
| | | * Copyright 2010 Sun Microsystems, Inc. |
| | | * Portions copyright 2012-2014 ForgeRock AS. |
| | | * Portions copyright 2012-2015 ForgeRock AS. |
| | | */ |
| | | package org.forgerock.opendj.grizzly; |
| | | |
| | |
| | | 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; |
| | |
| | | // 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); |
| | |
| | | * |
| | | * |
| | | * Copyright 2010 Sun Microsystems, Inc. |
| | | * Portions copyright 2012-2014 ForgeRock AS. |
| | | * Portions copyright 2012-2015 ForgeRock AS. |
| | | */ |
| | | package org.forgerock.opendj.grizzly; |
| | | |
| | |
| | | |
| | | 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; |
| | |
| | | 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); |
| | | } |
| | | } |
| | | |
| | |
| | | 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; |
| | |
| | | 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; |
| | |
| | | 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); |
| | | } |
| | | } |
| | | } |