Java Arrays.checkOffsetAndCount Examples

Java Arrays.checkOffsetAndCount - 9 examples found. These are the top rated real world Java examples of java.util.Arrays.checkOffsetAndCount extracted from open source projects. You can rate examples to help us improve the quality of examples.
Example #1
0
 /**
  * Creates a new byte buffer by wrapping the given byte array.
  *
  * <p>The new buffer's position will be {@code start}, limit will be {@code start + byteCount},
  * capacity will be the length of the array.
  *
  * @param array the byte array which the new buffer will be based on.
  * @param start the start index, must not be negative and not greater than {@code array.length}.
  * @param byteCount the length, must not be negative and not greater than {@code array.length -
  *     start}.
  * @return the created byte buffer.
  * @throws IndexOutOfBoundsException if either {@code start} or {@code byteCount} is invalid.
  */
 public static ByteBuffer wrap(byte[] array, int start, int byteCount) {
   Arrays.checkOffsetAndCount(array.length, start, byteCount);
   ByteBuffer buf = new ByteArrayBuffer(array);
   buf.position = start;
   buf.limit = start + byteCount;
   return buf;
 }
Example #2
0
 /**
  * Creates a new int buffer by wrapping the given int array.
  *
  * <p>The new buffer's position will be {@code start}, limit will be {@code start + intCount},
  * capacity will be the length of the array.
  *
  * @param array the int array which the new buffer will be based on.
  * @param start the start index, must not be negative and not greater than {@code array.length}
  * @param intCount the length, must not be negative and not greater than {@code array.length -
  *     start}.
  * @return the created int buffer.
  * @exception IndexOutOfBoundsException if either {@code start} or {@code intCount} is invalid.
  */
 public static IntBuffer wrap(int[] array, int start, int intCount) {
   Arrays.checkOffsetAndCount(array.length, start, intCount);
   IntBuffer buf = new IntArrayBuffer(array);
   buf.position = start;
   buf.limit = start + intCount;
   return buf;
 }
Example #3
0
 private synchronized int deflateImpl(byte[] buf, int offset, int byteCount, int flush) {
   checkOpen();
   Arrays.checkOffsetAndCount(buf.length, offset, byteCount);
   if (inputBuffer == null) {
     setInput(EmptyArray.BYTE);
   }
   return deflateImpl(buf, offset, byteCount, streamHandle, flush);
 }
 /**
  * Writes {@code count} characters starting at {@code offset} in {@code buf} to this writer's
  * {@code StringBuffer}.
  *
  * @param chars the non-null character array to write.
  * @param offset the index of the first character in {@code chars} to write.
  * @param count the maximum number of characters to write.
  * @throws IndexOutOfBoundsException if {@code offset < 0} or {@code count < 0}, or if {@code
  *     offset + count} is greater than the size of {@code buf}.
  */
 @Override
 public void write(char[] chars, int offset, int count) {
   Arrays.checkOffsetAndCount(chars.length, offset, count);
   if (count == 0) {
     return;
   }
   buf.append(chars, offset, count);
 }
Example #5
0
 /**
  * Writes bytes in the given byte array, starting from the specified offset, to the current
  * position and increases the position by the number of bytes written.
  *
  * @param src the source byte array.
  * @param srcOffset the offset of byte array, must not be negative and not greater than {@code
  *     src.length}.
  * @param byteCount the number of bytes to write, must not be negative and not greater than {@code
  *     src.length - srcOffset}.
  * @return {@code this}
  * @throws BufferOverflowException if {@code remaining()} is less than {@code byteCount}.
  * @throws IndexOutOfBoundsException if either {@code srcOffset} or {@code byteCount} is invalid.
  * @throws ReadOnlyBufferException if no changes may be made to the contents of this buffer.
  */
 public ByteBuffer put(byte[] src, int srcOffset, int byteCount) {
   Arrays.checkOffsetAndCount(src.length, srcOffset, byteCount);
   if (byteCount > remaining()) {
     throw new BufferOverflowException();
   }
   for (int i = srcOffset; i < srcOffset + byteCount; ++i) {
     put(src[i]);
   }
   return this;
 }
Example #6
0
 /**
  * Reads bytes from the current position into the specified byte array, starting at the specified
  * offset, and increases the position by the number of bytes read.
  *
  * @param dst the target byte array.
  * @param dstOffset the offset of the byte array, must not be negative and not greater than {@code
  *     dst.length}.
  * @param byteCount the number of bytes to read, must not be negative and not greater than {@code
  *     dst.length - dstOffset}
  * @return {@code this}
  * @throws IndexOutOfBoundsException if {@code dstOffset < 0 || byteCount < 0}
  * @throws BufferUnderflowException if {@code byteCount > remaining()}
  */
 public ByteBuffer get(byte[] dst, int dstOffset, int byteCount) {
   Arrays.checkOffsetAndCount(dst.length, dstOffset, byteCount);
   if (byteCount > remaining()) {
     throw new BufferUnderflowException();
   }
   for (int i = dstOffset; i < dstOffset + byteCount; ++i) {
     dst[i] = get();
   }
   return this;
 }