Freigeben über


ByteBuffer.Put Method

Definition

Overloads

Put(ByteBuffer)

Relative bulk put method  (optional operation).

Put(Byte[])

Relative bulk put method  (optional operation).

Put(SByte)

Relative put method  (optional operation).

Put(Int32, Byte[])

Absolute bulk put method  (optional operation).

Put(Int32, SByte)

Absolute put method  (optional operation).

Put(Byte[], Int32, Int32)

Relative bulk put method  (optional operation).

Put(Int32, ByteBuffer, Int32, Int32)

Absolute bulk put method  (optional operation).

Put(Int32, Byte[], Int32, Int32)

Absolute bulk put method  (optional operation).

Put(ByteBuffer)

Relative bulk put method  (optional operation).

[Android.Runtime.Register("put", "(Ljava/nio/ByteBuffer;)Ljava/nio/ByteBuffer;", "GetPut_Ljava_nio_ByteBuffer_Handler")]
public virtual Java.Nio.ByteBuffer Put (Java.Nio.ByteBuffer src);
[<Android.Runtime.Register("put", "(Ljava/nio/ByteBuffer;)Ljava/nio/ByteBuffer;", "GetPut_Ljava_nio_ByteBuffer_Handler")>]
abstract member Put : Java.Nio.ByteBuffer -> Java.Nio.ByteBuffer
override this.Put : Java.Nio.ByteBuffer -> Java.Nio.ByteBuffer

Parameters

src
ByteBuffer

The source buffer from which bytes are to be read; must not be this buffer

Returns

This buffer

Attributes

Exceptions

if src.remaining() is greater than this buffer's remaining().

if src is this buffer.

if no changes may be made to the contents of this buffer.

Remarks

Relative bulk put method&nbsp;&nbsp;(optional operation).

This method transfers the bytes remaining in the given source buffer into this buffer. If there are more bytes remaining in the source buffer than in this buffer, that is, if src.remaining()&nbsp;>&nbsp;remaining(), then no bytes are transferred and a BufferOverflowException is thrown.

Otherwise, this method copies n&nbsp;=&nbsp;src.remaining() bytes from the given buffer into this buffer, starting at each buffer's current position. The positions of both buffers are then incremented by n.

In other words, an invocation of this method of the form dst.put(src) has exactly the same effect as the loop

while (src.hasRemaining())
                    dst.put(src.get()); 

except that it first checks that there is sufficient space in this buffer and it is potentially much more efficient. If this buffer and the source buffer share the same backing array or memory, then the result will be as if the source elements were first copied to an intermediate location before being written into this buffer.

Java documentation for java.nio.ByteBuffer.put(java.nio.ByteBuffer).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to

Put(Byte[])

Relative bulk put method&nbsp;&nbsp;(optional operation).

[Android.Runtime.Register("put", "([B)Ljava/nio/ByteBuffer;", "")]
public Java.Nio.ByteBuffer Put (byte[] src);
[<Android.Runtime.Register("put", "([B)Ljava/nio/ByteBuffer;", "")>]
member this.Put : byte[] -> Java.Nio.ByteBuffer

Parameters

src
Byte[]

The source array

Returns

This buffer

Attributes

Exceptions

if remaining() is less than src.length.

if no changes may be made to the contents of this buffer.

Remarks

Relative bulk put method&nbsp;&nbsp;(optional operation).

This method transfers the entire content of the given source byte array into this buffer. An invocation of this method of the form dst.put(a) behaves in exactly the same way as the invocation

dst.put(a, 0, a.length)

Java documentation for java.nio.ByteBuffer.put(byte[]).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to

Put(SByte)

Relative put method&nbsp;&nbsp;(optional operation).

[Android.Runtime.Register("put", "(B)Ljava/nio/ByteBuffer;", "GetPut_BHandler")]
public abstract Java.Nio.ByteBuffer Put (sbyte b);
[<Android.Runtime.Register("put", "(B)Ljava/nio/ByteBuffer;", "GetPut_BHandler")>]
abstract member Put : sbyte -> Java.Nio.ByteBuffer

Parameters

b
SByte

The byte to be written

Returns

This buffer

Attributes

Exceptions

if position is equal or greater than limit.

if no changes may be made to the contents of this buffer.

Remarks

Relative put method&nbsp;&nbsp;(optional operation).

Writes the given byte into this buffer at the current position, and then increments the position.

Java documentation for java.nio.ByteBuffer.put(byte).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to

Put(Int32, Byte[])

Absolute bulk put method&nbsp;&nbsp;(optional operation).

[Android.Runtime.Register("put", "(I[B)Ljava/nio/ByteBuffer;", "GetPut_IarrayBHandler", ApiSince=35)]
public virtual Java.Nio.ByteBuffer Put (int index, byte[] src);
[<Android.Runtime.Register("put", "(I[B)Ljava/nio/ByteBuffer;", "GetPut_IarrayBHandler", ApiSince=35)>]
abstract member Put : int * byte[] -> Java.Nio.ByteBuffer
override this.Put : int * byte[] -> Java.Nio.ByteBuffer

Parameters

index
Int32

The index in this buffer at which the first byte will be written; must be non-negative and less than limit()

src
Byte[]

The array from which bytes are to be read

Returns

This buffer

Attributes

Remarks

Absolute bulk put method&nbsp;&nbsp;(optional operation).

This method copies bytes into this buffer from the given source array. The position of this buffer is unchanged. An invocation of this method of the form dst.put(index,&nbsp;src) behaves in exactly the same way as the invocation:

dst.put(index, src, 0, src.length);

Added in 13.

Java documentation for java.nio.ByteBuffer.put(int, byte[]).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to

Put(Int32, SByte)

Absolute put method&nbsp;&nbsp;(optional operation).

[Android.Runtime.Register("put", "(IB)Ljava/nio/ByteBuffer;", "GetPut_IBHandler")]
public abstract Java.Nio.ByteBuffer Put (int index, sbyte b);
[<Android.Runtime.Register("put", "(IB)Ljava/nio/ByteBuffer;", "GetPut_IBHandler")>]
abstract member Put : int * sbyte -> Java.Nio.ByteBuffer

Parameters

index
Int32

The index at which the byte will be written

b
SByte

The byte value to be written

Returns

This buffer

Attributes

Exceptions

if index is invalid.

if no changes may be made to the contents of this buffer.

Remarks

Absolute put method&nbsp;&nbsp;(optional operation).

Writes the given byte into this buffer at the given index.

Java documentation for java.nio.ByteBuffer.put(int, byte).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to

Put(Byte[], Int32, Int32)

Relative bulk put method&nbsp;&nbsp;(optional operation).

[Android.Runtime.Register("put", "([BII)Ljava/nio/ByteBuffer;", "GetPut_arrayBIIHandler")]
public virtual Java.Nio.ByteBuffer Put (byte[] src, int offset, int length);
[<Android.Runtime.Register("put", "([BII)Ljava/nio/ByteBuffer;", "GetPut_arrayBIIHandler")>]
abstract member Put : byte[] * int * int -> Java.Nio.ByteBuffer
override this.Put : byte[] * int * int -> Java.Nio.ByteBuffer

Parameters

src
Byte[]

The array from which bytes are to be read

offset
Int32

The offset within the array of the first byte to be read; must be non-negative and no larger than src.length

length
Int32

The number of bytes to be read from the given array; must be non-negative and no larger than src.length - offset

Returns

This buffer

Attributes

Exceptions

if remaining() is less than byteCount.

if either srcOffset or byteCount is invalid.

if no changes may be made to the contents of this buffer.

Remarks

Relative bulk put method&nbsp;&nbsp;(optional operation).

This method transfers bytes into this buffer from the given source array. If there are more bytes to be copied from the array than remain in this buffer, that is, if length&nbsp;>&nbsp;remaining(), then no bytes are transferred and a BufferOverflowException is thrown.

Otherwise, this method copies length bytes from the given array into this buffer, starting at the given offset in the array and at the current position of this buffer. The position of this buffer is then incremented by length.

In other words, an invocation of this method of the form dst.put(src,&nbsp;off,&nbsp;len) has exactly the same effect as the loop

{@code
                for (int i = off; i < off + len; i++)
                    dst.put(src[i]);
            }

except that it first checks that there is sufficient space in this buffer and it is potentially much more efficient.

Java documentation for java.nio.ByteBuffer.put(byte[], int, int).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to

Put(Int32, ByteBuffer, Int32, Int32)

Absolute bulk put method&nbsp;&nbsp;(optional operation).

[Android.Runtime.Register("put", "(ILjava/nio/ByteBuffer;II)Ljava/nio/ByteBuffer;", "GetPut_ILjava_nio_ByteBuffer_IIHandler", ApiSince=35)]
public virtual Java.Nio.ByteBuffer Put (int index, Java.Nio.ByteBuffer src, int offset, int length);
[<Android.Runtime.Register("put", "(ILjava/nio/ByteBuffer;II)Ljava/nio/ByteBuffer;", "GetPut_ILjava_nio_ByteBuffer_IIHandler", ApiSince=35)>]
abstract member Put : int * Java.Nio.ByteBuffer * int * int -> Java.Nio.ByteBuffer
override this.Put : int * Java.Nio.ByteBuffer * int * int -> Java.Nio.ByteBuffer

Parameters

index
Int32

The index in this buffer at which the first byte will be written; must be non-negative and less than limit()

src
ByteBuffer

The buffer from which bytes are to be read

offset
Int32

The index within the source buffer of the first byte to be read; must be non-negative and less than src.limit()

length
Int32

The number of bytes to be read from the given buffer; must be non-negative and no larger than the smaller of limit() - index and src.limit() - offset

Returns

This buffer

Attributes

Remarks

Absolute bulk put method&nbsp;&nbsp;(optional operation).

This method transfers length bytes into this buffer from the given source buffer, starting at the given offset in the source buffer and the given index in this buffer. The positions of both buffers are unchanged.

In other words, an invocation of this method of the form dst.put(index,&nbsp;src,&nbsp;offset,&nbsp;length) has exactly the same effect as the loop

{@code
            for (int i = offset, j = index; i < offset + length; i++, j++)
                dst.put(j, src.get(i));
            }

except that it first checks the consistency of the supplied parameters and it is potentially much more efficient. If this buffer and the source buffer share the same backing array or memory, then the result will be as if the source elements were first copied to an intermediate location before being written into this buffer.

Added in 16.

Java documentation for java.nio.ByteBuffer.put(int, java.nio.ByteBuffer, int, int).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to

Put(Int32, Byte[], Int32, Int32)

Absolute bulk put method&nbsp;&nbsp;(optional operation).

[Android.Runtime.Register("put", "(I[BII)Ljava/nio/ByteBuffer;", "GetPut_IarrayBIIHandler", ApiSince=35)]
public virtual Java.Nio.ByteBuffer Put (int index, byte[] src, int offset, int length);
[<Android.Runtime.Register("put", "(I[BII)Ljava/nio/ByteBuffer;", "GetPut_IarrayBIIHandler", ApiSince=35)>]
abstract member Put : int * byte[] * int * int -> Java.Nio.ByteBuffer
override this.Put : int * byte[] * int * int -> Java.Nio.ByteBuffer

Parameters

index
Int32

The index in this buffer at which the first byte will be written; must be non-negative and less than limit()

src
Byte[]

The array from which bytes are to be read

offset
Int32

The offset within the array of the first byte to be read; must be non-negative and less than src.length

length
Int32

The number of bytes to be read from the given array; must be non-negative and no larger than the smaller of limit() - index and src.length - offset

Returns

This buffer

Attributes

Remarks

Absolute bulk put method&nbsp;&nbsp;(optional operation).

This method transfers length bytes from the given array, starting at the given offset in the array and at the given index in this buffer. The position of this buffer is unchanged.

An invocation of this method of the form dst.put(index,&nbsp;src,&nbsp;offset,&nbsp;length) has exactly the same effect as the following loop except that it first checks the consistency of the supplied parameters and it is potentially much more efficient:

{@code
                for (int i = offset, j = index; i < offset + length; i++, j++)
                    dst.put(j, src[i]);
            }

Added in 13.

Java documentation for java.nio.ByteBuffer.put(int, byte[], int, int).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to