| | |
| | | * |
| | | * |
| | | * Copyright 2009-2010 Sun Microsystems, Inc. |
| | | * Portions copyright 2011 ForgeRock AS |
| | | * Portions copyright 2011-2012 ForgeRock AS |
| | | */ |
| | | package org.forgerock.opendj.ldap; |
| | | |
| | |
| | | * if {@code offset + length} is greater than {@code bytes.length}. |
| | | */ |
| | | public static ByteString wrap(final byte[] bytes, final int offset, |
| | | final int length) throws IndexOutOfBoundsException |
| | | final int length) |
| | | { |
| | | checkArrayBounds(bytes, offset, length); |
| | | return new ByteString(bytes, offset, length); |
| | |
| | | * if {@code offset + length} is greater than {@code b.length}. |
| | | */ |
| | | static void checkArrayBounds(final byte[] b, final int offset, |
| | | final int length) throws IndexOutOfBoundsException |
| | | final int length) |
| | | { |
| | | if (offset < 0 || offset > b.length || length < 0 |
| | | || offset + length > b.length || offset + length < 0) |
| | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | public byte byteAt(final int index) throws IndexOutOfBoundsException |
| | | public byte byteAt(final int index) |
| | | { |
| | | if (index >= length || index < 0) |
| | | { |
| | |
| | | * {@inheritDoc} |
| | | */ |
| | | public int compareTo(final byte[] bytes, final int offset, final int length) |
| | | throws IndexOutOfBoundsException |
| | | { |
| | | checkArrayBounds(bytes, offset, length); |
| | | return compareTo(this.buffer, this.offset, this.length, bytes, offset, |
| | |
| | | * {@inheritDoc} |
| | | */ |
| | | public byte[] copyTo(final byte[] bytes, final int offset) |
| | | throws IndexOutOfBoundsException |
| | | { |
| | | if (offset < 0) |
| | | { |
| | |
| | | * {@inheritDoc} |
| | | */ |
| | | public boolean equals(final byte[] bytes, final int offset, final int length) |
| | | throws IndexOutOfBoundsException |
| | | { |
| | | checkArrayBounds(bytes, offset, length); |
| | | return equals(this.buffer, this.offset, this.length, bytes, offset, length); |
| | |
| | | * {@inheritDoc} |
| | | */ |
| | | public ByteString subSequence(final int start, final int end) |
| | | throws IndexOutOfBoundsException |
| | | { |
| | | if (start < 0 || start > end || end > length) |
| | | { |
| | |
| | | * @throws IndexOutOfBoundsException |
| | | * If this byte string has less than four bytes. |
| | | */ |
| | | public int toInt() throws IndexOutOfBoundsException |
| | | public int toInt() |
| | | { |
| | | if (length < 4) |
| | | { |
| | |
| | | * @throws IndexOutOfBoundsException |
| | | * If this byte string has less than eight bytes. |
| | | */ |
| | | public long toLong() throws IndexOutOfBoundsException |
| | | public long toLong() |
| | | { |
| | | if (length < 8) |
| | | { |