0N/A<!--
2362N/A Copyright (c) 2000, 2004, Oracle and/or its affiliates. All rights reserved.
0N/A DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A
0N/A This code is free software; you can redistribute it and/or modify it
0N/A under the terms of the GNU General Public License version 2 only, as
2362N/A published by the Free Software Foundation. Oracle designates this
0N/A particular file as subject to the "Classpath" exception as provided
2362N/A by Oracle in the LICENSE file that accompanied this code.
0N/A
0N/A This code is distributed in the hope that it will be useful, but WITHOUT
0N/A ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A version 2 for more details (a copy is included in the LICENSE file that
0N/A accompanied this code).
0N/A
0N/A You should have received a copy of the GNU General Public License version
0N/A 2 along with this work; if not, write to the Free Software Foundation,
0N/A Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A
2362N/A Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A or visit www.oracle.com if you need additional information or have any
2362N/A questions.
0N/A-->
0N/A
0N/A<!doctype html public "-//IETF//DTD HTML//EN">
0N/A<html>
0N/A<body bgcolor="white">
0N/A
0N/ADefines buffers, which are containers for data, and provides an overview of the
0N/Aother NIO packages.
0N/A
0N/A
0N/A<p> The central abstractions of the NIO APIs are: </p>
0N/A
0N/A<ul>
0N/A
0N/A <li><p> <a href="#buffers"><i>Buffers</i></a>, which are containers for data;
0N/A </p></li>
0N/A
0N/A <li><p> <a href="charset/package-summary.html"><i>Charsets</i></a> and their
0N/A associated <i>decoders</i> and <i>encoders</i>, <br> which translate between
0N/A bytes and Unicode characters; </p></li>
0N/A
0N/A <li><p> <a href="channels/package-summary.html"><i>Channels</i></a> of
0N/A various types, which represent connections <br> to entities capable of
0N/A performing I/O operations; and </p></li>
0N/A
0N/A <li><p> <i>Selectors</i> and <i>selection keys</i>, which together with <br>
0N/A <i>selectable channels</i> define a <a
0N/A href="channels/package-summary.html#multiplex">multiplexed, non-blocking <br>
0N/A I/O</a>&nbsp;facility. </p></li>
0N/A
0N/A</ul>
0N/A
0N/A<p> The <tt>java.nio</tt> package defines the buffer classes, which are used
0N/Athroughout the NIO APIs. The charset API is defined in the {@link
0N/Ajava.nio.charset} package, and the channel and selector APIs are defined in the
0N/A{@link java.nio.channels} package. Each of these subpackages has its own
0N/Aservice-provider (SPI) subpackage, the contents of which can be used to extend
0N/Athe platform's default implementations or to construct alternative
0N/Aimplementations.
0N/A
0N/A
0N/A<a name="buffers">
0N/A
0N/A<blockquote><table cellspacing=1 cellpadding=0 summary="Description of the various buffers">
0N/A <tr><th><p align="left">Buffers</p></th><th><p align="left">Description</p></th></tr>
0N/A <tr><td valign=top><tt>{@link java.nio.Buffer}</tt></td>
0N/A <td>Position, limit, and capacity;
0N/A <br>clear, flip, rewind, and mark/reset</td></tr>
0N/A <tr><td valign=top><tt>&nbsp;&nbsp;{@link java.nio.ByteBuffer}</tt></td>
0N/A <td>Get/put, compact, views; allocate,&nbsp;wrap</td></tr>
0N/A <tr><td valign=top><tt>&nbsp;&nbsp;&nbsp;&nbsp;{@link java.nio.MappedByteBuffer}&nbsp;&nbsp;</tt></td>
0N/A <td>A byte buffer mapped to a file</td></tr>
0N/A <tr><td valign=top><tt>&nbsp;&nbsp;{@link java.nio.CharBuffer}</tt></td>
0N/A <td>Get/put, compact; allocate,&nbsp;wrap</td></tr>
0N/A <tr><td valign=top><tt>&nbsp;&nbsp;{@link java.nio.DoubleBuffer}</tt></td>
0N/A <td>&nbsp;&nbsp;&nbsp;&nbsp;'&nbsp;'</td></tr>
0N/A <tr><td valign=top><tt>&nbsp;&nbsp;{@link java.nio.FloatBuffer}</tt></td>
0N/A <td>&nbsp;&nbsp;&nbsp;&nbsp;'&nbsp;'</td></tr>
0N/A <tr><td valign=top><tt>&nbsp;&nbsp;{@link java.nio.IntBuffer}</tt></td>
0N/A <td>&nbsp;&nbsp;&nbsp;&nbsp;'&nbsp;'</td></tr>
0N/A <tr><td valign=top><tt>&nbsp;&nbsp;{@link java.nio.LongBuffer}</tt></td>
0N/A <td>&nbsp;&nbsp;&nbsp;&nbsp;'&nbsp;'</td></tr>
0N/A <tr><td valign=top><tt>&nbsp;&nbsp;{@link java.nio.ShortBuffer}</tt></td>
0N/A <td>&nbsp;&nbsp;&nbsp;&nbsp;'&nbsp;'</td></tr>
0N/A <tr><td valign=top><tt>{@link java.nio.ByteOrder}</tt></td>
0N/A <td>Typesafe enumeration for&nbsp;byte&nbsp;orders</td></tr>
0N/A</table></blockquote>
0N/A
0N/A<p> A <i>buffer</i> is a container for a fixed amount of data of a specific
0N/Aprimitive type. In addition to its content a buffer has a <i>position</i>,
0N/Awhich is the index of the next element to be read or written, and a
0N/A<i>limit</i>, which is the index of the first element that should not be read
0N/Aor written. The base {@link java.nio.Buffer} class defines these properties as
0N/Awell as methods for <i>clearing</i>, <i>flipping</i>, and <i>rewinding</i>, for
0N/A<i>marking</i> the current position, and for <i>resetting</i> the position to
0N/Athe previous mark.
0N/A
0N/A<p> There is a buffer class for each non-boolean primitive type. Each class
0N/Adefines a family of <i>get</i> and <i>put</i> methods for moving data out of
0N/Aand in to a buffer, methods for <i>compacting</i>, <i>duplicating</i>, and
0N/A<i>slicing</i> a buffer, and static methods for <i>allocating</i> a new buffer
0N/Aas well as for <i>wrapping</i> an existing array into a buffer.
0N/A
0N/A<p> Byte buffers are distinguished in that they can be used as the sources and
0N/Atargets of I/O operations. They also support several features not found in the
0N/Aother buffer classes:
0N/A
0N/A<ul>
0N/A
0N/A <li><p> A byte buffer can be allocated as a <a href="ByteBuffer.html#direct">
0N/A <i>direct</i></a> buffer, in which case the Java virtual machine will make a
0N/A best effort to perform native I/O operations directly upon it. </p></li>
0N/A
0N/A <li><p> A byte buffer can be created by {@link
0N/A java.nio.channels.FileChannel#map </code><i>mapping</i><code>} a region of a
0N/A file directly into memory, in which case a few additional file-related
0N/A operations defined in the {@link java.nio.MappedByteBuffer} class are
0N/A available. </p></li>
0N/A
0N/A <li><p> A byte buffer provides access to its content as either a heterogeneous
0N/A or homogeneous sequence of <a href="ByteBuffer.html#bin">binary data</i></a>
0N/A of any non-boolean primitive type, in either big-endian or little-endian <a
0N/A href="ByteOrder.html">byte order</a>. </p></li>
0N/A
0N/A</ul>
0N/A
0N/A<p> Unless otherwise noted, passing a <tt>null</tt> argument to a constructor
0N/Aor method in any class or interface in this package will cause a {@link
0N/Ajava.lang.NullPointerException NullPointerException} to be thrown.
0N/A
0N/A@since 1.4
0N/A@author Mark Reinhold
0N/A@author JSR-51 Expert Group
0N/A
0N/A</body>
0N/A</html>