< prev index next >

src/java.base/share/classes/java/nio/X-Buffer.java.template

Print this page




 530      * will be the number of $type$s remaining in this buffer, its mark will be
 531      * undefined, and its byte order will be
 532 #if[byte]
 533      * {@link ByteOrder#BIG_ENDIAN BIG_ENDIAN}.
 534 #else[byte]
 535      * identical to that of this buffer.
 536 #end[byte]
 537      * The new buffer will be direct if, and only if, this buffer is direct, and
 538      * it will be read-only if, and only if, this buffer is read-only.  </p>
 539      *
 540      * @return  The new $type$ buffer
 541 #if[byte]
 542      *
 543      * @see #alignedSlice(int)
 544 #end[byte]
 545      */
 546     @Override
 547     public abstract $Type$Buffer slice();
 548 
 549     /**








































 550      * Creates a new $type$ buffer that shares this buffer's content.
 551      *
 552      * <p> The content of the new buffer will be that of this buffer.  Changes
 553      * to this buffer's content will be visible in the new buffer, and vice
 554      * versa; the two buffers' position, limit, and mark values will be
 555      * independent.
 556      *
 557      * <p> The new buffer's capacity, limit, position,
 558 #if[byte]
 559      * and mark values will be identical to those of this buffer, and its byte
 560      * order will be {@link ByteOrder#BIG_ENDIAN BIG_ENDIAN}.
 561 #else[byte]
 562      * mark values, and byte order will be identical to those of this buffer.
 563 #end[byte]
 564      * The new buffer will be direct if, and only if, this buffer is direct, and
 565      * it will be read-only if, and only if, this buffer is read-only.  </p>
 566      *
 567      * @return  The new $type$ buffer
 568      */
 569     @Override


1933      */
1934     public final ByteBuffer alignedSlice(int unitSize) {
1935         int pos = position();
1936         int lim = limit();
1937 
1938         int pos_mod = alignmentOffset(pos, unitSize);
1939         int lim_mod = alignmentOffset(lim, unitSize);
1940 
1941         // Round up the position to align with unit size
1942         int aligned_pos = (pos_mod > 0)
1943             ? pos + (unitSize - pos_mod)
1944             : pos;
1945 
1946         // Round down the limit to align with unit size
1947         int aligned_lim = lim - lim_mod;
1948 
1949         if (aligned_pos > lim || aligned_lim < pos) {
1950             aligned_pos = aligned_lim = pos;
1951         }
1952 
1953         return slice(aligned_pos, aligned_lim);
1954     }
1955 
1956     abstract ByteBuffer slice(int pos, int lim);
1957 
1958     // #BIN
1959     //
1960     // Binary-data access methods  for short, char, int, long, float,
1961     // and double will be inserted here
1962 
1963 #end[byte]
1964 
1965 #if[streamableType]
1966 
1967 #if[char]
1968     @Override
1969 #end[char]
1970     public $Streamtype$Stream $type$s() {
1971         return StreamSupport.$streamtype$Stream(() -> new $Type$BufferSpliterator(this),
1972             Buffer.SPLITERATOR_CHARACTERISTICS, false);
1973     }
1974 
1975 #end[streamableType]
1976 
1977 }


 530      * will be the number of $type$s remaining in this buffer, its mark will be
 531      * undefined, and its byte order will be
 532 #if[byte]
 533      * {@link ByteOrder#BIG_ENDIAN BIG_ENDIAN}.
 534 #else[byte]
 535      * identical to that of this buffer.
 536 #end[byte]
 537      * The new buffer will be direct if, and only if, this buffer is direct, and
 538      * it will be read-only if, and only if, this buffer is read-only.  </p>
 539      *
 540      * @return  The new $type$ buffer
 541 #if[byte]
 542      *
 543      * @see #alignedSlice(int)
 544 #end[byte]
 545      */
 546     @Override
 547     public abstract $Type$Buffer slice();
 548 
 549     /**
 550      * Creates a new $type$ buffer whose content is a shared subsequence of
 551      * this buffer's content.
 552      *
 553      * <p> The new buffer will start at position {@code index} in this buffer
 554      * and will contain {@code length} elements. Changes to this buffer's
 555      * content will be visible in the new buffer, and vice versa; the two
 556      * buffers' position, limit, and mark values will be independent.
 557      *
 558      * <p> The new buffer's position will be zero, its capacity and its limit
 559      * will be {@code length}, its mark will be undefined, and its byte order
 560      * will be
 561 #if[byte]
 562      * {@link ByteOrder#BIG_ENDIAN BIG_ENDIAN}.
 563 #else[byte]
 564      * identical to that of this buffer.
 565 #end[byte]
 566      * The new buffer will be direct if, and only if, this buffer is direct,
 567      * and it will be read-only if, and only if, this buffer is read-only. </p>
 568      *
 569      * @param   index
 570      *          The position in this buffer at which the content of the new
 571      *          buffer will start; must be non-negative and less than
 572      *          {@link #limit() limit()}
 573      *
 574      * @param   length
 575      *          The number of elements the new buffer will contain; must be
 576      *          non-negative and no larger than {@code limit() - index}
 577      *
 578      * @return  The new buffer
 579      *
 580      * @throws  IndexOutOfBoundsException
 581      *          If {@code index} is negative or not less than {@code limit()},
 582      *          {@code length} is negative, or {@code length > limit() - index}
 583      *
 584      * @since 13
 585      */
 586     @Override
 587     public abstract $Type$Buffer slice(int index, int length);
 588 
 589     /**
 590      * Creates a new $type$ buffer that shares this buffer's content.
 591      *
 592      * <p> The content of the new buffer will be that of this buffer.  Changes
 593      * to this buffer's content will be visible in the new buffer, and vice
 594      * versa; the two buffers' position, limit, and mark values will be
 595      * independent.
 596      *
 597      * <p> The new buffer's capacity, limit, position,
 598 #if[byte]
 599      * and mark values will be identical to those of this buffer, and its byte
 600      * order will be {@link ByteOrder#BIG_ENDIAN BIG_ENDIAN}.
 601 #else[byte]
 602      * mark values, and byte order will be identical to those of this buffer.
 603 #end[byte]
 604      * The new buffer will be direct if, and only if, this buffer is direct, and
 605      * it will be read-only if, and only if, this buffer is read-only.  </p>
 606      *
 607      * @return  The new $type$ buffer
 608      */
 609     @Override


1973      */
1974     public final ByteBuffer alignedSlice(int unitSize) {
1975         int pos = position();
1976         int lim = limit();
1977 
1978         int pos_mod = alignmentOffset(pos, unitSize);
1979         int lim_mod = alignmentOffset(lim, unitSize);
1980 
1981         // Round up the position to align with unit size
1982         int aligned_pos = (pos_mod > 0)
1983             ? pos + (unitSize - pos_mod)
1984             : pos;
1985 
1986         // Round down the limit to align with unit size
1987         int aligned_lim = lim - lim_mod;
1988 
1989         if (aligned_pos > lim || aligned_lim < pos) {
1990             aligned_pos = aligned_lim = pos;
1991         }
1992 
1993         return slice(aligned_pos, aligned_lim - aligned_pos);
1994     }
1995 


1996     // #BIN
1997     //
1998     // Binary-data access methods  for short, char, int, long, float,
1999     // and double will be inserted here
2000 
2001 #end[byte]
2002 
2003 #if[streamableType]
2004 
2005 #if[char]
2006     @Override
2007 #end[char]
2008     public $Streamtype$Stream $type$s() {
2009         return StreamSupport.$streamtype$Stream(() -> new $Type$BufferSpliterator(this),
2010             Buffer.SPLITERATOR_CHARACTERISTICS, false);
2011     }
2012 
2013 #end[streamableType]
2014 
2015 }
< prev index next >