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