public abstract class IntBuffer 
  extends Buffer implements Comparable<IntBuffer>
| java.lang.Object | ||
| ↳ | java.nio.Buffer | |
| ↳ | java.nio.IntBuffer | |
一个int缓冲区。
这个类在int缓冲区中定义了四类操作:
相对 bulk put将int数组或其他int缓冲区的连续序列传输到此缓冲区的方法; 和
方法  compacting ,  duplicating和  slicing INT缓冲区。
Int缓冲区可以通过  allocation (为缓冲区的内容分配空间),  wrapping现有的int数组创建到缓冲区中,或者通过创建现有字节缓冲区的 view来创建。
像字节缓冲区一样,int缓冲区是direct or non-direct 。 通过此类的wrap方法创建的整型缓冲区将是非直接的。 当且仅当字节缓冲区本身是直接的时,作为字节缓冲区视图创建的整型缓冲区才是直接的。 通过调用isDirect方法可以确定int缓冲区是否是直接的。
指定此类中不具有返回值的方法以返回调用它们的缓冲区。 这允许方法调用被链接。
| Public methods | |
|---|---|
|  static IntBuffer |  allocate(int capacity) 分配一个新的int缓冲区。 | 
|  final int[] |  array() 返回支持此缓冲区的int数组 (可选操作) 。 | 
|  final int |  arrayOffset() 返回缓冲区第一个元素 (可选操作)的此缓冲区的后备数组内的偏移量。 | 
|  abstract IntBuffer |  asReadOnlyBuffer() 创建一个共享此缓冲区内容的新的只读int缓冲区。 | 
|  abstract IntBuffer |  compact() 压缩此缓冲区 (可选操作) 。 | 
|  int |  compareTo(IntBuffer that) 将此缓冲区与另一个进行比较。 | 
|  abstract IntBuffer |  duplicate() 创建一个共享此缓冲区内容的新int缓冲区。 | 
|  boolean |  equals(Object ob) 告诉这个缓冲区是否等于另一个对象。 | 
|  abstract int |  get() 相对 获得方法。 | 
|  abstract int |  get(int index) 绝对 get方法。 | 
|  IntBuffer |  get(int[] dst, int offset, int length) 相对批量 获取方法。 | 
|  IntBuffer |  get(int[] dst) 相对批量 获取方法。 | 
|  final boolean |  hasArray() 告诉这个缓冲区是否由一个可访问的int数组支持。 | 
|  int |  hashCode() 返回此缓冲区的当前哈希码。 | 
|  abstract boolean |  isDirect() 告诉这个int缓冲区是否是直接的。 | 
|  abstract ByteOrder |  order() 检索此缓冲区的字节顺序。 | 
|  abstract IntBuffer |  put(int i) 相对 放置方法 (可选操作) 。 | 
|  IntBuffer |  put(int[] src, int offset, int length) 相对批量 放置方法 (可选操作) 。 | 
|  abstract IntBuffer |  put(int index, int i) 绝对 放置方法 (可选操作) 。 | 
|  final IntBuffer |  put(int[] src) 相对批量 放置方法 (可选操作) 。 | 
|  IntBuffer |  put(IntBuffer src) 相对批量 放置方法 (可选操作) 。 | 
|  abstract IntBuffer |  slice() 创建一个新的int缓冲区,其内容是此缓冲区内容的共享子序列。 | 
|  String |  toString() 返回汇总此缓冲区状态的字符串。 | 
|  static IntBuffer |  wrap(int[] array) 将int数组包装到缓冲区中。 | 
|  static IntBuffer |  wrap(int[] array, int offset, int length) 将int数组包装到缓冲区中。 | 
| Inherited methods | |
|---|---|
|  From class  java.nio.Buffer  | |
|  From class  java.lang.Object  | |
|  From interface  java.lang.Comparable  | |
IntBuffer allocate (int capacity)
分配一个新的int缓冲区。
新的缓冲区的位置将为零,其限制将是其容量,其标记将是未定义的,并且其每个元素将被初始化为零。 它将有一个 backing array ,其 array offset将为零。
| Parameters | |
|---|---|
| capacity | int: The new buffer's capacity, in ints | 
| Returns | |
|---|---|
| IntBuffer | The new int buffer | 
| Throws | |
|---|---|
| IllegalArgumentException | If the capacity is a negative integer | 
int[] array ()
返回支持此缓冲区的int数组 (可选操作) 。
修改此缓冲区的内容将导致返回的数组内容被修改,反之亦然。
在调用此方法之前调用 hasArray方法,以确保此缓冲区具有可访问的后备数组。
| Returns | |
|---|---|
| int[] | The array that backs this buffer | 
| Throws | |
|---|---|
| ReadOnlyBufferException | If this buffer is backed by an array but is read-only | 
| UnsupportedOperationException | If this buffer is not backed by an accessible array | 
int arrayOffset ()
返回缓冲区第一个元素 (可选操作)的此缓冲区的后备数组内的偏移量。
如果此缓冲区由数组支持,则缓冲区位置 p对应于数组索引 p + arrayOffset() 。
在调用此方法之前调用 hasArray方法,以确保此缓冲区具有可访问的后备阵列。
| Returns | |
|---|---|
| int | The offset within this buffer's array of the first element of the buffer | 
| Throws | |
|---|---|
| ReadOnlyBufferException | If this buffer is backed by an array but is read-only | 
| UnsupportedOperationException | If this buffer is not backed by an accessible array | 
IntBuffer asReadOnlyBuffer ()
创建一个共享此缓冲区内容的新的只读int缓冲区。
新缓冲区的内容将是该缓冲区的内容。 此缓冲区内容的更改将在新缓冲区中可见; 但是新的缓冲区本身将是只读的,并且不允许修改共享内容。 两个缓冲区的位置,限制和标记值将是独立的。
新缓冲区的容量,限制,位置和标记值将与该缓冲区的相同。
如果此缓冲区本身是只读的,则此方法的行为方式与 duplicate方法完全相同。
| Returns | |
|---|---|
| IntBuffer | The new, read-only int buffer | 
IntBuffer compact ()
压缩此缓冲区 (可选操作) 。
缓冲区当前位置与其限制之间的整数(如果有的话)被复制到缓冲区的开始位置。 也就是说,索引p = position()处的int被复制到索引零,索引p + 1处的int被复制到索引1,等等,直到索引limit()-1处的int被复制到索引n = limit() - 1 - p 。 然后将缓冲区的位置设置为n + 1,并将其限制设置为其容量。 标记(如果已定义)将被丢弃。
缓冲区的位置被设置为被复制的整数数量,而不是零,因此可以通过调用另一个相对 put方法来立即调用此方法。
| Returns | |
|---|---|
| IntBuffer | This buffer | 
| Throws | |
|---|---|
| ReadOnlyBufferException | If this buffer is read-only | 
int compareTo (IntBuffer that)
将此缓冲区与另一个进行比较。
通过按照字典顺序比较剩余元素的序列,比较两个int缓冲区,而不考虑每个序列在其相应缓冲区内的起始位置。 对int元素进行比较,就好像调用compare(int, int) 。
一个int缓冲区不能与任何其他类型的对象进行比较。
| Parameters | |
|---|---|
| that | IntBuffer | 
| Returns | |
|---|---|
| int | A negative integer, zero, or a positive integer as this buffer is less than, equal to, or greater than the given buffer | 
IntBuffer duplicate ()
创建一个共享此缓冲区内容的新int缓冲区。
新缓冲区的内容将是该缓冲区的内容。 这个缓冲区内容的改变将在新缓冲区中可见,反之亦然; 两个缓冲区的位置,限制和标记值将是独立的。
新缓冲区的容量,限制,位置和标记值将与该缓冲区的相同。 当且仅当此缓冲区是直接的时,新缓冲区才是直接的,并且只有在此缓冲区是只读的情况下,它才会是只读的。
| Returns | |
|---|---|
| IntBuffer | The new int buffer | 
boolean equals (Object ob)
告诉这个缓冲区是否等于另一个对象。
两个int缓冲区是相等的,并且只有当,
它们具有相同的元素类型,
他们有相同数量的剩余元素,并且
独立于其起始位置考虑的剩余元素的两个序列是逐点相等的。
int缓冲区不等于任何其他类型的对象。
| Parameters | |
|---|---|
| ob | Object: The object to which this buffer is to be compared | 
| Returns | |
|---|---|
| boolean | true if, and only if, this buffer is equal to the given object | 
int get ()
相对获得方法。 在此缓冲区的当前位置读取int,然后递增该位置。
| Returns | |
|---|---|
| int | The int at the buffer's current position | 
| Throws | |
|---|---|
| BufferUnderflowException | If the buffer's current position is not smaller than its limit | 
int get (int index)
绝对get方法。 在给定索引处读取int。
| Parameters | |
|---|---|
| index | int: The index from which the int will be read | 
| Returns | |
|---|---|
| int | The int at the given index | 
| Throws | |
|---|---|
| IndexOutOfBoundsException | If index is negative or not smaller than the buffer's limit | 
IntBuffer get (int[] dst, int offset, int length)
相对批量 获取方法。
该方法将int从此缓冲区转移到给定的目标数组中。 如果缓冲区中剩余的整数少于满足请求所需的平均值 ,也就是说,如果length > remaining() ,则不传送整数并且抛出BufferUnderflowException 。
否则,此方法将length ints从此缓冲区复制到给定数组中,从此缓冲区的当前位置开始,并在数组中给定的偏移量处开始。 此缓冲区的位置然后递增length 。
换句话说,调用这种形式为 src.get(dst, off, len)的方法与 循环具有完全相同的效果
     for (int i = off; i < off + len; i++)
         dst[i] = src.get();  except that it first checks that there are sufficient ints in this buffer and it is potentially much more efficient. 
      
      
     | Parameters | |
|---|---|
| dst | int: The array into which ints are to be written | 
| offset | int: The offset within the array of the first int to be written; must be non-negative and no larger than dst.length | 
| length | int: The maximum number of ints to be written to the given array; must be non-negative and no larger than dst.length - offset | 
| Returns | |
|---|---|
| IntBuffer | This buffer | 
| Throws | |
|---|---|
| BufferUnderflowException | If there are fewer than length ints remaining in this buffer | 
| IndexOutOfBoundsException | If the preconditions on the offset and length parameters do not hold | 
IntBuffer get (int[] dst)
相对批量 获取方法。
该方法将int从此缓冲区转移到给定的目标数组中。 表单src.get(a)的这种方法的调用的行为方式与调用完全相同
     src.get(a, 0, a.length)  
      
     | Parameters | |
|---|---|
| dst | int | 
| Returns | |
|---|---|
| IntBuffer | This buffer | 
| Throws | |
|---|---|
| BufferUnderflowException | If there are fewer than length ints remaining in this buffer | 
boolean hasArray ()
告诉这个缓冲区是否由一个可访问的int数组支持。
如果此方法返回 true ,则可安全地调用 array和 arrayOffset方法。
| Returns | |
|---|---|
| boolean | true if, and only if, this buffer is backed by an array and is not read-only | 
int hashCode ()
返回此缓冲区的当前哈希码。
int缓冲区的哈希码仅依赖于其余的元素; 也就是说,从position()到元素limit() - 1的元素。
由于缓冲区散列码与内容相关,因此除非知道其内容不会改变,否则在散列映射或类似数据结构中使用缓冲区作为键是不可取的。
| Returns | |
|---|---|
| int | The current hash code of this buffer | 
boolean isDirect ()
告诉这个int缓冲区是否是直接的。
| Returns | |
|---|---|
| boolean | true if, and only if, this buffer is direct | 
ByteOrder order ()
检索此缓冲区的字节顺序。
通过分配或包装现有的int阵列创建的整型缓冲区的字节顺序是底层硬件的 native order 。 创建为字节缓冲区view的整型缓冲区的字节顺序是创建视图时字节缓冲区的字节顺序。
| Returns | |
|---|---|
| ByteOrder | This buffer's byte order | 
IntBuffer put (int i)
相对 放置方法 (可选操作) 。
将给定的int写入此缓冲区的当前位置,然后递增该位置。
| Parameters | |
|---|---|
| i | int: The int to be written | 
| Returns | |
|---|---|
| IntBuffer | This buffer | 
| Throws | |
|---|---|
| BufferOverflowException | If this buffer's current position is not smaller than its limit | 
| ReadOnlyBufferException | If this buffer is read-only | 
IntBuffer put (int[] src, int offset, int length)
相对批量 放置方法 (可选操作) 。
这个方法将ints从给定的源数组传递到这个缓冲区。 如果要从数组中复制更多的整数而不是保留在此缓冲区中,也就是说,如果length > remaining() ,则不传输整数并引发BufferOverflowException 。
否则,此方法从给定数组中将length个整数复制到此缓冲区中,从数组中给定的偏移量和此缓冲区的当前位置开始。 此缓冲区的位置然后增加length 。
换句话说,调用形式为 dst.put(src, off, len)的此方法与 循环具有完全相同的效果
     for (int i = off; i < off + len; i++)
         dst.put(a[i]);  except that it first checks that there is sufficient space in this buffer and it is potentially much more efficient. 
      
      
     | Parameters | |
|---|---|
| src | int: The array from which ints are to be read | 
| offset | int: The offset within the array of the first int to be read; must be non-negative and no larger than array.length | 
| length | int: The number of ints to be read from the given array; must be non-negative and no larger than array.length - offset | 
| Returns | |
|---|---|
| IntBuffer | This buffer | 
| Throws | |
|---|---|
| BufferOverflowException | If there is insufficient space in this buffer | 
| IndexOutOfBoundsException | If the preconditions on the offset and length parameters do not hold | 
| ReadOnlyBufferException | If this buffer is read-only | 
IntBuffer put (int index, int i)
绝对 放置方法 (可选操作) 。
在给定索引处将给定的int写入此缓冲区。
| Parameters | |
|---|---|
| index | int: The index at which the int will be written | 
| i | int: The int value to be written | 
| Returns | |
|---|---|
| IntBuffer | This buffer | 
| Throws | |
|---|---|
| IndexOutOfBoundsException | If index is negative or not smaller than the buffer's limit | 
| ReadOnlyBufferException | If this buffer is read-only | 
IntBuffer put (int[] src)
相对批量 放置方法 (可选操作) 。
此方法将给定源int数组的全部内容传输到此缓冲区。 表单dst.put(a)的此方法的调用与调用完全相同
     dst.put(a, 0, a.length)  
      
     | Parameters | |
|---|---|
| src | int | 
| Returns | |
|---|---|
| IntBuffer | This buffer | 
| Throws | |
|---|---|
| BufferOverflowException | If there is insufficient space in this buffer | 
| ReadOnlyBufferException | If this buffer is read-only | 
IntBuffer put (IntBuffer src)
相对批量 放置方法 (可选操作) 。
此方法将剩余在给定源缓冲区中的ints传送到此缓冲区中。 如果源缓冲区中剩余的字节 数多于此缓冲区中的字节 数 ,也就是说,如果src.remaining() > remaining() ,则不传输整数并且引发BufferOverflowException 。
否则,此方法从给定缓冲区中将 n = src.remaining()个整数复制到此缓冲区,从每个缓冲区的当前位置开始。 然后两个缓冲器的位置增加n 。
换句话说,调用表单 dst.put(src)的这种方法与 循环具有完全相同的效果
     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. 
      
      
     | Parameters | |
|---|---|
| src | IntBuffer: The source buffer from which ints are to be read; must not be this buffer | 
| Returns | |
|---|---|
| IntBuffer | This buffer | 
| Throws | |
|---|---|
| BufferOverflowException | If there is insufficient space in this buffer for the remaining ints in the source buffer | 
| IllegalArgumentException | If the source buffer is this buffer | 
| ReadOnlyBufferException | If this buffer is read-only | 
IntBuffer slice ()
创建一个新的int缓冲区,其内容是此缓冲区内容的共享子序列。
新缓冲区的内容将从此缓冲区的当前位置开始。 这个缓冲区内容的改变将在新缓冲区中可见,反之亦然; 两个缓冲区的位置,限制和标记值将是独立的。
新缓冲区的位置将为零,其容量和限制将为此缓冲区中剩余的整数,其标记将不确定。 当且仅当此缓冲区是直接的时,新缓冲区才是直接的,并且只有在此缓冲区是只读的情况下,它才会是只读的。
| Returns | |
|---|---|
| IntBuffer | The new int buffer | 
String toString ()
Returns a string summarizing the state of this buffer.
| Returns | |
|---|---|
| String | A summary string | 
IntBuffer wrap (int[] array)
将int数组包装到缓冲区中。
新的缓冲区将由给定的int数组支持; 也就是说,修改缓冲区将导致数组被修改,反之亦然。 新缓冲区的容量和限制将为array.length ,其位置将为零,其标记将不确定。 其 backing array将是给定的阵列,其 array offset将为零。
| Parameters | |
|---|---|
| array | int: The array that will back this buffer | 
| Returns | |
|---|---|
| IntBuffer | The new int buffer | 
IntBuffer wrap (int[] array, int offset, int length)
将int数组包装到缓冲区中。
新的缓冲区将由给定的int数组支持; 也就是说,修改缓冲区将导致数组被修改,反之亦然。 新缓冲区容量为array.length ,位置为offset ,限制为offset + length ,其标记为未定义。 其 backing array将是给定的阵列,其 array offset将为零。
| Parameters | |
|---|---|
| array | int: The array that will back the new buffer | 
| offset | int: The offset of the subarray to be used; must be non-negative and no larger than array.length. The new buffer's position will be set to this value. | 
| length | int: The length of the subarray to be used; must be non-negative and no larger than array.length - offset. The new buffer's limit will be set to offset + length. | 
| Returns | |
|---|---|
| IntBuffer | The new int buffer | 
| Throws | |
|---|---|
| IndexOutOfBoundsException | If the preconditions on the offset and length parameters do not hold |