< prev index next >

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

Print this page


   1 /*
   2  * Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 #warn This file is preprocessed before being compiled
  27 
  28 package java.nio;
  29 
  30 #if[char]
  31 import java.io.IOException;

  32 #end[char]
  33 #if[streamableType]
  34 import java.util.Spliterator;
  35 import java.util.stream.StreamSupport;
  36 import java.util.stream.$Streamtype$Stream;
  37 #end[streamableType]
  38 
  39 /**
  40  * $A$ $type$ buffer.
  41  *
  42  * <p> This class defines {#if[byte]?six:four} categories of operations upon
  43  * $type$ buffers:
  44  *
  45  * <ul>
  46  *
  47  *   <li><p> Absolute and relative {@link #get() <i>get</i>} and
  48  *   {@link #put($type$) <i>put</i>} methods that read and write
  49  *   single $type$s; </p></li>
  50  *
  51  *   <li><p> Relative {@link #get($type$[]) <i>bulk get</i>}


1531      * <pre>
1532      *     dst.put($x$) </pre>
1533      *
1534      * @param  $x$
1535      *         The 16-bit $type$ to append
1536      *
1537      * @return  This buffer
1538      *
1539      * @throws  BufferOverflowException
1540      *          If there is insufficient space in this buffer
1541      *
1542      * @throws  ReadOnlyBufferException
1543      *          If this buffer is read-only
1544      *
1545      * @since  1.5
1546      */
1547     public $Type$Buffer append($type$ $x$) {
1548         return put($x$);
1549     }
1550 


































1551 #end[char]
1552 
1553 
1554     // -- Other byte stuff: Access to binary data --
1555 
1556 #if[!byte]
1557 
1558     /**
1559      * Retrieves this buffer's byte order.
1560      *
1561      * <p> The byte order of $a$ $type$ buffer created by allocation or by
1562      * wrapping an existing {@code $type$} array is the {@link
1563      * ByteOrder#nativeOrder native order} of the underlying
1564      * hardware.  The byte order of $a$ $type$ buffer created as a <a
1565      * href="ByteBuffer.html#views">view</a> of a byte buffer is that of the
1566      * byte buffer at the moment that the view is created.  </p>
1567      *
1568      * @return  This buffer's byte order
1569      */
1570     public abstract ByteOrder order();


   1 /*
   2  * Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 #warn This file is preprocessed before being compiled
  27 
  28 package java.nio;
  29 
  30 #if[char]
  31 import java.io.IOException;
  32 import java.util.Objects;
  33 #end[char]
  34 #if[streamableType]
  35 import java.util.Spliterator;
  36 import java.util.stream.StreamSupport;
  37 import java.util.stream.$Streamtype$Stream;
  38 #end[streamableType]
  39 
  40 /**
  41  * $A$ $type$ buffer.
  42  *
  43  * <p> This class defines {#if[byte]?six:four} categories of operations upon
  44  * $type$ buffers:
  45  *
  46  * <ul>
  47  *
  48  *   <li><p> Absolute and relative {@link #get() <i>get</i>} and
  49  *   {@link #put($type$) <i>put</i>} methods that read and write
  50  *   single $type$s; </p></li>
  51  *
  52  *   <li><p> Relative {@link #get($type$[]) <i>bulk get</i>}


1532      * <pre>
1533      *     dst.put($x$) </pre>
1534      *
1535      * @param  $x$
1536      *         The 16-bit $type$ to append
1537      *
1538      * @return  This buffer
1539      *
1540      * @throws  BufferOverflowException
1541      *          If there is insufficient space in this buffer
1542      *
1543      * @throws  ReadOnlyBufferException
1544      *          If this buffer is read-only
1545      *
1546      * @since  1.5
1547      */
1548     public $Type$Buffer append($type$ $x$) {
1549         return put($x$);
1550     }
1551 
1552     /**
1553      * {@inheritDoc}
1554      *
1555      * @implSpec
1556      * The implementation transfers data by one of two means. If the given {@link Appendable}
1557      * is a {@link CharBuffer}, {@code put(CharBuffer)} is invoked on it with this
1558      * buffer as parameter. Otherwise {@link Appendable#append(CharSequence, int, int)} is
1559      * invoked on it with this buffer and its position and length as parameters.
1560      *
1561      * @param  out the appendable, non-null
1562      * @return the number of characters transferred
1563      * @throws IOException if an I/O error occurs when reading or writing
1564      * @throws NullPointerException if {@code out} is {@code null}
1565      * @throws BufferOverflowException if there is insufficient space in out
1566      *         buffer for the remaining chars in the source buffer
1567      * @throws IllegalArgumentException if out is this buffer
1568      * @throws ReadOnlyBufferException if out is a read-only buffer
1569      *
1570      * @since 10
1571      */
1572     @Override
1573     public long transferTo(Appendable out) throws IOException {
1574         Objects.requireNonNull(out, "out");
1575         if (this == out) {
1576             throw new IllegalArgumentException("Illegal transfer of a buffer to itself");
1577         }
1578         int length = remaining();
1579         if (out instanceof CharBuffer) {
1580             ((CharBuffer)out).put(this);
1581         } else {
1582             out.append(this, position(), length);
1583         }
1584         return length;
1585     }
1586 #end[char]
1587 
1588 
1589     // -- Other byte stuff: Access to binary data --
1590 
1591 #if[!byte]
1592 
1593     /**
1594      * Retrieves this buffer's byte order.
1595      *
1596      * <p> The byte order of $a$ $type$ buffer created by allocation or by
1597      * wrapping an existing {@code $type$} array is the {@link
1598      * ByteOrder#nativeOrder native order} of the underlying
1599      * hardware.  The byte order of $a$ $type$ buffer created as a <a
1600      * href="ByteBuffer.html#views">view</a> of a byte buffer is that of the
1601      * byte buffer at the moment that the view is created.  </p>
1602      *
1603      * @return  This buffer's byte order
1604      */
1605     public abstract ByteOrder order();


< prev index next >