public override ByteBuffer Slice() { ReadWriteHeapByteBuffer slice = new ReadWriteHeapByteBuffer( backingArray, Remaining, offset + position); slice.order = order; return(slice); }
internal static ReadWriteHeapByteBuffer Copy(HeapByteBuffer other, int markOfOther) { ReadWriteHeapByteBuffer buf = new ReadWriteHeapByteBuffer( other.backingArray, other.Capacity, other.offset); buf.limit = other.Limit; buf.position = other.Position; buf.mark = markOfOther; buf.SetOrder(other.Order); return(buf); }
/// <summary> /// Creates a new byte buffer by wrapping the given byte array. /// <para/> /// The new buffer's position will be <paramref name="start"/>, limit will be /// <c>start + len</c>, capacity will be the length of the array. /// </summary> /// <param name="array">The byte array which the new buffer will be based on.</param> /// <param name="start"> /// The start index, must not be negative and not greater than <c>array.Length</c>. /// </param> /// <param name="length"> /// The length, must not be negative and not greater than /// <c>array.Length - start</c>. /// </param> /// <returns>The new byte buffer</returns> /// <exception cref="IndexOutOfRangeException">if either <paramref name="start"/> or <paramref name="length"/> are invalid.</exception> public static ByteBuffer Wrap(byte[] array, int start, int length) { int actualLength = array.Length; if ((start < 0) || (length < 0) || ((long)start + (long)length > actualLength)) { throw new ArgumentOutOfRangeException(); } ByteBuffer buf = new ReadWriteHeapByteBuffer(array); buf.position = start; buf.limit = start + length; return(buf); }